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());
}
}
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();
}
Aggregations