Search in sources :

Example 1 with SetupActionAssertComponent

use of org.hl7.fhir.dstu3.model.TestScript.SetupActionAssertComponent 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 name, TestScriptTestComponent test, SnapShotGenerationTestsContext context) throws IOException, FHIRException {
    if (TestingUtilities.context == null)
        TestingUtilities.context = SimpleWorkerContext.fromPack(Utilities.path(TestingUtilities.home(), "publish", "definitions.xml.zip"));
    if (fp == null)
        fp = new FHIRPathEngine(TestingUtilities.context);
    fp.setHostServices(context);
    resolveFixtures(context);
    SetupActionOperationComponent op = test.getActionFirstRep().getOperation();
    StructureDefinition source = (StructureDefinition) context.fetchFixture(op.getSourceId());
    StructureDefinition base = getSD(source.getBaseDefinition(), context);
    StructureDefinition output = source.copy();
    ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context, null, null);
    pu.setIds(source, false);
    pu.generateSnapshot(base, output, source.getUrl(), source.getName());
    context.fixtures.put(op.getResponseId(), output);
    context.snapshots.put(output.getUrl(), output);
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(Utilities.path("[tmp]"), op.getResponseId() + ".xml")), output);
    // ok, now the asserts:
    for (int i = 1; i < test.getAction().size(); i++) {
        SetupActionAssertComponent a = test.getAction().get(i).getAssert();
        Assertions.assertTrue(fp.evaluateToBoolean(source, source, a.getExpression()), a.getLabel() + ": " + a.getDescription());
    }
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) FHIRPathEngine(org.hl7.fhir.dstu3.utils.FHIRPathEngine) ProfileUtilities(org.hl7.fhir.dstu3.conformance.ProfileUtilities) FileOutputStream(java.io.FileOutputStream) SetupActionOperationComponent(org.hl7.fhir.dstu3.model.TestScript.SetupActionOperationComponent) SetupActionAssertComponent(org.hl7.fhir.dstu3.model.TestScript.SetupActionAssertComponent) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

FileOutputStream (java.io.FileOutputStream)1 ProfileUtilities (org.hl7.fhir.dstu3.conformance.ProfileUtilities)1 XmlParser (org.hl7.fhir.dstu3.formats.XmlParser)1 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)1 SetupActionAssertComponent (org.hl7.fhir.dstu3.model.TestScript.SetupActionAssertComponent)1 SetupActionOperationComponent (org.hl7.fhir.dstu3.model.TestScript.SetupActionOperationComponent)1 FHIRPathEngine (org.hl7.fhir.dstu3.utils.FHIRPathEngine)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1