start working on using new IG infrastructure for Tx tests

This commit is contained in:
Grahame Grieve 2024-12-02 06:52:18 +03:00
parent 3538428d98
commit e59e752567
9 changed files with 107 additions and 36 deletions

View File

@ -628,9 +628,11 @@ public class Utilities {
public static String padRight(String src, char c, int len) {
StringBuilder s = new StringBuilder();
s.append(src);
for (int i = 0; i < len - src.length(); i++)
s.append(c);
if (src != null) {
s.append(src);
for (int i = 0; i < len - src.length(); i++)
s.append(c);
}
return s.toString();
}

View File

@ -6,6 +6,6 @@ public class CommonPackages {
public static final String VER_XVER = "0.1.0";
public static final String ID_PUBPACK = "hl7.fhir.pubpack";
public static final String VER_PUBPACK = "0.1.9";
public static final String VER_PUBPACK = "0.2.0";
}

View File

@ -178,8 +178,9 @@ public class HierarchicalTableGenerator {
return style;
}
public void setTag(String tag) {
public Piece setTag(String tag) {
this.tag = tag;
return this;
}
public Piece setText(String text) {

View File

@ -56,6 +56,7 @@ public class TxTester {
public String describe();
public Resource loadResource(String filename) throws IOException, FHIRFormatError, FileNotFoundException, FHIRException, DefinitionException;
public byte[] loadContent(String filename) throws FileNotFoundException, IOException;
public boolean hasContent(String filename) throws IOException;
}
private String server;
@ -172,7 +173,16 @@ public class TxTester {
}
private String loadVersion() throws JsonException, IOException {
return processHistoryMarkdown(loader.loadContent("history.md"));
if (loader.hasContent("history.json")) {
return readHistory(loader.loadContent("history.json"));
} else {
return processHistoryMarkdown(loader.loadContent("history.md"));
}
}
private String readHistory(byte[] content) throws JsonException, IOException {
JsonObject json = JsonParser.parseObject(content);
return json.getJsonObjects("versions").get(0).asString("version");
}
public static String processHistoryMarkdown(byte[] content) throws IOException {
@ -650,6 +660,11 @@ public class TxTester {
public byte[] loadContent(String filename) throws FileNotFoundException, IOException {
return TextFile.fileToBytes(Utilities.path(folder, filename));
}
@Override
public boolean hasContent(String filename) throws IOException {
return new File(Utilities.path(folder, filename)).exists();
}
}
}

View File

@ -101,7 +101,7 @@ public class SnapShotGenerationXTests {
private List<Rule> rules = new ArrayList<>();
private StructureDefinition source;
private StructureDefinition included;
private List<StructureDefinition> included = new ArrayList<StructureDefinition>();
private StructureDefinition expected;
private StructureDefinition output;
public boolean outputIsJson;
@ -146,7 +146,7 @@ public class SnapShotGenerationXTests {
return fail;
}
public StructureDefinition getIncluded() {
public List<StructureDefinition> getIncluded() {
return included;
}
@ -191,12 +191,14 @@ public class SnapShotGenerationXTests {
expected = (StructureDefinition) XVersionLoader.loadXml(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", id + "-output.xml"));
}
if (!Utilities.noString(include))
included = (StructureDefinition) XVersionLoader.loadXml(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", include + ".xml"));
included.add((StructureDefinition) XVersionLoader.loadXml(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", include + ".xml")));
if (!Utilities.noString(register)) {
if (TestingUtilities.findTestResource("rX", "snapshot-generation", register + ".xml")) {
included = (StructureDefinition) XVersionLoader.loadXml(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", register + ".xml"));
} else {
included = (StructureDefinition) XVersionLoader.loadJson(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", register + ".json"));
for (String r : register.split("\\,")) {
if (TestingUtilities.findTestResource("rX", "snapshot-generation", r + ".xml")) {
included.add((StructureDefinition) XVersionLoader.loadXml(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", r + ".xml")));
} else {
included.add((StructureDefinition) XVersionLoader.loadJson(version, TestingUtilities.loadTestResourceStream("rX", "snapshot-generation", r + ".json")));
}
}
}
}
@ -321,7 +323,7 @@ public class SnapShotGenerationXTests {
else
return td.getOutput();
case INCLUDE:
return td.getIncluded();
return td.getIncluded().get(0);
default:
throw new FHIRException("Not done yet");
}
@ -401,8 +403,11 @@ public class SnapShotGenerationXTests {
for (TestDetails t : tests) {
if (t.expected != null && url.equals(t.expected.getUrl()))
return t.expected;
if (t.included != null && url.equals(t.included.getUrl()))
return t.included;
for (StructureDefinition sd : t.included) {
if (url.equals(sd.getUrl())) {
return sd;
}
}
}
return null;
}
@ -499,23 +504,26 @@ public class SnapShotGenerationXTests {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
ProfileUtilities pu = new ProfileUtilities(UtilitiesXTests.context(version), messages, null);
pu.setNewSlicingProcessing(true);
pu.setIds(test.included, false);
pu.setAllowUnknownProfile(AllowUnknownProfile.ALL_TYPES);
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 (!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) {
System.out.println(vm.summary());
ec++;
for (StructureDefinition sd : test.included) {
pu.setIds(sd, false);
pu.setAllowUnknownProfile(AllowUnknownProfile.ALL_TYPES);
StructureDefinition base = UtilitiesXTests.context(version).fetchResource(StructureDefinition.class, sd.getBaseDefinition());
if (base != null) {
pu.generateSnapshot(base, sd, sd.getUrl(), "http://test.org/profile", sd.getName());
}
if (!UtilitiesXTests.context(version).hasResource(StructureDefinition.class, sd.getUrl()))
UtilitiesXTests.context(version).cacheResource(sd);
int ec = 0;
for (ValidationMessage vm : messages) {
if (vm.getLevel() == IssueSeverity.ERROR) {
System.out.println(vm.summary());
ec++;
}
}
if (ec > 0) {
throw new FHIRException("register gen failed: " + messages.toString());
}
}
if (ec > 0)
throw new FHIRException("register gen failed: " + messages.toString());
}
StructureDefinition base = getSD(test.getSource().getBaseDefinition());
if (!base.getUrl().equals(test.getSource().getBaseDefinition()))
@ -560,14 +568,19 @@ public class SnapShotGenerationXTests {
if (!fail) {
test.output = output;
UtilitiesXTests.context(version).cacheResource(output);
File dst = ManagedFileAccess.file(UtilitiesXTests.tempFile("snapshot", test.getId() + "-output.xml"));
File dst = ManagedFileAccess.file(UtilitiesXTests.tempFile("snapshot", test.getId() + "-output" + (test.outputIsJson ? ".json" : ".xml")));
if (dst.exists())
dst.delete();
if (test.outputIsJson) {
XVersionLoader.saveJson(version, output, ManagedFileAccess.outStream(UtilitiesXTests.tempFile("snapshot", test.getId() + "-output.json")));
XVersionLoader.saveJson(version, output, ManagedFileAccess.outStream(dst.getAbsolutePath()));
} else {
XVersionLoader.saveXml(version, output, ManagedFileAccess.outStream(UtilitiesXTests.tempFile("snapshot", test.getId() + "-output.json")));
}
XVersionLoader.saveXml(version, output, ManagedFileAccess.outStream(dst.getAbsolutePath()));
}
if (test.outputIsJson) {
XVersionLoader.saveJson(version, test.expected, ManagedFileAccess.outStream(UtilitiesXTests.tempFile("snapshot", test.getId() + "-expected" + (test.outputIsJson ? ".json" : ".xml"))));
} else {
XVersionLoader.saveXml(version, test.expected, ManagedFileAccess.outStream(UtilitiesXTests.tempFile("snapshot", test.getId() + "-expected" + (test.outputIsJson ? ".json" : ".xml"))));
}
StructureDefinition t1 = test.expected.copy();
t1.setText(null);
StructureDefinition t2 = test.output.copy();
@ -583,7 +596,6 @@ public class SnapShotGenerationXTests {
return path;
}
private StructureDefinition getSD(String url) throws DefinitionException, FHIRException, IOException {
StructureDefinition sd = context.getByUrl(url);
if (sd == null)

View File

@ -147,4 +147,9 @@ public class ExternalTerminologyServiceTests implements ITxTesterLoader {
public byte[] loadContent(String filename) throws FileNotFoundException, IOException {
return TestingUtilities.loadTestResourceBytes("tx", filename);
}
@Override
public boolean hasContent(String filename) throws IOException {
return TestingUtilities.findTestResource("tx", filename);
}
}

View File

@ -188,4 +188,11 @@ public class LocalTerminologyServiceTests implements ITxTesterLoader {
public byte[] loadContent(String filename) throws FileNotFoundException, IOException {
return TestingUtilities.loadTestResourceBytes("tx", filename);
}
@Override
public boolean hasContent(String filename) throws IOException {
return TestingUtilities.findTestResource("tx", filename);
}
}

View File

@ -174,4 +174,9 @@ public class OntoserverTests implements ITxTesterLoader {
public byte[] loadContent(String filename) throws FileNotFoundException, IOException {
return TestingUtilities.loadTestResourceBytes("tx", filename);
}
@Override
public boolean hasContent(String filename) throws IOException {
return TestingUtilities.findTestResource("tx", filename);
}
}

View File

@ -0,0 +1,24 @@
-------------------------------------------------------------------------------------
{"code" : {
"system" : "http://fhir.de/CodeSystem/dkgev/Fachabteilungsschluessel-erweitert",
"code" : "3600"
}, "valueSet" :null, "langs":"en-US", "useServer":"true", "useClient":"false", "guessSystem":"false", "activeOnly":"false", "membershipOnly":"false", "displayWarningMode":"false", "versionFlexible":"false", "profile": {
"resourceType" : "Parameters",
"parameter" : [{
"name" : "profile-url",
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"display" : "Intensivmedizin",
"code" : "3600",
"system" : "http://fhir.de/CodeSystem/dkgev/Fachabteilungsschluessel-erweitert",
"version" : "1.5.0",
"server" : "http://tx-dev.fhir.org/r5",
"unknown-systems" : "",
"issues" : {
"resourceType" : "OperationOutcome"
}
}
-------------------------------------------------------------------------------------