Unit test fixes

This commit is contained in:
jamesagnew 2014-03-19 17:38:31 -04:00
parent f278d9d096
commit 31e8584f12
9 changed files with 436 additions and 212 deletions

View File

@ -10,8 +10,6 @@
and maybe a way to configure this in the FhirContext so that the parser
can take advantage?
* Return link-self in returned bundles from server
* Add SimpleSetters for all primitive datatypes
* Implement and add Simple Getters in a similar way to simple setters

View File

@ -272,6 +272,7 @@ public class JsonParser extends BaseParser implements IParser {
if (theChildName != null) {
theWriter.writeStartObject(theChildName);
} else {
theWriter.flush();//TODO: remove
theWriter.writeStartObject();
}
encodeCompositeElementToStreamWriter(theValue, theWriter, childCompositeDef);
@ -377,6 +378,7 @@ public class JsonParser extends BaseParser implements IParser {
}
currentChildName = childName;
} else {
theEventWriter.flush();//TODO: remove
encodeChildElementToStreamWriter(theEventWriter, nextValue, childDef, null);
}
@ -410,6 +412,7 @@ public class JsonParser extends BaseParser implements IParser {
nextExt.write(theEventWriter);
}
theEventWriter.writeEnd();
theEventWriter.writeEnd();
}
if (!haveContent) {
@ -438,6 +441,7 @@ public class JsonParser extends BaseParser implements IParser {
// }
theEventWriter.writeEnd();
theEventWriter.flush(); // TODO: remove
}
}

View File

@ -274,7 +274,7 @@ class ParserState<T extends IElement> {
@Override
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
throw new DataFormatException("Found unexpected element content");
throw new DataFormatException("Found unexpected element content '" + theLocalPart + "' within <link>");
}
}

View File

@ -517,6 +517,7 @@ public class XmlParser extends BaseParser implements IParser {
theEventWriter.writeStartElement("link");
theEventWriter.writeAttribute("rel", theRel);
theEventWriter.writeAttribute("href", theStringDt.getValue());
theEventWriter.writeEndElement();
}
}

View File

