diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java index 1ce754b47..338f36537 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java @@ -356,6 +356,10 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP return new ValidationEngineBuilder(terminologyCachePath, userAgent, version, txServer, txLog, txVersion, timeTracker, canRunWithoutTerminologyServer, loggingService, THO); } + public ValidationEngineBuilder withNoTerminologyServer() { + return new ValidationEngineBuilder(terminologyCachePath, userAgent, version, null, null, txVersion, timeTracker, true, loggingService, THO); + } + public ValidationEngine fromNothing() throws IOException { ValidationEngine engine = new ValidationEngine(); SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder().withLoggingService(loggingService); diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationEngineTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationEngineTests.java index dc1f445ab..a1c111269 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationEngineTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationEngineTests.java @@ -251,6 +251,34 @@ public class ValidationEngineTests { System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages"); } + + @Test + public void test401USCore() throws Exception { + if (!TestUtilities.silent) + System.out.println("Test401USCore: Validate observation401_ucum.json against US-Core with no terminology server"); + ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", "n/a", FhirPublication.R4, "4.0.1"); + CacheVerificationLogger logger = new CacheVerificationLogger(); + IgLoader igLoader = new IgLoader(ve.getPcm(), ve.getContext(), ve.getVersion(), true); + if (!TestUtilities.silent) + System.out.println(" .. load USCore"); + igLoader.loadIg(ve.getIgs(), ve.getBinaries(), "hl7.fhir.us.core#3.1.1", false); + List profiles = new ArrayList<>(); + OperationOutcome op = ve.validate(FhirFormat.JSON, TestingUtilities.loadTestResourceStream("validator", "observation401_ucum.json"), profiles); + if (!TestUtilities.silent) + for (OperationOutcomeIssueComponent issue : op.getIssue()) + System.out.println(" - " + issue.getDetails().getText()); + int e = errors(op); + int w = warnings(op); + int h = hints(op); + Assertions.assertEquals(0, e); + Assertions.assertEquals(2, w); + Assertions.assertEquals(0, h); + assertTrue(logger.verifyHasNoRequests(), "Unexpected request to TX server"); + if (!TestUtilities.silent) + System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages"); + } + + private int errors(OperationOutcome op) { int i = 0; for (OperationOutcomeIssueComponent vm : op.getIssue()) { diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/utilities/TestUtilities.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/utilities/TestUtilities.java index 69104d5db..0463188cb 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/utilities/TestUtilities.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/utilities/TestUtilities.java @@ -46,13 +46,22 @@ public class TestUtilities { } public static ValidationEngine getValidationEngine(java.lang.String src, java.lang.String txServer, FhirPublication version, java.lang.String vString) throws Exception { TestingUtilities.injectCorePackageLoader(); - final ValidationEngine validationEngine = new ValidationEngine.ValidationEngineBuilder() - .withVersion(vString) - .withUserAgent(TestConstants.USER_AGENT) - .withTerminologyCachePath(getTerminologyCacheDirectory(vString)) - .withTxServer(txServer, TestConstants.TX_CACHE_LOG, version) - .fromSource(src); - TerminologyCache.setCacheErrors(true); + ValidationEngine validationEngine = null; + if ("n/a".equals(txServer)) { + validationEngine = new ValidationEngine.ValidationEngineBuilder() + .withVersion(vString) + .withUserAgent(TestConstants.USER_AGENT) + .withNoTerminologyServer() + .fromSource(src); + } else { + validationEngine = new ValidationEngine.ValidationEngineBuilder() + .withVersion(vString) + .withUserAgent(TestConstants.USER_AGENT) + .withTerminologyCachePath(getTerminologyCacheDirectory(vString)) + .withTxServer(txServer, TestConstants.TX_CACHE_LOG, version) + .fromSource(src); + TerminologyCache.setCacheErrors(true); + } return validationEngine; }