|
|
|
@ -46,7 +46,7 @@ import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class SnapShotGenerationTestsX {
|
|
|
|
|
public class SnapShotGenerationXTests {
|
|
|
|
|
|
|
|
|
|
public enum TestFetchMode {
|
|
|
|
|
INPUT,
|
|
|
|
@ -171,19 +171,19 @@ public class SnapShotGenerationTestsX {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void load() throws FHIRFormatError, FileNotFoundException, IOException {
|
|
|
|
|
if (TestingUtilitiesX.findTestResource("rX", "snapshot-generation", id + "-input.json"))
|
|
|
|
|
source = (StructureDefinition) new JsonParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", id + "-input.json"));
|
|
|
|
|
if (UtilitiesXTests.findTestResource("rX", "snapshot-generation", id + "-input.json"))
|
|
|
|
|
source = (StructureDefinition) new JsonParser().parse(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", id + "-input.json"));
|
|
|
|
|
else
|
|
|
|
|
source = (StructureDefinition) new XmlParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", id + "-input.xml"));
|
|
|
|
|
source = (StructureDefinition) new XmlParser().parse(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", id + "-input.xml"));
|
|
|
|
|
if (!fail)
|
|
|
|
|
expected = (StructureDefinition) new XmlParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", id + "-expected.xml"));
|
|
|
|
|
expected = (StructureDefinition) new XmlParser().parse(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", id + "-expected.xml"));
|
|
|
|
|
if (!Utilities.noString(include))
|
|
|
|
|
included = (StructureDefinition) new XmlParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", include + ".xml"));
|
|
|
|
|
included = (StructureDefinition) new XmlParser().parse(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", include + ".xml"));
|
|
|
|
|
if (!Utilities.noString(register)) {
|
|
|
|
|
if (TestingUtilitiesX.findTestResource("rX", "snapshot-generation", register + ".xml")) {
|
|
|
|
|
included = (StructureDefinition) new XmlParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", register + ".xml"));
|
|
|
|
|
if (UtilitiesXTests.findTestResource("rX", "snapshot-generation", register + ".xml")) {
|
|
|
|
|
included = (StructureDefinition) new XmlParser().parse(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", register + ".xml"));
|
|
|
|
|
} else {
|
|
|
|
|
included = (StructureDefinition) new JsonParser().parse(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", register + ".json"));
|
|
|
|
|
included = (StructureDefinition) new JsonParser().parse(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", register + ".json"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -201,13 +201,13 @@ public class SnapShotGenerationTestsX {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isDatatype(String name) {
|
|
|
|
|
StructureDefinition sd = TestingUtilitiesX.context(version).fetchTypeDefinition(name);
|
|
|
|
|
StructureDefinition sd = UtilitiesXTests.context(version).fetchTypeDefinition(name);
|
|
|
|
|
return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE || sd.getKind() == StructureDefinitionKind.COMPLEXTYPE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isResource(String typeSimple) {
|
|
|
|
|
StructureDefinition sd = TestingUtilitiesX.context(version).fetchTypeDefinition(typeSimple);
|
|
|
|
|
StructureDefinition sd = UtilitiesXTests.context(version).fetchTypeDefinition(typeSimple);
|
|
|
|
|
return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.RESOURCE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -239,7 +239,7 @@ public class SnapShotGenerationTestsX {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getLinkForProfile(StructureDefinition profile, String url) {
|
|
|
|
|
StructureDefinition sd = TestingUtilitiesX.context(version).fetchResource(StructureDefinition.class, url);
|
|
|
|
|
StructureDefinition sd = UtilitiesXTests.context(version).fetchResource(StructureDefinition.class, url);
|
|
|
|
|
if (sd == null)
|
|
|
|
|
return url + "|" + url;
|
|
|
|
|
else
|
|
|
|
@ -265,15 +265,15 @@ public class SnapShotGenerationTestsX {
|
|
|
|
|
public Resource fetchFixture(String id) {
|
|
|
|
|
TestFetchMode mode = TestFetchMode.INPUT;
|
|
|
|
|
if (id.equals("patient"))
|
|
|
|
|
return TestingUtilitiesX.context(version).fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient");
|
|
|
|
|
return UtilitiesXTests.context(version).fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient");
|
|
|
|
|
if (id.equals("valueset"))
|
|
|
|
|
return TestingUtilitiesX.context(version).fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/ValueSet");
|
|
|
|
|
return UtilitiesXTests.context(version).fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/ValueSet");
|
|
|
|
|
if (id.equals("organization"))
|
|
|
|
|
return TestingUtilitiesX.context(version).fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Organization");
|
|
|
|
|
return UtilitiesXTests.context(version).fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Organization");
|
|
|
|
|
if (id.equals("operationoutcome"))
|
|
|
|
|
return TestingUtilitiesX.context(version).fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/OperationOutcome");
|
|
|
|
|
return UtilitiesXTests.context(version).fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/OperationOutcome");
|
|
|
|
|
if (id.equals("parameters"))
|
|
|
|
|
return TestingUtilitiesX.context(version).fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Parameters");
|
|
|
|
|
return UtilitiesXTests.context(version).fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Parameters");
|
|
|
|
|
|
|
|
|
|
if (id.contains("-")) {
|
|
|
|
|
String[] p = id.split("\\-");
|
|
|
|
@ -329,7 +329,7 @@ public class SnapShotGenerationTestsX {
|
|
|
|
|
@Override
|
|
|
|
|
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException {
|
|
|
|
|
if ("fixture".equals(functionName))
|
|
|
|
|
return new TypeDetails(CollectionStatus.SINGLETON, TestingUtilitiesX.context(version).getResourceNamesAsSet());
|
|
|
|
|
return new TypeDetails(CollectionStatus.SINGLETON, UtilitiesXTests.context(version).getResourceNamesAsSet());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -356,7 +356,7 @@ public class SnapShotGenerationTestsX {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException {
|
|
|
|
|
IResourceValidator val = TestingUtilitiesX.context(version).newValidator();
|
|
|
|
|
IResourceValidator val = UtilitiesXTests.context(version).newValidator();
|
|
|
|
|
List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>();
|
|
|
|
|
if (item instanceof Resource) {
|
|
|
|
|
val.validate(appContext, valerrors, (Resource) item, url);
|
|
|
|
@ -392,7 +392,7 @@ public class SnapShotGenerationTestsX {
|
|
|
|
|
public static Iterable<Object[]> data() throws ParserConfigurationException, IOException, FHIRFormatError, SAXException {
|
|
|
|
|
|
|
|
|
|
SnapShotGenerationTestsContext context = new SnapShotGenerationTestsContext();
|
|
|
|
|
Document tests = XMLUtil.parseToDom(TestingUtilitiesX.loadTestResource("rX", "snapshot-generation", "manifest.xml"));
|
|
|
|
|
Document tests = XMLUtil.parseToDom(UtilitiesXTests.loadTestResource("rX", "snapshot-generation", "manifest.xml"));
|
|
|
|
|
Element test = XMLUtil.getFirstChild(tests.getDocumentElement());
|
|
|
|
|
List<Object[]> objects = new ArrayList<Object[]>();
|
|
|
|
|
while (test != null && test.getNodeName().equals("test")) {
|
|
|
|
@ -416,7 +416,7 @@ public class SnapShotGenerationTestsX {
|
|
|
|
|
version = test.version;
|
|
|
|
|
this.context = context;
|
|
|
|
|
if (fp == null)
|
|
|
|
|
fp = new FHIRPathEngine(TestingUtilitiesX.context(version));
|
|
|
|
|
fp = new FHIRPathEngine(UtilitiesXTests.context(version));
|
|
|
|
|
fp.setHostServices(context);
|
|
|
|
|
messages = new ArrayList<ValidationMessage>();
|
|
|
|
|
|
|
|
|
@ -453,29 +453,29 @@ public class SnapShotGenerationTestsX {
|
|
|
|
|
private void testSort(TestDetails test) throws DefinitionException, FHIRException, IOException {
|
|
|
|
|
StructureDefinition base = getSD(test.getSource().getBaseDefinition());
|
|
|
|
|
test.setOutput(test.getSource().copy());
|
|
|
|
|
ProfileUtilities pu = new ProfileUtilities(TestingUtilitiesX.context(version), null, null);
|
|
|
|
|
ProfileUtilities pu = new ProfileUtilities(UtilitiesXTests.context(version), null, null);
|
|
|
|
|
pu.setIds(test.getSource(), false);
|
|
|
|
|
List<String> errors = new ArrayList<String>();
|
|
|
|
|
pu.sortDifferential(base, test.getOutput(), test.getOutput().getUrl(), errors, false);
|
|
|
|
|
if (!errors.isEmpty())
|
|
|
|
|
throw new FHIRException(errors.get(0));
|
|
|
|
|
IOUtils.copy(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(TestingUtilitiesX.tempFile("snapshot", test.getId() + "-expected.xml")));
|
|
|
|
|
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilitiesX.tempFile("snapshot", test.getId() + "-actual.xml")), test.getOutput());
|
|
|
|
|
IOUtils.copy(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(UtilitiesXTests.tempFile("snapshot", test.getId() + "-expected.xml")));
|
|
|
|
|
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(UtilitiesXTests.tempFile("snapshot", test.getId() + "-actual.xml")), test.getOutput());
|
|
|
|
|
Assertions.assertTrue(test.expected.equalsDeep(test.output), "Output does not match expected");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testGen(boolean fail, TestDetails test) throws Exception {
|
|
|
|
|
if (!Utilities.noString(test.register)) {
|
|
|
|
|
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
|
|
|
|
|
ProfileUtilities pu = new ProfileUtilities(TestingUtilitiesX.context(version), messages, null);
|
|
|
|
|
ProfileUtilities pu = new ProfileUtilities(UtilitiesXTests.context(version), messages, null);
|
|
|
|
|
pu.setNewSlicingProcessing(true);
|
|
|
|
|
pu.setIds(test.included, false);
|
|
|
|
|
StructureDefinition base = TestingUtilitiesX.context(version).fetchResource(StructureDefinition.class, test.included.getBaseDefinition());
|
|
|
|
|
StructureDefinition base = UtilitiesXTests.context(version).fetchResource(StructureDefinition.class, test.included.getBaseDefinition());
|
|
|
|
|
if (base != null) {
|
|
|
|
|
pu.generateSnapshot(base, test.included, test.included.getUrl(), "http://test.org/profile", test.included.getName());
|
|
|
|
|
}
|
|
|
|
|
if (!TestingUtilitiesX.context(version).hasResource(StructureDefinition.class, test.included.getUrl()))
|
|
|
|
|
TestingUtilitiesX.context(version).cacheResource(test.included);
|
|
|
|
|
if (!UtilitiesXTests.context(version).hasResource(StructureDefinition.class, test.included.getUrl()))
|
|
|
|
|
UtilitiesXTests.context(version).cacheResource(test.included);
|
|
|
|
|
int ec = 0;
|
|
|
|
|
for (ValidationMessage vm : messages) {
|
|
|
|
|
if (vm.getLevel() == IssueSeverity.ERROR) {
|
|
|
|
@ -491,7 +491,7 @@ public class SnapShotGenerationTestsX {
|
|
|
|
|
throw new Exception("URL mismatch on base: " + base.getUrl() + " wanting " + test.getSource().getBaseDefinition());
|
|
|
|
|
|
|
|
|
|
StructureDefinition output = test.getSource().copy();
|
|
|
|
|
ProfileUtilities pu = new ProfileUtilities(TestingUtilitiesX.context(version), messages, new TestPKP());
|
|
|
|
|
ProfileUtilities pu = new ProfileUtilities(UtilitiesXTests.context(version), messages, new TestPKP());
|
|
|
|
|
pu.setNewSlicingProcessing(test.isNewSliceProcessing());
|
|
|
|
|
pu.setThrowException(false);
|
|
|
|
|
pu.setDebug(test.isDebug());
|
|
|
|
@ -527,12 +527,12 @@ public class SnapShotGenerationTestsX {
|
|
|
|
|
}
|
|
|
|
|
if (!fail) {
|
|
|
|
|
test.output = output;
|
|
|
|
|
TestingUtilitiesX.context(version).cacheResource(output);
|
|
|
|
|
File dst = new File(TestingUtilitiesX.tempFile("snapshot", test.getId() + "-expected.xml"));
|
|
|
|
|
UtilitiesXTests.context(version).cacheResource(output);
|
|
|
|
|
File dst = new File(UtilitiesXTests.tempFile("snapshot", test.getId() + "-expected.xml"));
|
|
|
|
|
if (dst.exists())
|
|
|
|
|
dst.delete();
|
|
|
|
|
IOUtils.copy(TestingUtilitiesX.loadTestResourceStream("rX", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(dst));
|
|
|
|
|
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilitiesX.tempFile("snapshot", test.getId() + "-actual.xml")), output);
|
|
|
|
|
IOUtils.copy(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(dst));
|
|
|
|
|
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(UtilitiesXTests.tempFile("snapshot", test.getId() + "-actual.xml")), output);
|
|
|
|
|
StructureDefinition t1 = test.expected.copy();
|
|
|
|
|
t1.setText(null);
|
|
|
|
|
StructureDefinition t2 = test.output.copy();
|
|
|
|
@ -551,10 +551,10 @@ public class SnapShotGenerationTestsX {
|
|
|
|
|
private StructureDefinition getSD(String url) throws DefinitionException, FHIRException, IOException {
|
|
|
|
|
StructureDefinition sd = context.getByUrl(url);
|
|
|
|
|
if (sd == null)
|
|
|
|
|
sd = TestingUtilitiesX.context(version).fetchResource(StructureDefinition.class, url);
|
|
|
|
|
sd = UtilitiesXTests.context(version).fetchResource(StructureDefinition.class, url);
|
|
|
|
|
if (!sd.hasSnapshot()) {
|
|
|
|
|
StructureDefinition base = getSD(sd.getBaseDefinition());
|
|
|
|
|
ProfileUtilities pu = new ProfileUtilities(TestingUtilitiesX.context(version), messages, new TestPKP());
|
|
|
|
|
ProfileUtilities pu = new ProfileUtilities(UtilitiesXTests.context(version), messages, new TestPKP());
|
|
|
|
|
pu.setNewSlicingProcessing(true);
|
|
|
|
|
List<String> errors = new ArrayList<String>();
|
|
|
|
|
pu.sortDifferential(base, sd, url, errors, false);
|