Add test for UCUM with no terminology server

This commit is contained in:
Grahame Grieve 2023-07-05 07:23:10 +10:00
parent 4a85513acb
commit f77392199d
3 changed files with 48 additions and 7 deletions

View File

@ -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);

View File

@ -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<String> 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()) {

View File

@ -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;
}