Search in sources :

Example 21 with ValidationEngine

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

the class ValidationEngineTests method testCurrentJson.

@Test
public void testCurrentJson() throws Exception {
    if (!TestUtilities.silent)
        System.out.println("TestCurrentJson: Validate patient-example.json in Current version");
    ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, FhirPublication.R4, "4.0.1");
    CacheVerificationLogger logger = new CacheVerificationLogger();
    ve.getContext().getTxClient().setLogger(logger);
    OperationOutcome op = ve.validate(FhirFormat.JSON, TestingUtilities.loadTestResourceStream("validator", "patient-example.json"), null);
    int e = errors(op);
    int w = warnings(op);
    int h = hints(op);
    Assertions.assertEquals(0, e);
    Assertions.assertEquals(0, w);
    Assertions.assertEquals(1, 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 : 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 22 with ValidationEngine

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

the class ValidationEngineTests method test301USCore.

@Test
public void test301USCore() throws Exception {
    if (!TestUtilities.silent)
        System.out.println("Test301USCore: Validate patient300.xml against US-Core");
    ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", DEF_TX, FhirPublication.STU3, "3.0.2");
    CacheVerificationLogger logger = new CacheVerificationLogger();
    ve.getContext().getTxClient().setLogger(logger);
    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#1.0.1", false);
    List<String> profiles = new ArrayList<>();
    profiles.add("http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient");
    OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient301.xml"), 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(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 : IgLoader(org.hl7.fhir.validation.IgLoader) OperationOutcomeIssueComponent(org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent) CacheVerificationLogger(org.hl7.fhir.utilities.tests.CacheVerificationLogger) OperationOutcome(org.hl7.fhir.r5.model.OperationOutcome) ArrayList(java.util.ArrayList) ValidationEngine(org.hl7.fhir.validation.ValidationEngine) Test(org.junit.jupiter.api.Test)

Example 23 with ValidationEngine

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

the class ValidationEngineTests method test301.

@Test
public void test301() throws Exception {
    if (!TestUtilities.silent)
        System.out.println("Test301: Validate observation301.xml against Core");
    ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", DEF_TX, FhirPublication.STU3, "3.0.2");
    CacheVerificationLogger logger = new CacheVerificationLogger();
    ve.getContext().getTxClient().setLogger(logger);
    if (!TestUtilities.silent)
        System.out.println("  .. load USCore");
    OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "observation301.xml"), null);
    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);
    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 24 with ValidationEngine

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

the class ValidationEngineTests method testObs102.

@Test
public void testObs102() throws Exception {
    if (inbuild) {
        Assertions.assertTrue(true);
        return;
    }
    if (!TestUtilities.silent)
        System.out.println("TestObs102: Validate patient-example.xml in v1.0.2 version");
    ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", DEF_TX, FhirPublication.DSTU2, "1.0.2");
    ve.setNoInvariantChecks(true);
    CacheVerificationLogger logger = new CacheVerificationLogger();
    ve.getContext().getTxClient().setLogger(logger);
    OperationOutcome op = ve.validate(FhirFormat.JSON, TestingUtilities.loadTestResourceStream("validator", "observation102.json"), 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(1, 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 25 with ValidationEngine

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

the class ValidationEngineTests method testCurrentXml.

@Test
public void testCurrentXml() throws Exception {
    if (!TestUtilities.silent)
        System.out.println("TestCurrentXml: Validate patient-example.xml in Current version");
    ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, FhirPublication.R4, "4.0.1");
    CacheVerificationLogger logger = new CacheVerificationLogger();
    ve.getContext().getTxClient().setLogger(logger);
    OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient-example.xml"), null);
    int e = errors(op);
    int w = warnings(op);
    int h = hints(op);
    if (!TestUtilities.silent) {
        System.out.println("  .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
        for (OperationOutcomeIssueComponent iss : op.getIssue()) {
            System.out.println("    " + iss.getDetails().getText());
        }
    }
    Assertions.assertEquals(0, e);
    Assertions.assertEquals(0, w);
    Assertions.assertEquals(1, h);
    assertTrue(logger.verifyHasNoRequests(), "Unexpected request to TX server");
}
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)

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