Search in sources :

Example 1 with TestScriptTestComponent

use of org.hl7.fhir.dstu3.model.TestScript.TestScriptTestComponent 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)

Example 2 with TestScriptTestComponent

use of org.hl7.fhir.dstu3.model.TestScript.TestScriptTestComponent in project org.hl7.fhir.core by hapifhir.

the class SnapShotGenerationTests method data.

public static Stream<Arguments> data() throws IOException, FHIRFormatError {
    SnapShotGenerationTestsContext context = new SnapShotGenerationTestsContext();
    String contents = readFileFromClasspathAsString("snapshot-generation-tests.xml");
    context.tests = (TestScript) new XmlParser().parse(contents);
    context.checkTestsDetails();
    List<Arguments> objects = new ArrayList<>();
    for (TestScriptTestComponent e : context.tests.getTest()) {
        objects.add(Arguments.of(e.getName(), e, context));
    }
    return objects.stream();
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) TestScriptTestComponent(org.hl7.fhir.dstu3.model.TestScript.TestScriptTestComponent) Arguments(org.junit.jupiter.params.provider.Arguments) ArrayList(java.util.ArrayList)

Aggregations

XmlParser (org.hl7.fhir.dstu3.formats.XmlParser)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 ProfileUtilities (org.hl7.fhir.dstu3.conformance.ProfileUtilities)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 TestScriptTestComponent (org.hl7.fhir.dstu3.model.TestScript.TestScriptTestComponent)1 FHIRPathEngine (org.hl7.fhir.dstu3.utils.FHIRPathEngine)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 Arguments (org.junit.jupiter.params.provider.Arguments)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1