Search in sources :

Example 71 with ValidationMessage

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

the class ProfileUtilitiesTests method testSimple.

// /**
// * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
@Test
public void testSimple() throws FHIRException, FileNotFoundException, IOException, UcumException {
    StructureDefinition focus = new StructureDefinition();
    StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setBaseDefinition(base.getUrl());
    focus.setType("Patient");
    focus.setDerivation(TypeDerivationRule.CONSTRAINT);
    List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
    new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://hl7.org/fhir/R4", "Simple Test");
    boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
    for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
        ElementDefinition b = base.getSnapshot().getElement().get(i);
        ElementDefinition f = focus.getSnapshot().getElement().get(i);
        if (ok) {
            if (!f.hasBase())
                ok = false;
            else if (!b.getPath().equals(f.getPath()))
                ok = false;
            else {
                b.setBase(null);
                f.setBase(null);
                ok = Base.compareDeep(b, f, true);
            }
        }
    }
    if (!ok) {
        compareXml(base, focus);
        throw new FHIRException("Snap shot generation simple test failed");
    } else
        System.out.println("Snap shot generation simple test passed");
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) Test(org.junit.jupiter.api.Test)

Example 72 with ValidationMessage

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

the class ProfileUtilitiesTests method testSimple2.

// 
// /**
// * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base. for a different resource with recursion
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
@Test
public void testSimple2() throws EOperationOutcome, Exception {
    StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/ValueSet").copy();
    StructureDefinition focus = base.copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setSnapshot(null);
    focus.setDifferential(null);
    List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
    new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://hl7.org/fhir/R4", "Simple Test");
    boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
    for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
        if (ok) {
            ElementDefinition b = base.getSnapshot().getElement().get(i);
            ElementDefinition f = focus.getSnapshot().getElement().get(i);
            if (!f.hasBase() || !b.getPath().equals(f.getPath()))
                ok = false;
            else {
                f.setBase(null);
                b.setBase(null);
                ok = Base.compareDeep(b, f, true);
            }
        }
    }
    if (!ok) {
        compareXml(base, focus);
        System.out.println("Snap shot generation simple test failed");
        throw new FHIRException("Snap shot generation simple test failed");
    } else
        System.out.println("Snap shot generation simple test passed");
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) Test(org.junit.jupiter.api.Test)

Example 73 with ValidationMessage

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

the class SnapShotGenerationTests method test.

@SuppressWarnings("deprecation")
@ParameterizedTest(name = "{index}: file {0}")
@MethodSource("data")
public void test(String id, TestDetails test, SnapShotGenerationTestsContext context) throws Exception {
    fp.setHostServices(context);
    messages = new ArrayList<ValidationMessage>();
    if (test.isFail()) {
        try {
            if (test.isGen())
                testGen(test, context);
            else
                testSort(test, context);
            Assertions.assertTrue(false, "Should have failed");
        } catch (Throwable e) {
            Assertions.assertTrue(true, "all ok");
        }
    } else if (test.isGen())
        testGen(test, context);
    else
        testSort(test, context);
    for (Rule r : test.getRules()) {
        StructureDefinition sdn = new StructureDefinition();
        boolean ok = fp.evaluateToBoolean(sdn, sdn, sdn, r.expression);
        Assertions.assertTrue(ok, r.description);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) TypeDerivationRule(org.hl7.fhir.r4.model.StructureDefinition.TypeDerivationRule) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 74 with ValidationMessage

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

the class ResourceComparer method vm.

protected void vm(IssueSeverity level, String message, String path, List<ValidationMessage> genMessages, List<ValidationMessage> specMessages) {
    ValidationMessage vm = new ValidationMessage(Source.ProfileComparer, IssueType.INFORMATIONAL, path, message, level == IssueSeverity.NULL ? IssueSeverity.INFORMATION : level);
    genMessages.add(vm);
    if (specMessages != null) {
        specMessages.add(vm);
    }
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage)

Example 75 with ValidationMessage

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

the class SnapShotGenerationTests method test.

@SuppressWarnings("deprecation")
@ParameterizedTest(name = "{index}: file {0}")
@MethodSource("data")
public void test(String id, TestDetails test, SnapShotGenerationTestsContext context) throws Exception {
    fp.setHostServices(context);
    messages = new ArrayList<ValidationMessage>();
    if (test.noR4b) {
        Assert.assertTrue(true);
    } else {
        System.out.println("---- " + id + " -----------------------------------------");
        if (test.isFail()) {
            boolean failed = true;
            try {
                if (test.isGen())
                    testGen(true, test, context);
                else
                    testSort(test, context);
                failed = false;
            } catch (Throwable e) {
                System.out.println("Error running test: " + e.getMessage());
                if (!Utilities.noString(test.regex)) {
                    Assertions.assertTrue(e.getMessage().matches(test.regex), "correct error message");
                } else if ("Should have failed".equals(e.getMessage())) {
                    throw e;
                } else {
                }
            }
            Assertions.assertTrue(failed, "Should have failed");
        } else if (test.isGen())
            testGen(false, test, context);
        else
            testSort(test, context);
        for (Rule r : test.getRules()) {
            StructureDefinition sdn = new StructureDefinition();
            boolean ok = fp.evaluateToBoolean(sdn, sdn, sdn, r.expression);
            Assertions.assertTrue(ok, r.description);
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) TypeDerivationRule(org.hl7.fhir.r4b.model.StructureDefinition.TypeDerivationRule) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)170 ArrayList (java.util.ArrayList)114 FHIRException (org.hl7.fhir.exceptions.FHIRException)92 Element (org.hl7.fhir.r5.elementmodel.Element)60 IOException (java.io.IOException)46 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)44 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)38 NodeStack (org.hl7.fhir.validation.instance.utils.NodeStack)30 IndexedElement (org.hl7.fhir.validation.instance.utils.IndexedElement)28 NotImplementedException (org.apache.commons.lang3.NotImplementedException)21 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)20 ValueSet (org.hl7.fhir.r5.model.ValueSet)20 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)19 NamedElement (org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement)19 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)18 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)18 FileNotFoundException (java.io.FileNotFoundException)17 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)16 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)16 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)16