From 229e0977d26a23f066efe43fcee69b98954ac1bd Mon Sep 17 00:00:00 2001 From: Heinz-Dieter Conradi Date: Wed, 28 Feb 2018 15:48:43 +0100 Subject: [PATCH] Add test for invalid local reference (DSTU3) Currently an invalid local reference causes an InternalErrorException caused by: FHIRException: Resource resolution services not provided. The validation should instead return normally and contain an error message. --- .../FhirInstanceValidatorDstu3Test.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java index 38bd6934ea6..95f2368eabc 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java @@ -17,12 +17,16 @@ import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport.CodeValidationResult; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent; +import org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus; import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; +import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent; +import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType; import org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionKind; import org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionComponent; import org.hl7.fhir.dstu3.utils.FHIRPathEngine; import org.hl7.fhir.instance.model.api.IBaseResource; + import org.junit.*; import org.junit.rules.TestRule; import org.junit.rules.TestWatcher; @@ -737,6 +741,25 @@ public class FhirInstanceValidatorDstu3Test { assertThat(nonInfo, empty()); } + /** + * An invalid local reference should not cause a ServiceException. + */ + @Test + public void testInvalidLocalReference() { + Questionnaire resource = new Questionnaire(); + resource.setStatus(PublicationStatus.ACTIVE); + + QuestionnaireItemComponent item = new QuestionnaireItemComponent(); + item.setLinkId("linkId-1"); + item.setType(QuestionnaireItemType.CHOICE); + item.setOptions(new Reference("#invalid-ref")); + resource.addItem(item); + + ValidationResult output = myVal.validateWithResult(resource); + List nonInfo = logResultsAndReturnNonInformationalOnes(output); + assertThat(nonInfo, hasSize(2)); + } + /** * See #370 */