Add test case for invalid query parameters in read operation

This commit is contained in:
Jafer Khan 2020-04-01 02:02:52 +05:00 committed by James Agnew
parent 0021561fb1
commit ce012ff7cf
1 changed files with 126 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
@ -64,6 +65,131 @@ public class ReadDstu3Test {
"</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: &quot;[_contained]&quot;\"/>",
" </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: &quot;[_containedType]&quot;\"/>",
" </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: &quot;[_count]&quot;\"/>",
" </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: &quot;[_include]&quot;\"/>",
" </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: &quot;[_revinclude]&quot;\"/>",
" </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: &quot;[_sort]&quot;\"/>",
" </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: &quot;[_total]&quot;\"/>",
" </issue>",
"</OperationOutcome>"
));
}
}
@Test
public void testIfModifiedSince() throws Exception {