From 3a03d4ff63562e59fb449c33a41f6a8fe5a2ff80 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Sun, 13 May 2018 10:31:54 -0400 Subject: [PATCH] Add test for #942 --- .../FhirInstanceValidatorR4Test.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java index 4d238bf8c71..f0405143199 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java @@ -26,6 +26,7 @@ import org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionKind; import org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent; import org.hl7.fhir.r4.utils.FHIRPathEngine; +import org.hl7.fhir.r4.utils.IResourceValidator; import org.hl7.fhir.utilities.validation.ValidationMessage; import org.junit.*; import org.junit.rules.TestRule; @@ -212,6 +213,40 @@ public class FhirInstanceValidatorR4Test { assertEquals("primitive types must have a value or must have child extensions", all.get(0).getMessage()); } + /** + * See #942 + */ + @Test + public void testValidateDoesntEnforceBestPracticesByDefault() { + Observation input = new Observation(); + input.setStatus(ObservationStatus.AMENDED); + input.getCode().addCoding().setSystem("http://loinc.org").setCode("1234").setDisplay("FOO"); + + FhirInstanceValidator instanceModule; + FhirValidator val; + ValidationResult result; + List all; + + // With BPs disabled + val = ourCtx.newValidator(); + instanceModule = new FhirInstanceValidator(myDefaultValidationSupport); + val.registerValidatorModule(instanceModule); + result = val.validateWithResult(input); + all = logResultsAndReturnAll(result); + assertTrue(result.isSuccessful()); + assertThat(all, empty()); + + // With BPs enabled + val = ourCtx.newValidator(); + instanceModule = new FhirInstanceValidator(myDefaultValidationSupport); + instanceModule.setBestPracticeWarningLevel(IResourceValidator.BestPracticeWarningLevel.Error); + val.registerValidatorModule(instanceModule); + result = val.validateWithResult(input); + all = logResultsAndReturnAll(result); + assertFalse(result.isSuccessful()); + assertEquals("All observations should have a subject", all.get(0).getMessage()); + } + private List logResultsAndReturnNonInformationalOnes(ValidationResult theOutput) { List retVal = new ArrayList();