|
17 | 17 | import de.numcodex.sq2cql.Translator;
|
18 | 18 | import de.numcodex.sq2cql.model.structured_query.StructuredQuery;
|
19 | 19 | import org.hl7.fhir.r4.model.OperationOutcome;
|
20 |
| -import org.junit.jupiter.api.Assertions; |
21 |
| -import org.junit.jupiter.api.BeforeAll; |
22 |
| -import org.junit.jupiter.api.Nested; |
23 |
| -import org.junit.jupiter.api.Test; |
24 |
| -import org.junit.jupiter.api.TestInstance; |
| 20 | +import org.junit.jupiter.api.*; |
25 | 21 | import org.junit.jupiter.params.ParameterizedTest;
|
26 | 22 | import org.junit.jupiter.params.provider.ValueSource;
|
27 | 23 | import org.slf4j.Logger;
|
|
31 | 27 | import org.springframework.beans.factory.annotation.Value;
|
32 | 28 | import org.springframework.boot.test.context.SpringBootTest;
|
33 | 29 | import org.springframework.boot.test.web.client.TestRestTemplate;
|
34 |
| -import org.springframework.http.HttpEntity; |
35 |
| -import org.springframework.http.HttpHeaders; |
36 |
| -import org.springframework.http.HttpMethod; |
37 |
| -import org.springframework.http.MediaType; |
38 |
| -import org.springframework.http.ResponseEntity; |
| 30 | +import org.springframework.http.*; |
39 | 31 | import org.springframework.test.annotation.DirtiesContext;
|
40 | 32 | import org.springframework.test.context.ActiveProfiles;
|
41 | 33 | import org.springframework.web.client.HttpStatusCodeException;
|
@@ -306,5 +298,53 @@ void invalidCRTDLReturnsValidationException(String parametersFile) {
|
306 | 298 | headers.add("content-type", "application/fhir+json");
|
307 | 299 | testExecutor(parametersFile, "http://localhost:" + port + "/fhir/$extract-data", headers, 400);
|
308 | 300 | }
|
| 301 | + |
| 302 | + @Test |
| 303 | + void testPayloadJustBelow2Mb() { |
| 304 | + HttpHeaders headers = new HttpHeaders(); |
| 305 | + headers.setContentType(MediaType.valueOf("application/fhir+json")); |
| 306 | + |
| 307 | + // Generate JSON payload just below 2 MB |
| 308 | + String payload = buildJsonPayload(2 * 1024 * 1024 - 50); // 2MB - 50 bytes |
| 309 | + |
| 310 | + TestRestTemplate restTemplate = new TestRestTemplate(); |
| 311 | + HttpEntity<String> entity = new HttpEntity<>(payload, headers); |
| 312 | + |
| 313 | + ResponseEntity<String> response = restTemplate.postForEntity( |
| 314 | + "http://localhost:" + port + "/fhir/$extract-data", |
| 315 | + entity, |
| 316 | + String.class |
| 317 | + ); |
| 318 | + |
| 319 | + assertThat(response.getStatusCode().value()).isEqualTo(400); |
| 320 | + } |
| 321 | + |
| 322 | + @Test |
| 323 | + void testPayloadJustAbove2Mb() { |
| 324 | + HttpHeaders headers = new HttpHeaders(); |
| 325 | + headers.setContentType(MediaType.valueOf("application/fhir+json")); |
| 326 | + |
| 327 | + // Generate JSON payload just above 2 MB |
| 328 | + String payload = buildJsonPayload(2 * 1024 * 1024 + 50); // 2MB + 50 bytes |
| 329 | + |
| 330 | + TestRestTemplate restTemplate = new TestRestTemplate(); |
| 331 | + HttpEntity<String> entity = new HttpEntity<>(payload, headers); |
| 332 | + |
| 333 | + ResponseEntity<String> response = restTemplate.postForEntity( |
| 334 | + "http://localhost:" + port + "/fhir/$extract-data", |
| 335 | + entity, |
| 336 | + String.class |
| 337 | + ); |
| 338 | + |
| 339 | + // Expect failure due to exceeding maxInMemorySize |
| 340 | + assertThat(response.getStatusCode().is5xxServerError()).isTrue(); |
| 341 | + } |
| 342 | + |
| 343 | + private String buildJsonPayload(int sizeInBytes) { |
| 344 | + // Simple JSON with a single string field |
| 345 | + return "{\"parameter\":[{\"name\":\"data\",\"valueString\":\"" + |
| 346 | + "x".repeat(Math.max(0, sizeInBytes)) + |
| 347 | + "\"}]}"; |
| 348 | + } |
309 | 349 | }
|
310 | 350 | }
|
0 commit comments