Merge pull request #777 from hapifhir/dotasek-add-terminology-to-testingutilities

Add hl7.terminology to shared worker contexts in tests
This commit is contained in:
dotasek 2022-03-29 19:07:59 -04:00 committed by GitHub
commit 0b5f1dd351
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 42 deletions

View File

@ -1,20 +1,11 @@
package org.hl7.fhir.r5.context;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
import org.hl7.fhir.utilities.VersionUtilities;
@ -28,6 +19,11 @@ import org.hl7.fhir.utilities.VersionUtilities;
public class CanonicalResourceManager<T extends CanonicalResource> {
private final String[] INVALID_TERMINOLOGY_URLS = {
"http://snomed.info/sct",
"http://nucc.org/provider-taxonomy"
};
public static abstract class CanonicalResourceProxy {
private String type;
private String id;
@ -219,7 +215,11 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
public void see(CachedCanonicalResource<T> cr) {
// ignore UTG NUCC erroneous code system
if (cr.getPackageInfo() != null && cr.getPackageInfo().getId() != null && cr.getPackageInfo().getId().startsWith("hl7.terminology") && "http://nucc.org/provider-taxonomy".equals(cr.getUrl())) {
if (cr.getPackageInfo() != null
&& cr.getPackageInfo().getId() != null
&& cr.getPackageInfo().getId().startsWith("hl7.terminology")
&& Arrays.stream(INVALID_TERMINOLOGY_URLS).anyMatch((it)->it.equals(cr.getUrl()))
) {
return;
}

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.context;
package org.hl7.fhir.r5.test.utils;
import java.io.IOException;
import java.io.InputStream;

View File

@ -114,6 +114,11 @@ public class TestingUtilities extends BaseTestingUtilities {
IWorkerContext fcontext = getWorkerContext(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
fcontext.setExpansionProfile(new Parameters());
if (!fcontext.hasPackage("hl7.terminology", null)) {
NpmPackage utg = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage("hl7.terminology");
System.out.println("Loading THO: "+utg.name()+"#"+utg.version());
fcontext.loadFromPackage(utg, new TestPackageLoader(new String[]{"CodeSystem", "ValueSet"}));
}
return fcontext;
} catch (Exception e) {
e.printStackTrace();

View File

@ -132,24 +132,24 @@ public class NarrativeGenerationTests {
}
XhtmlNode x = RendererFactory.factory(source, rc).build(source);
String target = TextFile.streamToString(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + ".html"));
String output = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
String tfn = TestingUtilities.tempFile("narrative", test.getId() + ".target.html");
String ofn = TestingUtilities.tempFile("narrative", test.getId() + ".output.html");
TextFile.stringToFile(target, tfn);
TextFile.stringToFile(output, ofn);
String msg = TestingUtilities.checkXMLIsSame(ofn, tfn);
String expected = TextFile.streamToString(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + ".html"));
String actual = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
String expectedFileName = TestingUtilities.tempFile("narrative", test.getId() + ".expected.html");
String actualFileName = TestingUtilities.tempFile("narrative", test.getId() + ".actual.html");
TextFile.stringToFile(expected, expectedFileName);
TextFile.stringToFile(actual, actualFileName);
String msg = TestingUtilities.checkXMLIsSame(actualFileName, expectedFileName);
Assertions.assertTrue(msg == null, "Output does not match expected: "+msg);
if (test.isMeta()) {
org.hl7.fhir.r5.elementmodel.Element e = Manager.parseSingle(context, TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + ".xml"), FhirFormat.XML);
x = RendererFactory.factory(source, rc).render(new ElementWrappers.ResourceWrapperMetaElement(rc, e));
target = TextFile.streamToString(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + "-meta.html"));
output = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
ofn = TestingUtilities.tempFile("narrative", test.getId() + "-meta.output.html");
TextFile.stringToFile(output, ofn);
msg = TestingUtilities.checkXMLIsSame(ofn, tfn);
expected = TextFile.streamToString(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + "-meta.html"));
actual = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
actualFileName = TestingUtilities.tempFile("narrative", test.getId() + "-meta.actual.html");
TextFile.stringToFile(actual, actualFileName);
msg = TestingUtilities.checkXMLIsSame(actualFileName, expectedFileName);
Assertions.assertTrue(msg == null, "Meta output does not match expected: "+msg);
}
}

