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.rest.server.interceptor.RequestValidatingInterceptor;
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
import ca.uhn.fhir.util.UrlUtil;
|
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 com.google.common.collect.Lists;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -131,6 +134,27 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
||||||
return retVal;
|
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
|
* 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;
|
return myResourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TreeMap<Long, T> getVersionToResource(String theIdPart) {
|
private synchronized TreeMap<Long, T> getVersionToResource(String theIdPart) {
|
||||||
if (!myIdToVersionToResourceMap.containsKey(theIdPart)) {
|
if (!myIdToVersionToResourceMap.containsKey(theIdPart)) {
|
||||||
myIdToVersionToResourceMap.put(theIdPart, new TreeMap<Long, T>());
|
myIdToVersionToResourceMap.put(theIdPart, new TreeMap<Long, T>());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
@Test
|
||||||
public void testGoal() {
|
public void testGoal() {
|
||||||
Goal goal = new Goal();
|
Goal goal = new Goal();
|
||||||
|
|
|
@ -1,14 +1,5 @@
|
||||||
package org.hl7.fhir.instance.hapi.validation;
|
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.context.FhirContext;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Parameters;
|
import ca.uhn.fhir.model.dstu2.resource.Parameters;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
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.util.TestUtil;
|
||||||
import ca.uhn.fhir.validation.FhirValidator;
|
import ca.uhn.fhir.validation.FhirValidator;
|
||||||
import ca.uhn.fhir.validation.ValidationResult;
|
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 {
|
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 FhirInstanceValidator ourValidator = new FhirInstanceValidator(new DefaultProfileValidationSupport());
|
||||||
private static FhirContext ourCtxDstu2 = FhirContext.forDstu2();
|
private static FhirContext ourCtxDstu2 = FhirContext.forDstu2();
|
||||||
private static FhirContext ourCtxHl7OrgDstu2 = FhirContext.forDstu2Hl7Org();
|
private static FhirContext ourCtxHl7OrgDstu2 = FhirContext.forDstu2Hl7Org();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See #872
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testParametersOkDstu2() {
|
public void testExtensionUrlWithHl7Url() throws IOException {
|
||||||
Patient patient = new Patient();
|
String input = IOUtils.toString(FhirInstanceValidatorTest.class.getResourceAsStream("/bug872-ext-with-hl7-url.json"), Charsets.UTF_8);
|
||||||
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();
|
FhirValidator val = ourCtxDstu2.newValidator();
|
||||||
|
|
||||||
val.registerValidatorModule(ourValidator);
|
val.registerValidatorModule(ourValidator);
|
||||||
|
@ -43,44 +49,6 @@ public class FhirInstanceValidatorTest {
|
||||||
assertTrue(result.isSuccessful());
|
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",
|
"resourceType": "Observation",
|
||||||
|
@ -130,13 +98,12 @@ public class FhirInstanceValidatorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParametersWithTwoParameters() {
|
public void testParametersHl7OrgDstu2() {
|
||||||
org.hl7.fhir.instance.model.Patient patient = new org.hl7.fhir.instance.model.Patient();
|
org.hl7.fhir.instance.model.Patient patient = new org.hl7.fhir.instance.model.Patient();
|
||||||
patient.addName().addGiven("James");
|
patient.addName().addGiven("James");
|
||||||
patient.setBirthDateElement(new DateType("2011-02-02"));
|
patient.setBirthDateElement(new DateType("2011-02-02"));
|
||||||
|
|
||||||
org.hl7.fhir.instance.model.Parameters input = new org.hl7.fhir.instance.model.Parameters();
|
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);
|
input.addParameter().setName("resource").setResource(patient);
|
||||||
|
|
||||||
FhirValidator val = ourCtxHl7OrgDstu2.newValidator();
|
FhirValidator val = ourCtxHl7OrgDstu2.newValidator();
|
||||||
|
@ -145,13 +112,47 @@ public class FhirInstanceValidatorTest {
|
||||||
|
|
||||||
ValidationResult result = val.validateWithResult(input);
|
ValidationResult result = val.validateWithResult(input);
|
||||||
|
|
||||||
String encoded = ourCtxHl7OrgDstu2.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome());
|
ourLog.info(ourCtxHl7OrgDstu2.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome()));
|
||||||
ourLog.info(encoded);
|
|
||||||
|
|
||||||
assertTrue(result.isSuccessful());
|
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
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
|
@ -177,12 +178,13 @@ public class FhirInstanceValidatorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParametersHl7OrgDstu2() {
|
public void testParametersWithTwoParameters() {
|
||||||
org.hl7.fhir.instance.model.Patient patient = new org.hl7.fhir.instance.model.Patient();
|
org.hl7.fhir.instance.model.Patient patient = new org.hl7.fhir.instance.model.Patient();
|
||||||
patient.addName().addGiven("James");
|
patient.addName().addGiven("James");
|
||||||
patient.setBirthDateElement(new DateType("2011-02-02"));
|
patient.setBirthDateElement(new DateType("2011-02-02"));
|
||||||
|
|
||||||
org.hl7.fhir.instance.model.Parameters input = new org.hl7.fhir.instance.model.Parameters();
|
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);
|
input.addParameter().setName("resource").setResource(patient);
|
||||||
|
|
||||||
FhirValidator val = ourCtxHl7OrgDstu2.newValidator();
|
FhirValidator val = ourCtxHl7OrgDstu2.newValidator();
|
||||||
|
@ -191,11 +193,31 @@ public class FhirInstanceValidatorTest {
|
||||||
|
|
||||||
ValidationResult result = val.validateWithResult(input);
|
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());
|
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
|
@AfterClass
|
||||||
public static void afterClassClearContext() {
|
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.ResultSeverityEnum;
|
||||||
import ca.uhn.fhir.validation.SingleValidationMessage;
|
import ca.uhn.fhir.validation.SingleValidationMessage;
|
||||||
import ca.uhn.fhir.validation.ValidationResult;
|
import ca.uhn.fhir.validation.ValidationResult;
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidatorDstu3Test;
|
import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidatorDstu3Test;
|
||||||
|
@ -293,6 +294,17 @@ public class FhirInstanceValidatorR4Test {
|
||||||
assertThat(nonInfo, empty());
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
@Before
|
@Before
|
||||||
public void 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