@ -19,6 +19,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.core.IsNot;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
@ -184,17 +185,23 @@ public abstract class RestfulServer extends HttpServlet {
}
String resourceName = null;
String requestPath = StringUtils.defaultString(request.getRequestURI());
String contextPath = StringUtils.defaultString(request.getContextPath());
String requestFullPath = StringUtils.defaultString(request.getRequestURI());
// String contextPath = StringUtils.defaultString(request.getContextPath());
String servletPath = StringUtils.defaultString(request.getServletPath());
IdDt id = null;
IdDt versionId = null;
String operation = null;
requestPath = requestPath.substring(contextPath.length());
if (requestPath.charAt(0) == '/') {
String requestPath = requestFullPath.substring(servletPath.length());
if (requestPath.length() > 0 && requestPath.charAt(0) == '/') {
requestPath = requestPath.substring(1);
}
StringBuffer requestUrl = request.getRequestURL();
int contextIndex = requestUrl.indexOf(servletPath);
String fhirServerBase = requestUrl.substring(0, contextIndex + servletPath.length());
String completeUrl = StringUtils.isNotBlank(request.getQueryString()) ? requestUrl + "?" + request.getQueryString() : requestUrl.toString();
ourLog.info("Request URI: {}", requestPath);
Map<String, String[]> params = new HashMap<String, String[]>(request.getParameterMap());
@ -256,7 +263,7 @@ public abstract class RestfulServer extends HttpServlet {
List<IResource> result = resourceMethod.invokeServer(resourceBinding.getResourceProvider(), id, versionId, params);
switch (resourceMethod.getReturnType()) {
case BUNDLE:
streamResponseAsBundle(response, result, responseEncoding);
streamResponseAsBundle(response, result, responseEncoding, fhirServerBase, completeUrl);
break;
case RESOURCE:
if (result.size() == 0) {
@ -329,7 +336,7 @@ public abstract class RestfulServer extends HttpServlet {
}
}
private void streamResponseAsBundle(HttpServletResponse theHttpResponse, List<IResource> theResult, EncodingUtil theResponseEncoding) throws IOException {
private void streamResponseAsBundle(HttpServletResponse theHttpResponse, List<IResource> theResult, EncodingUtil theResponseEncoding, String theFhirServerBase, String theCompleteUrl) throws IOException {
theHttpResponse.setStatus(200);
theHttpResponse.setContentType(theResponseEncoding.getBundleContentType());
theHttpResponse.setCharacterEncoding("UTF-8");
@ -338,6 +345,8 @@ public abstract class RestfulServer extends HttpServlet {
bundle.getAuthorName().setValue(getClass().getCanonicalName());
bundle.getBundleId().setValue(UUID.randomUUID().toString());
bundle.getPublished().setToCurrentTimeInLocalTimeZone();
bundle.getLinkBase().setValue(theFhirServerBase);
bundle.getLinkSelf().setValue(theCompleteUrl);
for (IResource next : theResult) {
BundleEntry entry = new BundleEntry();

View File

@ -1,169 +0,0 @@
package ca.uhn.fhir.rest.server;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import ca.uhn.fhir.model.api.PathSpecification;
import ca.uhn.fhir.model.dstu.composite.CodingDt;
import ca.uhn.fhir.model.dstu.composite.HumanNameDt;
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt;
import ca.uhn.fhir.rest.annotation.Include;
import ca.uhn.fhir.rest.annotation.Optional;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.Required;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.param.CodingListParam;
import ca.uhn.fhir.rest.param.QualifiedDateParam;
/**
* Created by dsotnikov on 2/25/2014.
*/
public class DummyPatientResourceProvider implements IResourceProvider {
public Map<String, Patient> getIdToPatient() {
Map<String, Patient> idToPatient = new HashMap<String, Patient>();
{
Patient patient = new Patient();
patient.addIdentifier();
patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL);
patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
patient.getIdentifier().get(0).setValue("00001");
patient.addName();
patient.getName().get(0).addFamily("Test");
patient.getName().get(0).addGiven("PatientOne");
patient.getGender().setText("M");
idToPatient.put("1", patient);
}
{
Patient patient = new Patient();
patient.getIdentifier().add(new IdentifierDt());
patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL);
patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
patient.getIdentifier().get(0).setValue("00002");
patient.getName().add(new HumanNameDt());
patient.getName().get(0).addFamily("Test");
patient.getName().get(0).addGiven("PatientTwo");
patient.getGender().setText("F");
idToPatient.put("2", patient);
}
return idToPatient;
}
@Search()
public Patient getPatientWithIncludes(@Required(name = "withIncludes") StringDt theString, @Include List<PathSpecification> theIncludes) {
Patient next = getIdToPatient().get("1");
next.addCommunication().setText(theString.getValue());
for (PathSpecification line : theIncludes) {
next.addAddress().addLine(line.getValue());
}
return next;
}
@Search()
public Patient getPatient(@Required(name = Patient.SP_IDENTIFIER) IdentifierDt theIdentifier) {
for (Patient next : getIdToPatient().values()) {
for (IdentifierDt nextId : next.getIdentifier()) {
if (nextId.matchesSystemAndValue(theIdentifier)) {
return next;
}
}
}
return null;
}
@Search()
public Patient getPatientWithDOB(@Required(name = "dob") QualifiedDateParam theDob) {
Patient next = getIdToPatient().get("1");
if (theDob.getComparator()!=null) {
next.addIdentifier().setValue(theDob.getComparator().getCode());
}else {
next.addIdentifier().setValue("NONE");
}
next.addIdentifier().setValue(theDob.getValueAsString());
return next;
}
@Search()
public List<Patient> getPatientWithOptionalName(@Required(name = "name1") StringDt theName1, @Optional(name = "name2") StringDt theName2) {
List<Patient> retVal = new ArrayList<Patient>();
Patient next = getIdToPatient().get("1");
next.getName().get(0).getFamily().set(0, theName1);
if (theName2 != null) {
next.getName().get(0).getGiven().set(0, theName2);
}
retVal.add(next);
return retVal;
}
/**
* @param theName3
*/
@Search()
public List<Patient> getPatientWithOptionalName(@Required(name = "aaa") StringDt theName1, @Optional(name = "bbb") StringDt theName2, @Optional(name = "ccc") StringDt theName3) {
List<Patient> retVal = new ArrayList<Patient>();
Patient next = getIdToPatient().get("1");
next.getName().get(0).getFamily().set(0, theName1);
if (theName2 != null) {
next.getName().get(0).getGiven().set(0, theName2);
}
retVal.add(next);
return retVal;
}
@Search()
public List<Patient> getPatientMultipleIdentifiers(@Required(name = "ids") CodingListParam theIdentifiers) {
List<Patient> retVal = new ArrayList<Patient>();
Patient next = getIdToPatient().get("1");
for (CodingDt nextId : theIdentifiers.getCodings()) {
next.getIdentifier().add(new IdentifierDt(nextId.getSystem().getValueAsString(), nextId.getCode().getValue()));
}
retVal.add(next);
return retVal;
}
/**
* Retrieve the resource by its identifier
*
* @param theId
* The resource identity
* @return The resource
*/
@Read()
public Patient getResourceById(@Read.IdParam IdDt theId) {
return getIdToPatient().get(theId.getValue());
}
@Read()
public Patient getResourceById(@Read.IdParam IdDt theId, @Read.VersionIdParam IdDt theVersionId) {
Patient retVal = getIdToPatient().get(theId.getValue());
retVal.getName().get(0).setText(theVersionId.getValue());
return retVal;
}
@Search()
public Collection<Patient> getResources() {
return getIdToPatient().values();
}
@Override
public Class<Patient> getResourceType() {
return Patient.class;
}
}

View File

@ -1,26 +0,0 @@
package ca.uhn.fhir.rest.server;
import java.util.Arrays;
import java.util.Collection;
public class DummyRestfulServer extends RestfulServer {
private static final long serialVersionUID = 1L;
private Collection<IResourceProvider> myResourceProviders;
public DummyRestfulServer(IResourceProvider... theResourceProviders) {
myResourceProviders = Arrays.asList(theResourceProviders);
}
@Override
public Collection<IResourceProvider> getResourceProviders() {
return myResourceProviders;
}
@Override
public ISecurityManager getSecurityManager() {
return null;
}
}

View File

@ -1,7 +1,15 @@
package ca.uhn.fhir.rest.server;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
@ -20,10 +28,24 @@ import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.PathSpecification;
import ca.uhn.fhir.model.dstu.composite.CodingDt;
import ca.uhn.fhir.model.dstu.composite.HumanNameDt;
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
import ca.uhn.fhir.model.dstu.resource.Conformance;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu.resource.Profile;
import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.annotation.Include;
import ca.uhn.fhir.rest.annotation.Optional;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.Required;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.param.CodingListParam;
import ca.uhn.fhir.rest.param.QualifiedDateParam;
import ca.uhn.fhir.rest.server.provider.ServerProfileProvider;
import ca.uhn.fhir.testutil.RandomServerPortProvider;
import ca.uhn.fhir.util.ExtensionConstants;
@ -31,9 +53,9 @@ import ca.uhn.fhir.util.ExtensionConstants;
/**
* Created by dsotnikov on 2/25/2014.
*/
public class ResfulServerTest {
public class ResfulServerMethodTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResfulServerTest.class);
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResfulServerMethodTest.class);
private static int ourPort;
private static Server ourServer;
private static CloseableHttpClient ourClient;
@ -50,7 +72,7 @@ public class ResfulServerTest {
ServletHandler proxyHandler = new ServletHandler();
ServletHolder servletHolder = new ServletHolder(new DummyRestfulServer(patientProvider,profProvider));
proxyHandler.addServletWithMapping(servletHolder, "/");
proxyHandler.addServletWithMapping(servletHolder, "/*");
ourServer.setHandler(proxyHandler);
ourServer.start();
@ -102,7 +124,7 @@ public class ResfulServerTest {
}
@Test
public void testGetMetadata() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/metadata");
@ -116,6 +138,9 @@ public class ResfulServerTest {
Conformance bundle = parser.parseResource(Conformance.class, responseContent);
IParser p = ourCtx.newJsonParser().setPrettyPrint(true);
p.encodeResourceToWriter(bundle, new OutputStreamWriter(System.out));
String enc = p.encodeResourceToString(bundle);
ourLog.info("Response:\n{}", enc);
assertTrue(enc.contains(ExtensionConstants.CONF_ALSO_CHAIN));
@ -409,4 +434,175 @@ public class ResfulServerTest {
}
public static class DummyRestfulServer extends RestfulServer {
private static final long serialVersionUID = 1L;
private Collection<IResourceProvider> myResourceProviders;
public DummyRestfulServer(IResourceProvider... theResourceProviders) {
myResourceProviders = Arrays.asList(theResourceProviders);
}
@Override
public Collection<IResourceProvider> getResourceProviders() {
return myResourceProviders;
}
@Override
public ISecurityManager getSecurityManager() {
return null;
}
}
/**
* Created by dsotnikov on 2/25/2014.
*/
public static class DummyPatientResourceProvider implements IResourceProvider {
public Map<String, Patient> getIdToPatient() {
Map<String, Patient> idToPatient = new HashMap<String, Patient>();
{
Patient patient = new Patient();
patient.addIdentifier();
patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL);
patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
patient.getIdentifier().get(0).setValue("00001");
patient.addName();
patient.getName().get(0).addFamily("Test");
patient.getName().get(0).addGiven("PatientOne");
patient.getGender().setText("M");
idToPatient.put("1", patient);
}
{
Patient patient = new Patient();
patient.getIdentifier().add(new IdentifierDt());
patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL);
patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
patient.getIdentifier().get(0).setValue("00002");
patient.getName().add(new HumanNameDt());
patient.getName().get(0).addFamily("Test");
patient.getName().get(0).addGiven("PatientTwo");
patient.getGender().setText("F");
idToPatient.put("2", patient);
}
return idToPatient;
}
@Search()
public Patient getPatientWithIncludes(@Required(name = "withIncludes") StringDt theString, @Include List<PathSpecification> theIncludes) {
Patient next = getIdToPatient().get("1");
next.addCommunication().setText(theString.getValue());
for (PathSpecification line : theIncludes) {
next.addAddress().addLine(line.getValue());
}
return next;
}
@Search()
public Patient getPatient(@Required(name = Patient.SP_IDENTIFIER) IdentifierDt theIdentifier) {
for (Patient next : getIdToPatient().values()) {
for (IdentifierDt nextId : next.getIdentifier()) {
if (nextId.matchesSystemAndValue(theIdentifier)) {
return next;
}
}
}
return null;
}
@Search()
public Patient getPatientWithDOB(@Required(name = "dob") QualifiedDateParam theDob) {
Patient next = getIdToPatient().get("1");
if (theDob.getComparator()!=null) {
next.addIdentifier().setValue(theDob.getComparator().getCode());
}else {
next.addIdentifier().setValue("NONE");
}
next.addIdentifier().setValue(theDob.getValueAsString());
return next;
}
@Search()
public List<Patient> getPatientWithOptionalName(@Required(name = "name1") StringDt theName1, @Optional(name = "name2") StringDt theName2) {
List<Patient> retVal = new ArrayList<Patient>();
Patient next = getIdToPatient().get("1");
next.getName().get(0).getFamily().set(0, theName1);
if (theName2 != null) {
next.getName().get(0).getGiven().set(0, theName2);
}
retVal.add(next);
return retVal;
}
/**
* @param theName3
*/
@Search()
public List<Patient> getPatientWithOptionalName(@Required(name = "aaa") StringDt theName1, @Optional(name = "bbb") StringDt theName2, @Optional(name = "ccc") StringDt theName3) {
List<Patient> retVal = new ArrayList<Patient>();
Patient next = getIdToPatient().get("1");
next.getName().get(0).getFamily().set(0, theName1);
if (theName2 != null) {
next.getName().get(0).getGiven().set(0, theName2);
}
retVal.add(next);
return retVal;
}
@Search()
public List<Patient> getPatientMultipleIdentifiers(@Required(name = "ids") CodingListParam theIdentifiers) {
List<Patient> retVal = new ArrayList<Patient>();
Patient next = getIdToPatient().get("1");
for (CodingDt nextId : theIdentifiers.getCodings()) {
next.getIdentifier().add(new IdentifierDt(nextId.getSystem().getValueAsString(), nextId.getCode().getValue()));
}
retVal.add(next);
return retVal;
}
/**
* Retrieve the resource by its identifier
*
* @param theId
* The resource identity
* @return The resource
*/
@Read()
public Patient getResourceById(@Read.IdParam IdDt theId) {
return getIdToPatient().get(theId.getValue());
}
@Read()
public Patient getResourceById(@Read.IdParam IdDt theId, @Read.VersionIdParam IdDt theVersionId) {
Patient retVal = getIdToPatient().get(theId.getValue());
retVal.getName().get(0).setText(theVersionId.getValue());
return retVal;
}
@Search()
public Collection<Patient> getResources() {
return getIdToPatient().values();
}
@Override
public Class<Patient> getResourceType() {
return Patient.class;
}
}
}

View File

@ -0,0 +1,211 @@
package ca.uhn.fhir.rest.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.PathSpecification;
import ca.uhn.fhir.model.dstu.composite.CodingDt;
import ca.uhn.fhir.model.dstu.composite.HumanNameDt;
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
import ca.uhn.fhir.model.dstu.resource.Conformance;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.annotation.Include;
import ca.uhn.fhir.rest.annotation.Optional;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.Required;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.param.CodingListParam;
import ca.uhn.fhir.rest.param.QualifiedDateParam;
import ca.uhn.fhir.rest.server.provider.ServerProfileProvider;
import ca.uhn.fhir.testutil.RandomServerPortProvider;
import ca.uhn.fhir.util.ExtensionConstants;
/**
* Created by dsotnikov on 2/25/2014.
*/
public class ResfulServerSelfReferenceTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResfulServerSelfReferenceTest.class);
private static int ourPort;
private static Server ourServer;
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx;
@BeforeClass
public static void beforeClass() throws Exception {
ourPort = RandomServerPortProvider.findFreePort();
ourServer = new Server(ourPort);
ourCtx = new FhirContext(Patient.class);
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
ServerProfileProvider profProvider=new ServerProfileProvider(ourCtx);
ServletHandler proxyHandler = new ServletHandler();
ServletHolder servletHolder = new ServletHolder(new DummyRestfulServer(patientProvider,profProvider));
proxyHandler.addServletWithMapping(servletHolder, "/fhir/context/*");
ourServer.setHandler(proxyHandler);
ourServer.start();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setConnectionManager(connectionManager);
ourClient = builder.build();
}
@AfterClass
public static void afterClass() throws Exception {
ourServer.stop();
}
@Test
public void testSearchByParamIdentifier() throws Exception {
String baseUri = "http://localhost:" + ourPort + "/fhir/context";
String uri = baseUri + "/Patient?identifier=urn:hapitest:mrns%7C00001";
HttpGet httpGet = new HttpGet(uri);
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
assertEquals(1, bundle.getEntries().size());
Patient patient = (Patient) bundle.getEntries().get(0).getResource();
assertEquals("PatientOne", patient.getName().get(0).getGiven().get(0).getValue());
assertEquals(uri, bundle.getLinkSelf().getValue());
assertEquals(baseUri, bundle.getLinkBase().getValue());
}
public static class DummyRestfulServer extends RestfulServer {
private static final long serialVersionUID = 1L;
private Collection<IResourceProvider> myResourceProviders;
public DummyRestfulServer(IResourceProvider... theResourceProviders) {
myResourceProviders = Arrays.asList(theResourceProviders);
}
@Override
public Collection<IResourceProvider> getResourceProviders() {
return myResourceProviders;
}
@Override
public ISecurityManager getSecurityManager() {
return null;
}
}
/**
* Created by dsotnikov on 2/25/2014.
*/
public static class DummyPatientResourceProvider implements IResourceProvider {
public Map<String, Patient> getIdToPatient() {
Map<String, Patient> idToPatient = new HashMap<String, Patient>();
{
Patient patient = new Patient();
patient.addIdentifier();
patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL);
patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
patient.getIdentifier().get(0).setValue("00001");
patient.addName();
patient.getName().get(0).addFamily("Test");
patient.getName().get(0).addGiven("PatientOne");
patient.getGender().setText("M");
idToPatient.put("1", patient);
}
{
Patient patient = new Patient();
patient.getIdentifier().add(new IdentifierDt());
patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL);
patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
patient.getIdentifier().get(0).setValue("00002");
patient.getName().add(new HumanNameDt());
patient.getName().get(0).addFamily("Test");
patient.getName().get(0).addGiven("PatientTwo");
patient.getGender().setText("F");
idToPatient.put("2", patient);
}
return idToPatient;
}
@Search()
public Patient getPatient(@Required(name = Patient.SP_IDENTIFIER) IdentifierDt theIdentifier) {
for (Patient next : getIdToPatient().values()) {
for (IdentifierDt nextId : next.getIdentifier()) {
if (nextId.matchesSystemAndValue(theIdentifier)) {
return next;
}
}
}
return null;
}
/**
* Retrieve the resource by its identifier
*
* @param theId
* The resource identity
* @return The resource
*/
@Read()
public Patient getResourceById(@Read.IdParam IdDt theId) {
return getIdToPatient().get(theId.getValue());
}
@Override
public Class<Patient> getResourceType() {
return Patient.class;
}
}
}