Search in sources :

Example 6 with ValidationEngine

use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.

the class ValidationEngineTests method test140.

@Test
public void test140() throws Exception {
    if (inbuild) {
        Assertions.assertTrue(true);
        return;
    }
    if (!TestUtilities.silent)
        System.out.println("Test140: Validate patient-example.xml in v1.4.0 version");
    ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", DEF_TX, FhirPublication.DSTU2016May, "1.4.0");
    CacheVerificationLogger logger = new CacheVerificationLogger();
    ve.getContext().getTxClient().setLogger(logger);
    OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient140.xml"), null);
    if (!TestUtilities.silent)
        for (OperationOutcomeIssueComponent iss : op.getIssue()) {
            System.out.println("    " + iss.getDetails().getText());
        }
    int e = errors(op);
    int w = warnings(op);
    int h = hints(op);
    Assertions.assertEquals(1, e);
    Assertions.assertEquals(0, 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");
}
Also used : OperationOutcomeIssueComponent(org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent) CacheVerificationLogger(org.hl7.fhir.utilities.tests.CacheVerificationLogger) OperationOutcome(org.hl7.fhir.r5.model.OperationOutcome) ValidationEngine(org.hl7.fhir.validation.ValidationEngine) Test(org.junit.jupiter.api.Test)

Example 7 with ValidationEngine

use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.

the class TestUtilities method getValidationEngine.

public static ValidationEngine getValidationEngine(java.lang.String src, java.lang.String txServer, String txLog, FhirPublication version, boolean canRunWithoutTerminologyServer, java.lang.String vString) throws Exception {
    final ValidationEngine validationEngine = new ValidationEngine.ValidationEngineBuilder().withCanRunWithoutTerminologyServer(canRunWithoutTerminologyServer).withVersion(vString).withUserAgent(TestConstants.USER_AGENT).withTerminologyCachePath(Paths.get(TestConstants.TX_CACHE, vString).toString()).withTxServer(txServer, txLog, version).fromSource(src);
    TerminologyCache.setCacheErrors(true);
    return validationEngine;
}
Also used : ValidationEngine(org.hl7.fhir.validation.ValidationEngine)

Example 8 with ValidationEngine

use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.

the class TestUtilities method getValidationEngine.

public static ValidationEngine getValidationEngine(java.lang.String src, java.lang.String txServer, FhirPublication version, java.lang.String vString) throws Exception {
    final ValidationEngine validationEngine = new ValidationEngine.ValidationEngineBuilder().withVersion(vString).withUserAgent(TestConstants.USER_AGENT).withTerminologyCachePath(Paths.get(TestConstants.TX_CACHE, vString).toString()).withTxServer(txServer, TestConstants.TX_CACHE_LOG, version).fromSource(src);
    TerminologyCache.setCacheErrors(true);
    return validationEngine;
}
Also used : ValidationEngine(org.hl7.fhir.validation.ValidationEngine)

Example 9 with ValidationEngine

use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.

the class SessionCacheTest method expiredSession.

@Test
@DisplayName("test session expiration works")
void expiredSession() throws IOException, InterruptedException {
    final long EXPIRE_TIME = 5L;
    SessionCache cache = new SessionCache(EXPIRE_TIME, TimeUnit.SECONDS);
    ValidationEngine testEngine = new ValidationEngine.ValidationEngineBuilder().fromNothing();
    String sessionId = cache.cacheSession(testEngine);
    TimeUnit.SECONDS.sleep(EXPIRE_TIME + 1L);
    Assertions.assertNull(cache.fetchSessionValidatorEngine(sessionId));
}
Also used : ValidationEngine(org.hl7.fhir.validation.ValidationEngine) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 10 with ValidationEngine

use of org.hl7.fhir.validation.ValidationEngine in project org.hl7.fhir.core by hapifhir.

the class SessionCacheTest method cachedSession.

@Test
@DisplayName("test session caching works")
void cachedSession() throws IOException {
    final long EXPIRE_TIME = 5L;
    SessionCache cache = new SessionCache(EXPIRE_TIME, TimeUnit.SECONDS);
    ValidationEngine testEngine = new ValidationEngine.ValidationEngineBuilder().fromNothing();
    String sessionId = cache.cacheSession(testEngine);
    Assertions.assertEquals(testEngine, cache.fetchSessionValidatorEngine(sessionId));
}
Also used : ValidationEngine(org.hl7.fhir.validation.ValidationEngine) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

ValidationEngine (org.hl7.fhir.validation.ValidationEngine)18 Test (org.junit.jupiter.api.Test)10 OperationOutcome (org.hl7.fhir.r5.model.OperationOutcome)7 CacheVerificationLogger (org.hl7.fhir.utilities.tests.CacheVerificationLogger)7 OperationOutcomeIssueComponent (org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent)6 IgLoader (org.hl7.fhir.validation.IgLoader)4 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 DisplayName (org.junit.jupiter.api.DisplayName)3 IOException (java.io.IOException)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)2 TimeTracker (org.hl7.fhir.utilities.TimeTracker)2 Test (org.junit.Test)2 File (java.io.File)1 PrintStream (java.io.PrintStream)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 ComparisonRenderer (org.hl7.fhir.r5.comparison.ComparisonRenderer)1 ComparisonSession (org.hl7.fhir.r5.comparison.ComparisonSession)1 SystemOutLoggingService (org.hl7.fhir.r5.context.SystemOutLoggingService)1