mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-17 02:15:22 +00:00
Add test case for invalid query parameters in read operation
This commit is contained in:
parent
0021561fb1
commit
ce012ff7cf
@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.stringContainsInOrder;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -64,6 +65,131 @@ public class ReadDstu3Test {
|
|||||||
"</Patient>"));
|
"</Patient>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidQueryParamsInRead() throws Exception {
|
||||||
|
CloseableHttpResponse status;
|
||||||
|
HttpGet httpGet;
|
||||||
|
|
||||||
|
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2?_contained=both&_format=xml&_pretty=true");
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
try (InputStream inputStream = status.getEntity().getContent()) {
|
||||||
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
String responseContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
||||||
|
assertThat(responseContent, stringContainsInOrder(
|
||||||
|
"<OperationOutcome xmlns=\"http://hl7.org/fhir\">",
|
||||||
|
" <issue>",
|
||||||
|
" <severity value=\"error\"/>",
|
||||||
|
" <code value=\"processing\"/>",
|
||||||
|
" <diagnostics value=\"Invalid query parameter(s) for this request: "[_contained]"\"/>",
|
||||||
|
" </issue>",
|
||||||
|
"</OperationOutcome>"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2?_containedType=contained&_format=xml&_pretty=true");
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
try (InputStream inputStream = status.getEntity().getContent()) {
|
||||||
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
String responseContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
||||||
|
assertThat(responseContent, stringContainsInOrder(
|
||||||
|
"<OperationOutcome xmlns=\"http://hl7.org/fhir\">",
|
||||||
|
" <issue>",
|
||||||
|
" <severity value=\"error\"/>",
|
||||||
|
" <code value=\"processing\"/>",
|
||||||
|
" <diagnostics value=\"Invalid query parameter(s) for this request: "[_containedType]"\"/>",
|
||||||
|
" </issue>",
|
||||||
|
"</OperationOutcome>"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2?_count=10&_format=xml&_pretty=true");
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
try (InputStream inputStream = status.getEntity().getContent()) {
|
||||||
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
String responseContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
||||||
|
assertThat(responseContent, stringContainsInOrder(
|
||||||
|
"<OperationOutcome xmlns=\"http://hl7.org/fhir\">",
|
||||||
|
" <issue>",
|
||||||
|
" <severity value=\"error\"/>",
|
||||||
|
" <code value=\"processing\"/>",
|
||||||
|
" <diagnostics value=\"Invalid query parameter(s) for this request: "[_count]"\"/>",
|
||||||
|
" </issue>",
|
||||||
|
"</OperationOutcome>"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2?_include=Patient:organization&_format=xml&_pretty=true");
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
try (InputStream inputStream = status.getEntity().getContent()) {
|
||||||
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
String responseContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
||||||
|
assertThat(responseContent, stringContainsInOrder(
|
||||||
|
"<OperationOutcome xmlns=\"http://hl7.org/fhir\">",
|
||||||
|
" <issue>",
|
||||||
|
" <severity value=\"error\"/>",
|
||||||
|
" <code value=\"processing\"/>",
|
||||||
|
" <diagnostics value=\"Invalid query parameter(s) for this request: "[_include]"\"/>",
|
||||||
|
" </issue>",
|
||||||
|
"</OperationOutcome>"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2?_revinclude=Provenance:target&_format=xml&_pretty=true");
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
try (InputStream inputStream = status.getEntity().getContent()) {
|
||||||
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
String responseContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
||||||
|
assertThat(responseContent, stringContainsInOrder(
|
||||||
|
"<OperationOutcome xmlns=\"http://hl7.org/fhir\">",
|
||||||
|
" <issue>",
|
||||||
|
" <severity value=\"error\"/>",
|
||||||
|
" <code value=\"processing\"/>",
|
||||||
|
" <diagnostics value=\"Invalid query parameter(s) for this request: "[_revinclude]"\"/>",
|
||||||
|
" </issue>",
|
||||||
|
"</OperationOutcome>"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2?_sort=family&_format=xml&_pretty=true");
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
try (InputStream inputStream = status.getEntity().getContent()) {
|
||||||
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
String responseContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
||||||
|
assertThat(responseContent, stringContainsInOrder(
|
||||||
|
"<OperationOutcome xmlns=\"http://hl7.org/fhir\">",
|
||||||
|
" <issue>",
|
||||||
|
" <severity value=\"error\"/>",
|
||||||
|
" <code value=\"processing\"/>",
|
||||||
|
" <diagnostics value=\"Invalid query parameter(s) for this request: "[_sort]"\"/>",
|
||||||
|
" </issue>",
|
||||||
|
"</OperationOutcome>"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2?_total=accurate&_format=xml&_pretty=true");
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
try (InputStream inputStream = status.getEntity().getContent()) {
|
||||||
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
String responseContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
||||||
|
assertThat(responseContent, stringContainsInOrder(
|
||||||
|
"<OperationOutcome xmlns=\"http://hl7.org/fhir\">",
|
||||||
|
" <issue>",
|
||||||
|
" <severity value=\"error\"/>",
|
||||||
|
" <code value=\"processing\"/>",
|
||||||
|
" <diagnostics value=\"Invalid query parameter(s) for this request: "[_total]"\"/>",
|
||||||
|
" </issue>",
|
||||||
|
"</OperationOutcome>"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfModifiedSince() throws Exception {
|
public void testIfModifiedSince() throws Exception {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user