Tests for #872
This commit is contained in:
parent
2eee606468
commit
790aaeb4ea
|
@ -25,6 +25,9 @@ import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
|||
import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
import ca.uhn.fhir.validation.FhirValidator;
|
||||
import ca.uhn.fhir.validation.ValidationResult;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -131,6 +134,27 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* See #872
|
||||
*/
|
||||
@Test
|
||||
public void testExtensionUrlWithHl7Url() throws IOException {
|
||||
String input = IOUtils.toString(ResourceProviderR4Test.class.getResourceAsStream("/bug872-ext-with-hl7-url.json"), Charsets.UTF_8);
|
||||
|
||||
HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate");
|
||||
post.setEntity(new StringEntity(input, ContentType.APPLICATION_JSON));
|
||||
|
||||
CloseableHttpResponse resp = ourHttpClient.execute(post);
|
||||
try {
|
||||
String respString = IOUtils.toString(resp.getEntity().getContent(), Charsets.UTF_8);
|
||||
ourLog.info(respString);
|
||||
assertEquals(200, resp.getStatusLine().getStatusCode());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(resp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #484
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"resourceType": "Patient",
|
||||
"extension": [
|
||||
{
|
||||
"url": "http://hl7.org/fhir/ValueSet/v3-ActInvoiceGroupCode",
|
||||
"valueString": "test"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -91,7 +91,7 @@ public class HashMapResourceProvider<T extends IBaseResource> implements IResour
|
|||
return myResourceType;
|
||||
}
|
||||
|
||||
private TreeMap<Long, T> getVersionToResource(String theIdPart) {
|
||||
private synchronized TreeMap<Long, T> getVersionToResource(String theIdPart) {
|
||||
if (!myIdToVersionToResourceMap.containsKey(theIdPart)) {
|
||||
myIdToVersionToResourceMap.put(theIdPart, new TreeMap<Long, T>());
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
if (retVal == null) {
|
||||
retVal = myDefaultValidationSupport.expandValueSet(any(FhirContext.class), arg);
|
||||
}
|
||||
ourLog.debug("expandValueSet({}) : {}", new Object[]{theInvocation.getArguments()[0], retVal});
|
||||
ourLog.debug("expandValueSet({}) : {}", new Object[] {theInvocation.getArguments()[0], retVal});
|
||||
return retVal;
|
||||
}
|
||||
});
|
||||
|
@ -97,7 +97,7 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
@Override
|
||||
public Boolean answer(InvocationOnMock theInvocation) {
|
||||
boolean retVal = myValidSystems.contains(theInvocation.getArguments()[1]);
|
||||
ourLog.debug("isCodeSystemSupported({}) : {}", new Object[]{theInvocation.getArguments()[1], retVal});
|
||||
ourLog.debug("isCodeSystemSupported({}) : {}", new Object[] {theInvocation.getArguments()[1], retVal});
|
||||
return retVal;
|
||||
}
|
||||
});
|
||||
|
@ -126,7 +126,7 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
}
|
||||
}
|
||||
if (retVal == null) {
|
||||
ourLog.info("fetchResource({}, {}) : {}", new Object[]{type, id, retVal});
|
||||
ourLog.info("fetchResource({}, {}) : {}", new Object[] {type, id, retVal});
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
} else {
|
||||
retVal = myDefaultValidationSupport.validateCode(ctx, system, code, (String) theInvocation.getArguments()[2]);
|
||||
}
|
||||
ourLog.debug("validateCode({}, {}, {}) : {}", new Object[]{system, code, theInvocation.getArguments()[2], retVal});
|
||||
ourLog.debug("validateCode({}, {}, {}) : {}", new Object[] {system, code, theInvocation.getArguments()[2], retVal});
|
||||
return retVal;
|
||||
}
|
||||
});
|
||||
|
@ -151,7 +151,7 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
@Override
|
||||
public CodeSystem answer(InvocationOnMock theInvocation) {
|
||||
CodeSystem retVal = myDefaultValidationSupport.fetchCodeSystem((FhirContext) theInvocation.getArguments()[0], (String) theInvocation.getArguments()[1]);
|
||||
ourLog.debug("fetchCodeSystem({}) : {}", new Object[]{theInvocation.getArguments()[1], retVal});
|
||||
ourLog.debug("fetchCodeSystem({}) : {}", new Object[] {theInvocation.getArguments()[1], retVal});
|
||||
return retVal;
|
||||
}
|
||||
});
|
||||
|
@ -166,7 +166,7 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
if (retVal == null) {
|
||||
retVal = myDefaultValidationSupport.fetchStructureDefinition((FhirContext) theInvocation.getArguments()[0], url);
|
||||
}
|
||||
ourLog.info("fetchStructureDefinition({}) : {}", new Object[]{url, retVal});
|
||||
ourLog.info("fetchStructureDefinition({}) : {}", new Object[] {url, retVal});
|
||||
return retVal;
|
||||
}
|
||||
});
|
||||
|
@ -174,7 +174,7 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
@Override
|
||||
public List<StructureDefinition> answer(InvocationOnMock theInvocation) {
|
||||
List<StructureDefinition> retVal = myDefaultValidationSupport.fetchAllStructureDefinitions((FhirContext) theInvocation.getArguments()[0]);
|
||||
ourLog.debug("fetchAllStructureDefinitions()", new Object[]{});
|
||||
ourLog.debug("fetchAllStructureDefinitions()", new Object[] {});
|
||||
return retVal;
|
||||
}
|
||||
});
|
||||
|
@ -195,7 +195,7 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
int index = 0;
|
||||
for (SingleValidationMessage next : theOutput.getMessages()) {
|
||||
ourLog.info("Result {}: {} - {}:{} {} - {}",
|
||||
new Object[]{index, next.getSeverity(), defaultString(next.getLocationLine()), defaultString(next.getLocationCol()), next.getLocationString(), next.getMessage()});
|
||||
new Object[] {index, next.getSeverity(), defaultString(next.getLocationLine()), defaultString(next.getLocationCol()), next.getLocationString(), next.getMessage()});
|
||||
index++;
|
||||
|
||||
retVal.add(next);
|
||||
|
@ -209,7 +209,7 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
|
||||
int index = 0;
|
||||
for (SingleValidationMessage next : theOutput.getMessages()) {
|
||||
ourLog.info("Result {}: {} - {} - {}", new Object[]{index, next.getSeverity(), next.getLocationString(), next.getMessage()});
|
||||
ourLog.info("Result {}: {} - {} - {}", new Object[] {index, next.getSeverity(), next.getLocationString(), next.getMessage()});
|
||||
index++;
|
||||
|
||||
if (next.getSeverity() != ResultSeverityEnum.INFORMATION) {
|
||||
|
@ -249,6 +249,17 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* See #872
|
||||
*/
|
||||
@Test
|
||||
public void testExtensionUrlWithHl7Url() throws IOException {
|
||||
String input = IOUtils.toString(FhirInstanceValidatorDstu3Test.class.getResourceAsStream("/bug872-ext-with-hl7-url.json"), Charsets.UTF_8);
|
||||
ValidationResult output = myVal.validateWithResult(input);
|
||||
List<SingleValidationMessage> nonInfo = logResultsAndReturnNonInformationalOnes(output);
|
||||
assertThat(nonInfo, empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGoal() {
|
||||
Goal goal = new Goal();
|
||||
|
|
|
@ -1,14 +1,5 @@
|
|||
package org.hl7.fhir.instance.hapi.validation;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.hl7.fhir.instance.model.*;
|
||||
import org.hl7.fhir.instance.model.Observation.ObservationStatus;
|
||||
import org.hl7.fhir.instance.model.QuestionnaireResponse.QuestionnaireResponseStatus;
|
||||
import org.junit.*;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Parameters;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
|
@ -17,22 +8,37 @@ import ca.uhn.fhir.model.primitive.StringDt;
|
|||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.validation.FhirValidator;
|
||||
import ca.uhn.fhir.validation.ValidationResult;
|
||||
import com.google.common.base.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hl7.fhir.instance.model.DateType;
|
||||
import org.hl7.fhir.instance.model.Observation;
|
||||
import org.hl7.fhir.instance.model.Observation.ObservationStatus;
|
||||
import org.hl7.fhir.instance.model.QuestionnaireResponse;
|
||||
import org.hl7.fhir.instance.model.QuestionnaireResponse.QuestionnaireResponseStatus;
|
||||
import org.hl7.fhir.instance.model.StringType;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class FhirInstanceValidatorTest {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirInstanceValidatorTest.class);
|
||||
private static FhirInstanceValidator ourValidator = new FhirInstanceValidator(new DefaultProfileValidationSupport());
|
||||
private static FhirContext ourCtxDstu2 = FhirContext.forDstu2();
|
||||
private static FhirContext ourCtxHl7OrgDstu2 = FhirContext.forDstu2Hl7Org();
|
||||
|
||||
/**
|
||||
* See #872
|
||||
*/
|
||||
@Test
|
||||
public void testParametersOkDstu2() {
|
||||
Patient patient = new Patient();
|
||||
patient.addName().addGiven("James");
|
||||
patient.setBirthDate(new DateDt("2011-02-02"));
|
||||
|
||||
Parameters input = new Parameters();
|
||||
input.addParameter().setName("resource").setResource(patient);
|
||||
|
||||
public void testExtensionUrlWithHl7Url() throws IOException {
|
||||
String input = IOUtils.toString(FhirInstanceValidatorTest.class.getResourceAsStream("/bug872-ext-with-hl7-url.json"), Charsets.UTF_8);
|
||||
FhirValidator val = ourCtxDstu2.newValidator();
|
||||
|
||||
val.registerValidatorModule(ourValidator);
|
||||
|
@ -43,44 +49,6 @@ public class FhirInstanceValidatorTest {
|
|||
assertTrue(result.isSuccessful());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testParametersWithParameterNoValue() {
|
||||
Parameters input = new Parameters();
|
||||
input.addParameter().setName("resource");
|
||||
|
||||
FhirValidator val = ourCtxDstu2.newValidator();
|
||||
|
||||
val.registerValidatorModule(ourValidator);
|
||||
|
||||
ValidationResult result = val.validateWithResult(input);
|
||||
|
||||
String encoded = ourCtxDstu2.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome());
|
||||
ourLog.info(encoded);
|
||||
|
||||
assertFalse(result.isSuccessful());
|
||||
assertThat(encoded, containsString("A parameter must have a value or a resource, but not both"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuestionnaireResponse() {
|
||||
QuestionnaireResponse qr = new QuestionnaireResponse();
|
||||
qr.setStatus(QuestionnaireResponseStatus.COMPLETED);
|
||||
qr.getGroup().addGroup().addQuestion().setLinkId("foo");
|
||||
qr.getGroup().addQuestion().setLinkId("bar");
|
||||
|
||||
FhirValidator val = ourCtxHl7OrgDstu2.newValidator();
|
||||
|
||||
val.registerValidatorModule(ourValidator);
|
||||
|
||||
ValidationResult result = val.validateWithResult(qr);
|
||||
|
||||
String encoded = ourCtxHl7OrgDstu2.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome());
|
||||
ourLog.info(encoded);
|
||||
|
||||
assertTrue(result.isSuccessful());
|
||||
}
|
||||
|
||||
/*
|
||||
* {
|
||||
"resourceType": "Observation",
|
||||
|
@ -130,13 +98,12 @@ public class FhirInstanceValidatorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testParametersWithTwoParameters() {
|
||||
public void testParametersHl7OrgDstu2() {
|
||||
org.hl7.fhir.instance.model.Patient patient = new org.hl7.fhir.instance.model.Patient();
|
||||
patient.addName().addGiven("James");
|
||||
patient.setBirthDateElement(new DateType("2011-02-02"));
|
||||
|
||||
org.hl7.fhir.instance.model.Parameters input = new org.hl7.fhir.instance.model.Parameters();
|
||||
input.addParameter().setName("mode").setValue(new StringType("create"));
|
||||
input.addParameter().setName("resource").setResource(patient);
|
||||
|
||||
FhirValidator val = ourCtxHl7OrgDstu2.newValidator();
|
||||
|
@ -145,13 +112,47 @@ public class FhirInstanceValidatorTest {
|
|||
|
||||
ValidationResult result = val.validateWithResult(input);
|
||||
|
||||
String encoded = ourCtxHl7OrgDstu2.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome());
|
||||
ourLog.info(encoded);
|
||||
|
||||
ourLog.info(ourCtxHl7OrgDstu2.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome()));
|
||||
assertTrue(result.isSuccessful());
|
||||
assertThat(encoded, not(containsString("A parameter must have a value or a resource, but not both")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParametersOkDstu2() {
|
||||
Patient patient = new Patient();
|
||||
patient.addName().addGiven("James");
|
||||
patient.setBirthDate(new DateDt("2011-02-02"));
|
||||
|
||||
Parameters input = new Parameters();
|
||||
input.addParameter().setName("resource").setResource(patient);
|
||||
|
||||
FhirValidator val = ourCtxDstu2.newValidator();
|
||||
|
||||
val.registerValidatorModule(ourValidator);
|
||||
|
||||
ValidationResult result = val.validateWithResult(input);
|
||||
|
||||
ourLog.info(ourCtxDstu2.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome()));
|
||||
assertTrue(result.isSuccessful());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testParametersWithParameterNoValue() {
|
||||
Parameters input = new Parameters();
|
||||
input.addParameter().setName("resource");
|
||||
|
||||
FhirValidator val = ourCtxDstu2.newValidator();
|
||||
|
||||
val.registerValidatorModule(ourValidator);
|
||||
|
||||
ValidationResult result = val.validateWithResult(input);
|
||||
|
||||
String encoded = ourCtxDstu2.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome());
|
||||
ourLog.info(encoded);
|
||||
|
||||
assertFalse(result.isSuccessful());
|
||||
assertThat(encoded, containsString("A parameter must have a value or a resource, but not both"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
|
@ -177,12 +178,13 @@ public class FhirInstanceValidatorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testParametersHl7OrgDstu2() {
|
||||
public void testParametersWithTwoParameters() {
|
||||
org.hl7.fhir.instance.model.Patient patient = new org.hl7.fhir.instance.model.Patient();
|
||||
patient.addName().addGiven("James");
|
||||
patient.setBirthDateElement(new DateType("2011-02-02"));
|
||||
|
||||
org.hl7.fhir.instance.model.Parameters input = new org.hl7.fhir.instance.model.Parameters();
|
||||
input.addParameter().setName("mode").setValue(new StringType("create"));
|
||||
input.addParameter().setName("resource").setResource(patient);
|
||||
|
||||
FhirValidator val = ourCtxHl7OrgDstu2.newValidator();
|
||||
|
@ -191,11 +193,31 @@ public class FhirInstanceValidatorTest {
|
|||
|
||||
ValidationResult result = val.validateWithResult(input);
|
||||
|
||||
ourLog.info(ourCtxHl7OrgDstu2.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome()));
|
||||
String encoded = ourCtxHl7OrgDstu2.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome());
|
||||
ourLog.info(encoded);
|
||||
|
||||
assertTrue(result.isSuccessful());
|
||||
assertThat(encoded, not(containsString("A parameter must have a value or a resource, but not both")));
|
||||
}
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirInstanceValidatorTest.class);
|
||||
@Test
|
||||
public void testQuestionnaireResponse() {
|
||||
QuestionnaireResponse qr = new QuestionnaireResponse();
|
||||
qr.setStatus(QuestionnaireResponseStatus.COMPLETED);
|
||||
qr.getGroup().addGroup().addQuestion().setLinkId("foo");
|
||||
qr.getGroup().addQuestion().setLinkId("bar");
|
||||
|
||||
FhirValidator val = ourCtxHl7OrgDstu2.newValidator();
|
||||
|
||||
val.registerValidatorModule(ourValidator);
|
||||
|
||||
ValidationResult result = val.validateWithResult(qr);
|
||||
|
||||
String encoded = ourCtxHl7OrgDstu2.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome());
|
||||
ourLog.info(encoded);
|
||||
|
||||
assertTrue(result.isSuccessful());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
|
|
|
@ -22,6 +22,7 @@ import ca.uhn.fhir.validation.FhirValidator;
|
|||
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
||||
import ca.uhn.fhir.validation.SingleValidationMessage;
|
||||
import ca.uhn.fhir.validation.ValidationResult;
|
||||
import com.google.common.base.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidatorDstu3Test;
|
||||
|
@ -293,6 +294,17 @@ public class FhirInstanceValidatorR4Test {
|
|||
assertThat(nonInfo, empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* See #872
|
||||
*/
|
||||
@Test
|
||||
public void testExtensionUrlWithHl7Url() throws IOException {
|
||||
String input = IOUtils.toString(FhirInstanceValidator.class.getResourceAsStream("/bug872-ext-with-hl7-url.json"), Charsets.UTF_8);
|
||||
ValidationResult output = myVal.validateWithResult(input);
|
||||
List<SingleValidationMessage> nonInfo = logResultsAndReturnNonInformationalOnes(output);
|
||||
assertThat(nonInfo, empty());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void before() {
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"resourceType": "Patient",
|
||||
"extension": [
|
||||
{
|
||||
"url": "http://hl7.org/fhir/ValueSet/v3-ActInvoiceGroupCode",
|
||||
"valueString": "test"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue