Merge branch 'master' of github.com:jamesagnew/hapi-fhir

This commit is contained in:
James 2016-12-11 18:13:24 -05:00
commit aa0485206d
3 changed files with 357 additions and 322 deletions

View File

@ -3,6 +3,9 @@ package org.hl7.fhir.dstu3.elementmodel;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
@ -290,7 +293,16 @@ public class XmlParser extends ParserBase {
} }
private Property getElementProp(List<Property> properties, String nodeName) { private Property getElementProp(List<Property> properties, String nodeName) {
for (Property p : properties) List<Property> propsSortedByLongestFirst = new ArrayList<Property>(properties);
// sort properties according to their name longest first, so .requestOrganizationReference comes first before .request[x]
// and therefore the longer property names get evaluated first
Collections.sort(propsSortedByLongestFirst, new Comparator<Property>() {
@Override
public int compare(Property o1, Property o2) {
return o2.getName().length() - o1.getName().length();
}
});
for (Property p : propsSortedByLongestFirst)
if (!p.getDefinition().hasRepresentation(PropertyRepresentation.XMLATTR) && !p.getDefinition().hasRepresentation(PropertyRepresentation.XMLTEXT)) { if (!p.getDefinition().hasRepresentation(PropertyRepresentation.XMLATTR) && !p.getDefinition().hasRepresentation(PropertyRepresentation.XMLTEXT)) {
if (p.getName().equals(nodeName)) if (p.getName().equals(nodeName))
return p; return p;

View File

@ -1,321 +1,321 @@
package ca.uhn.fhir.rest.server; package ca.uhn.fhir.rest.server;
import static org.hamcrest.Matchers.stringContainsInOrder; 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.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.dstu3.model.CodeType; import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.OperationOutcome; import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.dstu3.model.Organization; import org.hl7.fhir.dstu3.model.Organization;
import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.Parameters;
import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.StringType;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.Validate; import ca.uhn.fhir.rest.annotation.Validate;
import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.ValidationModeEnum; import ca.uhn.fhir.rest.api.ValidationModeEnum;
import ca.uhn.fhir.util.PortUtil; import ca.uhn.fhir.util.PortUtil;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
public class ValidateDstu3Test { public class ValidateDstu3Test {
private static CloseableHttpClient ourClient; private static CloseableHttpClient ourClient;
private static FhirContext ourCtx = FhirContext.forDstu3(); private static FhirContext ourCtx = FhirContext.forDstu3();
private static EncodingEnum ourLastEncoding; private static EncodingEnum ourLastEncoding;
private static IdType ourLastId; private static IdType ourLastId;
private static ValidationModeEnum ourLastMode; private static ValidationModeEnum ourLastMode;
public static Patient ourLastPatient; public static Patient ourLastPatient;
private static String ourLastProfile; private static String ourLastProfile;
private static String ourLastResourceBody; private static String ourLastResourceBody;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidateDstu3Test.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidateDstu3Test.class);
private static OperationOutcome ourOutcomeToReturn; private static OperationOutcome ourOutcomeToReturn;
private static int ourPort; private static int ourPort;
private static Server ourServer; private static Server ourServer;
@Before() @Before()
public void before() { public void before() {
ourLastResourceBody = null; ourLastResourceBody = null;
ourLastEncoding = null; ourLastEncoding = null;
ourOutcomeToReturn = null; ourOutcomeToReturn = null;
ourLastMode = null; ourLastMode = null;
ourLastProfile = null; ourLastProfile = null;
} }
@Test @Test
public void testValidate() throws Exception { public void testValidate() throws Exception {
Patient patient = new Patient(); Patient patient = new Patient();
patient.addIdentifier().setValue("001"); patient.addIdentifier().setValue("001");
patient.addIdentifier().setValue("002"); patient.addIdentifier().setValue("002");
Parameters params = new Parameters(); Parameters params = new Parameters();
params.addParameter().setName("resource").setResource(patient); params.addParameter().setName("resource").setResource(patient);
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate");
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost); HttpResponse status = ourClient.execute(httpPost);
String resp = IOUtils.toString(status.getEntity().getContent()); String resp = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(resp, stringContainsInOrder("<OperationOutcome")); assertThat(resp, stringContainsInOrder("<OperationOutcome"));
} }
@Test @Test
public void testValidateBlankMode() throws Exception { public void testValidateBlankMode() throws Exception {
Patient patient = new Patient(); Patient patient = new Patient();
patient.addIdentifier().setValue("001"); patient.addIdentifier().setValue("001");
patient.addIdentifier().setValue("002"); patient.addIdentifier().setValue("002");
Parameters params = new Parameters(); Parameters params = new Parameters();
params.addParameter().setName("resource").setResource(patient); params.addParameter().setName("resource").setResource(patient);
params.addParameter().setName("mode").setValue(new CodeType(" ")); params.addParameter().setName("mode").setValue(new CodeType(" "));
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate");
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost); HttpResponse status = ourClient.execute(httpPost);
String resp = IOUtils.toString(status.getEntity().getContent()); String resp = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(200, status.getStatusLine().getStatusCode());
} }
@Test @Test
public void testValidateInvalidMode() throws Exception { public void testValidateInvalidMode() throws Exception {
Patient patient = new Patient(); Patient patient = new Patient();
patient.addIdentifier().setValue("001"); patient.addIdentifier().setValue("001");
patient.addIdentifier().setValue("002"); patient.addIdentifier().setValue("002");
Parameters params = new Parameters(); Parameters params = new Parameters();
params.addParameter().setName("resource").setResource(patient); params.addParameter().setName("resource").setResource(patient);
params.addParameter().setName("mode").setValue(new CodeType("AAA")); params.addParameter().setName("mode").setValue(new CodeType("AAA"));
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate");
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost); HttpResponse status = ourClient.execute(httpPost);
String resp = IOUtils.toString(status.getEntity().getContent()); String resp = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(400, status.getStatusLine().getStatusCode()); assertEquals(400, status.getStatusLine().getStatusCode());
assertThat(resp, stringContainsInOrder("Invalid mode value: &quot;AAA&quot;")); assertThat(resp, stringContainsInOrder("Invalid mode value: &quot;AAA&quot;"));
} }
@Test @Test
public void testValidateMissingResource() throws Exception { public void testValidateMissingResource() throws Exception {
Patient patient = new Patient(); Patient patient = new Patient();
patient.addIdentifier().setValue("001"); patient.addIdentifier().setValue("001");
patient.addIdentifier().setValue("002"); patient.addIdentifier().setValue("002");
Parameters params = new Parameters(); Parameters params = new Parameters();
params.addParameter().setName("mode").setValue(new CodeType("create")); params.addParameter().setName("mode").setValue(new CodeType("create"));
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate");
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost); HttpResponse status = ourClient.execute(httpPost);
String resp = IOUtils.toString(status.getEntity().getContent()); String resp = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(null, ourLastPatient); assertEquals(null, ourLastPatient);
assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(200, status.getStatusLine().getStatusCode());
} }
@Test @Test
public void testValidateWithGet() throws Exception { public void testValidateWithGet() throws Exception {
ourOutcomeToReturn = new OperationOutcome(); ourOutcomeToReturn = new OperationOutcome();
ourOutcomeToReturn.addIssue().setDiagnostics("FOOBAR"); ourOutcomeToReturn.addIssue().setDiagnostics("FOOBAR");
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/$validate"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/$validate");
HttpResponse status = ourClient.execute(httpGet); HttpResponse status = ourClient.execute(httpGet);
String resp = IOUtils.toString(status.getEntity().getContent()); String resp = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(resp, stringContainsInOrder("<OperationOutcome", "FOOBAR")); assertThat(resp, stringContainsInOrder("<OperationOutcome", "FOOBAR"));
assertEquals(null, ourLastPatient); assertEquals(null, ourLastPatient);
assertEquals("Patient", ourLastId.getResourceType()); assertEquals("Patient", ourLastId.getResourceType());
assertEquals("123", ourLastId.getIdPart()); assertEquals("123", ourLastId.getIdPart());
} }
@Test @Test
public void testValidateWithNoParsed() throws Exception { public void testValidateWithNoParsed() throws Exception {
Organization org = new Organization(); Organization org = new Organization();
org.addIdentifier().setValue("001"); org.addIdentifier().setValue("001");
org.addIdentifier().setValue("002"); org.addIdentifier().setValue("002");
Parameters params = new Parameters(); Parameters params = new Parameters();
params.addParameter().setName("resource").setResource(org); params.addParameter().setName("resource").setResource(org);
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Organization/$validate"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Organization/$validate");
httpPost.setEntity(new StringEntity(ourCtx.newJsonParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); httpPost.setEntity(new StringEntity(ourCtx.newJsonParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost); HttpResponse status = ourClient.execute(httpPost);
assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(ourLastResourceBody, stringContainsInOrder("\"resourceType\":\"Organization\"", "\"identifier\"", "\"value\":\"001")); assertThat(ourLastResourceBody, stringContainsInOrder("\"resourceType\":\"Organization\"", "\"identifier\"", "\"value\":\"001"));
assertEquals(EncodingEnum.JSON, ourLastEncoding); assertEquals(EncodingEnum.JSON, ourLastEncoding);
} }
@Test @Test
public void testValidateWithOptions() throws Exception { public void testValidateWithOptions() throws Exception {
Patient patient = new Patient(); Patient patient = new Patient();
patient.addIdentifier().setValue("001"); patient.addIdentifier().setValue("001");
patient.addIdentifier().setValue("002"); patient.addIdentifier().setValue("002");
Parameters params = new Parameters(); Parameters params = new Parameters();
params.addParameter().setName("resource").setResource(patient); params.addParameter().setName("resource").setResource(patient);
params.addParameter().setName("profile").setValue(new StringType("http://foo")); params.addParameter().setName("profile").setValue(new StringType("http://foo"));
params.addParameter().setName("mode").setValue(new StringType(ValidationModeEnum.CREATE.getCode())); params.addParameter().setName("mode").setValue(new StringType(ValidationModeEnum.CREATE.getCode()));
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate");
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost); HttpResponse status = ourClient.execute(httpPost);
String resp = IOUtils.toString(status.getEntity().getContent()); String resp = IOUtils.toString(status.getEntity().getContent());
ourLog.info(resp); ourLog.info(resp);
IOUtils.closeQuietly(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(resp, stringContainsInOrder("<OperationOutcome")); assertThat(resp, stringContainsInOrder("<OperationOutcome"));
assertEquals("http://foo", ourLastProfile); assertEquals("http://foo", ourLastProfile);
assertEquals(ValidationModeEnum.CREATE, ourLastMode); assertEquals(ValidationModeEnum.CREATE, ourLastMode);
} }
@Test @Test
public void testValidateWithResults() throws Exception { public void testValidateWithResults() throws Exception {
ourOutcomeToReturn = new OperationOutcome(); ourOutcomeToReturn = new OperationOutcome();
ourOutcomeToReturn.addIssue().setDiagnostics("FOOBAR"); ourOutcomeToReturn.addIssue().setDiagnostics("FOOBAR");
Patient patient = new Patient(); Patient patient = new Patient();
patient.addIdentifier().setValue("001"); patient.addIdentifier().setValue("001");
patient.addIdentifier().setValue("002"); patient.addIdentifier().setValue("002");
Parameters params = new Parameters(); Parameters params = new Parameters();
params.addParameter().setName("resource").setResource(patient); params.addParameter().setName("resource").setResource(patient);
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate");
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost); HttpResponse status = ourClient.execute(httpPost);
String resp = IOUtils.toString(status.getEntity().getContent()); String resp = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(resp, stringContainsInOrder("<OperationOutcome", "FOOBAR")); assertThat(resp, stringContainsInOrder("<OperationOutcome", "FOOBAR"));
} }
@AfterClass @AfterClass
public static void afterClassClearContext() throws Exception { public static void afterClassClearContext() throws Exception {
ourServer.stop(); ourServer.stop();
TestUtil.clearAllStaticFieldsForUnitTest(); TestUtil.clearAllStaticFieldsForUnitTest();
} }
@BeforeClass @BeforeClass
public static void beforeClass() throws Exception { public static void beforeClass() throws Exception {
ourPort = PortUtil.findFreePort(); ourPort = PortUtil.findFreePort();
ourServer = new Server(ourPort); ourServer = new Server(ourPort);
PatientProvider patientProvider = new PatientProvider(); PatientProvider patientProvider = new PatientProvider();
ServletHandler proxyHandler = new ServletHandler(); ServletHandler proxyHandler = new ServletHandler();
RestfulServer servlet = new RestfulServer(ourCtx); RestfulServer servlet = new RestfulServer(ourCtx);
servlet.setResourceProviders(patientProvider, new OrganizationProvider()); servlet.setResourceProviders(patientProvider, new OrganizationProvider());
ServletHolder servletHolder = new ServletHolder(servlet); ServletHolder servletHolder = new ServletHolder(servlet);
proxyHandler.addServletWithMapping(servletHolder, "/*"); proxyHandler.addServletWithMapping(servletHolder, "/*");
ourServer.setHandler(proxyHandler); ourServer.setHandler(proxyHandler);
ourServer.start(); ourServer.start();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
HttpClientBuilder builder = HttpClientBuilder.create(); HttpClientBuilder builder = HttpClientBuilder.create();
builder.setConnectionManager(connectionManager); builder.setConnectionManager(connectionManager);
ourClient = builder.build(); ourClient = builder.build();
} }
public static class OrganizationProvider implements IResourceProvider { public static class OrganizationProvider implements IResourceProvider {
@Override @Override
public Class<Organization> getResourceType() { public Class<Organization> getResourceType() {
return Organization.class; return Organization.class;
} }
@Validate() @Validate()
public MethodOutcome validate(@ResourceParam String theResourceBody, @ResourceParam EncodingEnum theEncoding) { public MethodOutcome validate(@ResourceParam String theResourceBody, @ResourceParam EncodingEnum theEncoding) {
ourLastResourceBody = theResourceBody; ourLastResourceBody = theResourceBody;
ourLastEncoding = theEncoding; ourLastEncoding = theEncoding;
return new MethodOutcome(new IdType("001")); return new MethodOutcome(new IdType("001"));
} }
} }
public static class PatientProvider implements IResourceProvider { public static class PatientProvider implements IResourceProvider {
@Override @Override
public Class<Patient> getResourceType() { public Class<Patient> getResourceType() {
return Patient.class; return Patient.class;
} }
@Validate() @Validate()
public MethodOutcome validatePatient(@ResourceParam Patient thePatient, @IdParam(optional=true) IdType theId, @Validate.Mode ValidationModeEnum theMode, @Validate.Profile String theProfile) { public MethodOutcome validatePatient(@ResourceParam Patient thePatient, @IdParam(optional=true) IdType theId, @Validate.Mode ValidationModeEnum theMode, @Validate.Profile String theProfile) {
ourLastPatient = thePatient; ourLastPatient = thePatient;
ourLastId = theId; ourLastId = theId;
IdType id; IdType id;
if (thePatient != null) { if (thePatient != null) {
id = new IdType(thePatient.getIdentifier().get(0).getValue()); id = new IdType(thePatient.getIdentifier().get(0).getValue());
if (thePatient.getIdElement().isEmpty() == false) { if (thePatient.getIdElement().isEmpty() == false) {
id = thePatient.getIdElement(); id = thePatient.getIdElement();
} }
} else { } else {
id = new IdType("1"); id = new IdType("1");
} }
ourLastMode = theMode; ourLastMode = theMode;
ourLastProfile = theProfile; ourLastProfile = theProfile;
MethodOutcome outcome = new MethodOutcome(id.withVersion("002")); MethodOutcome outcome = new MethodOutcome(id.withVersion("002"));
outcome.setOperationOutcome(ourOutcomeToReturn); outcome.setOperationOutcome(ourOutcomeToReturn);
return outcome; return outcome;
} }
} }
} }

View File

@ -249,4 +249,27 @@ public class ResourceValidatorDstu3Test {
assertThat(messageString, not(containsString("valueResource"))); assertThat(messageString, not(containsString("valueResource")));
} }
@Test
public void testValidateDifferentPropertyButSameStartsWithPath() throws Exception {
EnrollmentResponse fhirObj = new EnrollmentResponse();
Organization org = new Organization();
org.setId("1");
fhirObj.setRequestOrganization(new Reference(org));
String input = ourCtx.newXmlParser().encodeResourceToString(fhirObj);
FhirValidator validator = ourCtx.newValidator();
validator.registerValidatorModule(new FhirInstanceValidator());
ValidationResult result = validator.validateWithResult(input);
assertEquals(3, result.getMessages().size());
fhirObj = new EnrollmentResponse();
Identifier ident = new Identifier().setSystem("a").setValue("b");
fhirObj.setRequest(ident);
input = ourCtx.newXmlParser().encodeResourceToString(fhirObj);
result = validator.validateWithResult(input);
assertEquals(2, result.getMessages().size());
}
} }