Code cleanup + Fix merge

This commit is contained in:
dotasek 2022-01-04 13:43:01 -05:00
parent 7ee5d0c5e4
commit 9fb60f4fed
1 changed files with 33 additions and 33 deletions

View File

@ -42,6 +42,7 @@ import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.TypeDetails;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.validation.IResourceValidator;
@ -86,7 +87,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
@Parameters(name = "{index}: id {0}")
public static Iterable<Object[]> data() throws IOException {
String contents = org.hl7.fhir.r5.test.utils.TestingUtilities.loadTestResource("validator", "manifest.json");
String contents = TestingUtilities.loadTestResource("validator", "manifest.json");
Map<String, JsonObject> examples = new HashMap<String, JsonObject>();
manifest = (JsonObject) new com.google.gson.JsonParser().parse(contents);
@ -101,7 +102,6 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
List<Object[]> objects = new ArrayList<Object[]>(examples.size());
for (String id : names) {
//if ("dr-eh".equals(id))
objects.add(new Object[]{id, examples.get(id)});
}
return objects;
@ -121,13 +121,11 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
this.content = content;
}
@SuppressWarnings("deprecation")
@Test
public void test() throws Exception {
long setup = System.nanoTime();
this.content = content;
this.name = name;
System.out.println("---- " + name + " ----------------------------------------------------------------");
System.out.println("** Core: ");
@ -145,28 +143,30 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
if (!ve.containsKey(version)) {
if (version.startsWith("5.0"))
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r5.core#4.5.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R5, true, "4.5.0", "fhir/test-cases"));
else if (version.startsWith("3.0"))
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.STU3, true, "3.0.2", "fhir/test-cases"));
else if (version.startsWith("4.3"))
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r4b.core#4.3.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R4B, true, "4.3.0", "fhir/test-cases"));
else if (version.startsWith("4.0"))
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R4, true, "4.0.1", "fhir/test-cases"));
else if (version.startsWith("1.0"))
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2, true, "1.0.2", "fhir/test-cases"));
else if (version.startsWith("3.0"))
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.STU3, true, "3.0.2", "fhir/test-cases"));
else if (version.startsWith("1.4"))
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2016May, true, "1.4.0", "fhir/test-cases"));
else if (version.startsWith("1.0"))
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2, true, "1.0.2", "fhir/test-cases"));
else
throw new Exception("unknown version " + version);
}
vCurr = ve.get(version);
igLoader = new IgLoader(vCurr.getPcm(), vCurr.getContext(), vCurr.getVersion(), true);
if (org.hl7.fhir.r5.test.utils.TestingUtilities.fcontexts == null) {
org.hl7.fhir.r5.test.utils.TestingUtilities.fcontexts = new HashMap<>();
if (TestingUtilities.fcontexts == null) {
TestingUtilities.fcontexts = new HashMap<>();
}
org.hl7.fhir.r5.test.utils.TestingUtilities.fcontexts.put(version, vCurr.getContext());
TestingUtilities.fcontexts.put(version, vCurr.getContext());
if (content.has("use-test") && !content.get("use-test").getAsBoolean())
return;
byte[] testCaseContent = org.hl7.fhir.r5.test.utils.TestingUtilities.loadTestResource("validator", JSONUtil.str(content, "file")).getBytes(StandardCharsets.UTF_8);
byte[] testCaseContent = TestingUtilities.loadTestResource("validator", JSONUtil.str(content, "file")).getBytes(StandardCharsets.UTF_8);
// load and process content
FhirFormat fmt = determineFormat(content, testCaseContent);
@ -201,7 +201,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
if (content.has("packages")) {
for (JsonElement e : content.getAsJsonArray("packages")) {
String n = e.getAsString();
InputStream cnt = n.endsWith(".tgz") ? org.hl7.fhir.r5.test.utils.TestingUtilities.loadTestResourceStream("validator", n) : null;
InputStream cnt = n.endsWith(".tgz") ? TestingUtilities.loadTestResourceStream("validator", n) : null;
if (cnt != null) {
igLoader.loadPackage(NpmPackage.fromPackage(cnt));
} else {
@ -215,7 +215,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
if (content.has("supporting")) {
for (JsonElement e : content.getAsJsonArray("supporting")) {
String filename = e.getAsString();
String contents = org.hl7.fhir.r5.test.utils.TestingUtilities.loadTestResource("validator", filename);
String contents = TestingUtilities.loadTestResource("validator", filename);
CanonicalResource mr = (CanonicalResource) loadResource(filename, contents);
val.getContext().cacheResource(mr);
if (mr instanceof ImplementationGuide) {
@ -230,7 +230,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
if (content.has("profiles")) {
for (JsonElement je : content.getAsJsonArray("profiles")) {
String filename = je.getAsString();
String contents = org.hl7.fhir.r5.test.utils.TestingUtilities.loadTestResource("validator", filename);
String contents = TestingUtilities.loadTestResource("validator", filename);
StructureDefinition sd = loadProfile(filename, contents, messages);
val.getContext().cacheResource(sd);
}
@ -274,7 +274,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
if (profile.has("supporting")) {
for (JsonElement e : profile.getAsJsonArray("supporting")) {
String filename = e.getAsString();
String contents = org.hl7.fhir.r5.test.utils.TestingUtilities.loadTestResource("validator", filename);
String contents = TestingUtilities.loadTestResource("validator", filename);
CanonicalResource mr = (CanonicalResource) loadResource(filename, contents);
val.getContext().cacheResource(mr);
if (mr instanceof ImplementationGuide) {
@ -287,7 +287,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
if (Utilities.isAbsoluteUrl(filename)) {
sd = val.getContext().fetchResource(StructureDefinition.class, filename);
} else {
String contents = org.hl7.fhir.r5.test.utils.TestingUtilities.loadTestResource("validator", filename);
String contents = TestingUtilities.loadTestResource("validator", filename);
System.out.println("Name: " + name + " - profile : " + profile.get("source").getAsString());
version = content.has("version") ? content.get("version").getAsString() : Constants.VERSION;
sd = loadProfile(filename, contents, messages);
@ -306,7 +306,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
if (logical.has("supporting")) {
for (JsonElement e : logical.getAsJsonArray("supporting")) {
String filename = e.getAsString();
String contents = org.hl7.fhir.r5.test.utils.TestingUtilities.loadTestResource("validator", filename);
String contents = TestingUtilities.loadTestResource("validator", filename);
CanonicalResource mr = (CanonicalResource) loadResource(filename, contents);
if (mr instanceof StructureDefinition) {
val.getContext().generateSnapshot((StructureDefinition) mr, true);
@ -345,9 +345,9 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
public StructureDefinition loadProfile(String filename, String contents, List<ValidationMessage> messages) throws IOException, FHIRFormatError, FileNotFoundException, FHIRException, DefinitionException {
StructureDefinition sd = (StructureDefinition) loadResource(filename, contents);
ProfileUtilities pu = new ProfileUtilities(org.hl7.fhir.r5.test.utils.TestingUtilities.context(version), messages, null);
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(version), messages, null);
if (!sd.hasSnapshot()) {
StructureDefinition base = org.hl7.fhir.r5.test.utils.TestingUtilities.context(version).fetchResource(StructureDefinition.class, sd.getBaseDefinition());
StructureDefinition base = TestingUtilities.context(version).fetchResource(StructureDefinition.class, sd.getBaseDefinition());
pu.generateSnapshot(base, sd, sd.getUrl(), null, sd.getTitle());
// (debugging) new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", sd.getId()+".xml")), sd);
}
@ -355,7 +355,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
if (r instanceof StructureDefinition) {
StructureDefinition childSd = (StructureDefinition) r;
if (!childSd.hasSnapshot()) {
StructureDefinition base = org.hl7.fhir.r5.test.utils.TestingUtilities.context(version).fetchResource(StructureDefinition.class, childSd.getBaseDefinition());
StructureDefinition base = TestingUtilities.context(version).fetchResource(StructureDefinition.class, childSd.getBaseDefinition());
pu.generateSnapshot(base, childSd, childSd.getUrl(), null, childSd.getTitle());
}
}
@ -422,7 +422,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
}
}
}
if (!org.hl7.fhir.r5.test.utils.TestingUtilities.context(version).isNoTerminologyServer() || !focus.has("tx-dependent")) {
if (!TestingUtilities.context(version).isNoTerminologyServer() || !focus.has("tx-dependent")) {
Assert.assertEquals("Test " + name + (profile == null ? "" : " profile: "+ profile) + ": Expected " + Integer.toString(java.get("errorCount").getAsInt()) + " errors, but found " + Integer.toString(ec) + ".", java.get("errorCount").getAsInt(), ec);
if (java.has("warningCount")) {
Assert.assertEquals( "Test " + name + (profile == null ? "" : " profile: "+ profile) + ": Expected " + Integer.toString(java.get("warningCount").getAsInt()) + " warnings, but found " + Integer.toString(wc) + ".", java.get("warningCount").getAsInt(), wc);
@ -496,18 +496,18 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
public Element fetch(IResourceValidator validator, Object appContext, String url) throws FHIRFormatError, DefinitionException, IOException, FHIRException {
Element res = null;
if (url.equals("Patient/test")) {
res = new ObjectConverter(org.hl7.fhir.r5.test.utils.TestingUtilities.context(version)).convert(new Patient());
} else if (org.hl7.fhir.r5.test.utils.TestingUtilities.findTestResource("validator", url.replace("/", "-").toLowerCase() + ".json")) {
res = Manager.makeParser(org.hl7.fhir.r5.test.utils.TestingUtilities.context(version), FhirFormat.JSON).parseSingle(org.hl7.fhir.r5.test.utils.TestingUtilities.loadTestResourceStream("validator", url.replace("/", "-").toLowerCase() + ".json"));
} else if (org.hl7.fhir.r5.test.utils.TestingUtilities.findTestResource("validator", url.replace("/", "-").toLowerCase() + ".xml")) {
res = Manager.makeParser(org.hl7.fhir.r5.test.utils.TestingUtilities.context(version), FhirFormat.XML).parseSingle(org.hl7.fhir.r5.test.utils.TestingUtilities.loadTestResourceStream("validator", url.replace("/", "-").toLowerCase() + ".xml"));
res = new ObjectConverter(TestingUtilities.context(version)).convert(new Patient());
} else if (TestingUtilities.findTestResource("validator", url.replace("/", "-").toLowerCase() + ".json")) {
res = Manager.makeParser(TestingUtilities.context(version), FhirFormat.JSON).parseSingle(TestingUtilities.loadTestResourceStream("validator", url.replace("/", "-").toLowerCase() + ".json"));
} else if (TestingUtilities.findTestResource("validator", url.replace("/", "-").toLowerCase() + ".xml")) {
res = Manager.makeParser(TestingUtilities.context(version), FhirFormat.XML).parseSingle(TestingUtilities.loadTestResourceStream("validator", url.replace("/", "-").toLowerCase() + ".xml"));
}
if (res == null && url.contains("/")) {
String tail = url.substring(url.indexOf("/") + 1);
if (org.hl7.fhir.r5.test.utils.TestingUtilities.findTestResource("validator", tail.replace("/", "-").toLowerCase() + ".json")) {
res = Manager.makeParser(org.hl7.fhir.r5.test.utils.TestingUtilities.context(version), FhirFormat.JSON).parseSingle(org.hl7.fhir.r5.test.utils.TestingUtilities.loadTestResourceStream("validator", tail.replace("/", "-").toLowerCase() + ".json"));
} else if (org.hl7.fhir.r5.test.utils.TestingUtilities.findTestResource("validator", tail.replace("/", "-").toLowerCase() + ".xml")) {
res = Manager.makeParser(org.hl7.fhir.r5.test.utils.TestingUtilities.context(version), FhirFormat.XML).parseSingle(org.hl7.fhir.r5.test.utils.TestingUtilities.loadTestResourceStream("validator", tail.replace("/", "-").toLowerCase() + ".xml"));
if (TestingUtilities.findTestResource("validator", tail.replace("/", "-").toLowerCase() + ".json")) {
res = Manager.makeParser(TestingUtilities.context(version), FhirFormat.JSON).parseSingle(TestingUtilities.loadTestResourceStream("validator", tail.replace("/", "-").toLowerCase() + ".json"));
} else if (TestingUtilities.findTestResource("validator", tail.replace("/", "-").toLowerCase() + ".xml")) {
res = Manager.makeParser(TestingUtilities.context(version), FhirFormat.XML).parseSingle(TestingUtilities.loadTestResourceStream("validator", tail.replace("/", "-").toLowerCase() + ".xml"));
}
}
return res;
@ -553,7 +553,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
@Override
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException {
IResourceValidator val = org.hl7.fhir.r5.test.utils.TestingUtilities.context(version).newValidator();
IResourceValidator val = TestingUtilities.context(version).newValidator();
List<ValidationMessage> valerrors = new ArrayList<ValidationMessage>();
if (item instanceof Resource) {
val.validate(appContext, valerrors, (Resource) item, url);