View File

@ -18,7 +18,7 @@ import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.exceptions.PathEngineException;
import org.hl7.fhir.r5.conformance.ProfileUtilities;
import org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider;
import org.hl7.fhir.r5.context.TestPackageLoader;
import org.hl7.fhir.r5.test.utils.TestPackageLoader;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser;

View File

@ -1,6 +1,5 @@
package org.hl7.fhir.r5.test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@ -13,7 +12,7 @@ import javax.xml.parsers.ParserConfigurationException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.context.TestPackageLoader;
import org.hl7.fhir.r5.test.utils.TestPackageLoader;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser;
@ -109,13 +108,8 @@ public class VocabTests {
/* Do NOT get a shared worker context from Testing Utilities or else the terminology package loaded below
will appear in tests where it causes failures.
*/
context = TestingUtilities.getWorkerContext(VersionUtilities.getMajMin(TestingUtilities.DEFAULT_CONTEXT_VERSION));
if (!context.hasPackage("hl7.terminology", null)) {
NpmPackage utg = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage("hl7.terminology");
System.out.println("Loading THO: "+utg.name()+"#"+utg.version());
context.loadFromPackage(utg, new TestPackageLoader(new String[]{"CodeSystem", "ValueSet"}));
}
context = TestingUtilities.getSharedWorkerContext(VersionUtilities.getMajMin(TestingUtilities.DEFAULT_CONTEXT_VERSION));
}
@ParameterizedTest(name = "{index}: file {0}")
@ -150,13 +144,13 @@ public class VocabTests {
if (outcome.isOk()) {
outcome.getValueset().getExpansion().setIdentifier(null);
outcome.getValueset().getExpansion().setTimestamp(null);
String target = new XmlParser().setOutputStyle(OutputStyle.PRETTY).composeString(targetVS);
String output = new XmlParser().setOutputStyle(OutputStyle.PRETTY).composeString(outcome.getValueset());
String tfn = TestingUtilities.tempFile("vocab", test.getId() + ".target.html");
String ofn = TestingUtilities.tempFile("vocab", test.getId() + ".output.html");
TextFile.stringToFile(target, tfn);
TextFile.stringToFile(output, ofn);
String msg = TestingUtilities.checkXMLIsSame(ofn, tfn);
String expected = new XmlParser().setOutputStyle(OutputStyle.PRETTY).composeString(targetVS);
String actual = new XmlParser().setOutputStyle(OutputStyle.PRETTY).composeString(outcome.getValueset());
String expectedFileName = TestingUtilities.tempFile("vocab", test.getId() + ".expected.html");
String actualFileName = TestingUtilities.tempFile("vocab", test.getId() + ".actual.html");
TextFile.stringToFile(expected, expectedFileName);
TextFile.stringToFile(actual, actualFileName);
String msg = TestingUtilities.checkXMLIsSame(actualFileName, expectedFileName);
Assertions.assertTrue(msg == null, "Output does not match expected: "+msg);
} else {
Assertions.fail("Expansion Failed: "+outcome.getError());

View File

@ -19,7 +19,7 @@
<properties>
<hapi_fhir_version>5.4.0</hapi_fhir_version>
<validator_test_case_version>1.1.94</validator_test_case_version>
<validator_test_case_version>1.1.95</validator_test_case_version>
<junit_jupiter_version>5.7.1</junit_jupiter_version>
<junit_platform_launcher_version>1.7.1</junit_platform_launcher_version>
<maven_surefire_version>3.0.0-M5</maven_surefire_version>