Add tests
This commit is contained in:
parent
a8585c881d
commit
344b1256ce
|
@ -27,7 +27,6 @@ import org.hl7.fhir.dstu3.model.Appointment;
|
|||
import org.hl7.fhir.dstu3.model.CodeType;
|
||||
import org.hl7.fhir.dstu3.model.CodeableConcept;
|
||||
import org.hl7.fhir.dstu3.model.Coding;
|
||||
import org.hl7.fhir.dstu3.model.ConceptMap;
|
||||
import org.hl7.fhir.dstu3.model.ContactPoint.ContactPointSystem;
|
||||
import org.hl7.fhir.dstu3.model.DateTimeType;
|
||||
import org.hl7.fhir.dstu3.model.DateType;
|
||||
|
|
|
@ -201,7 +201,7 @@ public class TestRestfulServer extends RestfulServer {
|
|||
* This is a simple paging strategy that keeps the last 10
|
||||
* searches in memory
|
||||
*/
|
||||
setPagingProvider(new FifoMemoryPagingProvider(10));
|
||||
setPagingProvider(new FifoMemoryPagingProvider(10).setMaximumPageSize(500));
|
||||
|
||||
/*
|
||||
* Load interceptors for the server from Spring
|
||||
|
|
|
@ -26,6 +26,7 @@ import ca.uhn.fhir.context.FhirContext;
|
|||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.param.ReferenceParam;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
@ -36,6 +37,7 @@ public class ServerSearchDstu2Test {
|
|||
private static FhirContext ourCtx = FhirContext.forDstu2();
|
||||
private static String ourLastMethod;
|
||||
private static StringParam ourLastRef;
|
||||
private static ReferenceParam ourLastRef2;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerSearchDstu2Test.class);
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
|
@ -44,8 +46,30 @@ public class ServerSearchDstu2Test {
|
|||
public void before() {
|
||||
ourLastMethod = null;
|
||||
ourLastRef = null;
|
||||
ourLastRef2 = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReferenceParamMissingFalse() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/?param3:missing=false");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
assertEquals("searchParam3", ourLastMethod);
|
||||
assertEquals(Boolean.FALSE, ourLastRef2.getMissing());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReferenceParamMissingTrue() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/?param3:missing=true");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
assertEquals("searchParam3", ourLastMethod);
|
||||
assertEquals(Boolean.TRUE, ourLastRef2.getMissing());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchParam1() throws Exception {
|
||||
|
@ -57,19 +81,7 @@ public class ServerSearchDstu2Test {
|
|||
assertEquals("searchParam1", ourLastMethod);
|
||||
assertEquals("param1value", ourLastRef.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchWithEncodedValue() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/?param1=" + URLEncoder.encode("Jernelöv", "UTF-8"));
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
assertEquals("searchParam1", ourLastMethod);
|
||||
assertEquals("Jernelöv", ourLastRef.getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchParam2() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/?param2=param2value&foo=bar");
|
||||
|
@ -92,6 +104,17 @@ public class ServerSearchDstu2Test {
|
|||
assertEquals("param value", ourLastRef.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchWithEncodedValue() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/?param1=" + URLEncoder.encode("Jernelöv", "UTF-8"));
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
assertEquals("searchParam1", ourLastMethod);
|
||||
assertEquals("Jernelöv", ourLastRef.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknownSearchParam() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/?foo=bar");
|
||||
|
@ -102,7 +125,6 @@ public class ServerSearchDstu2Test {
|
|||
assertEquals(null, ourLastMethod);
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
|
@ -133,7 +155,7 @@ public class ServerSearchDstu2Test {
|
|||
}
|
||||
|
||||
public static class DummyPatientResourceProvider {
|
||||
|
||||
|
||||
//@formatter:off
|
||||
@Search(allowUnknownParams=true)
|
||||
public List<IBaseResource> searchParam1(
|
||||
|
@ -166,6 +188,22 @@ public class ServerSearchDstu2Test {
|
|||
}
|
||||
//@formatter:on
|
||||
|
||||
//@formatter:off
|
||||
@Search(allowUnknownParams=true)
|
||||
public List<IBaseResource> searchParam3(
|
||||
@RequiredParam(name = "param3") ReferenceParam theParam) {
|
||||
ourLastMethod = "searchParam3";
|
||||
ourLastRef2 = theParam;
|
||||
|
||||
List<IBaseResource> retVal = new ArrayList<IBaseResource>();
|
||||
Patient patient = new Patient();
|
||||
patient.setId("123");
|
||||
patient.addName().addGiven("GIVEN");
|
||||
retVal.add(patient);
|
||||
return retVal;
|
||||
}
|
||||
//@formatter:on
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue