From 95959ed01aa9ee9ad68bf33dc7978427c5431adc Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 28 Feb 2020 15:57:21 +1100 Subject: [PATCH] enhance snapshot generation tests to allow specifying version for the base --- .../fhir/r5/test/utils/TestingUtilities.java | 20 +++++++++++++------ .../fhir/r5/test/SnapShotGenerationTests.java | 9 ++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java index 1a2686032..744646a7b 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java @@ -26,6 +26,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -41,6 +42,7 @@ import org.hl7.fhir.r5.model.Parameters; import org.hl7.fhir.utilities.CSFile; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; +import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.cache.PackageCacheManager; import org.hl7.fhir.utilities.cache.ToolsVersion; @@ -59,22 +61,28 @@ import com.google.gson.JsonSyntaxException; public class TestingUtilities { private static final boolean SHOW_DIFF = true; - static public IWorkerContext fcontext; + static public Map fcontexts; - public static IWorkerContext context() { - if (fcontext == null) { + public static IWorkerContext context() { + return context("4.0.1"); + } + public static IWorkerContext context(String version) { + if (fcontexts == null) { + fcontexts = new HashMap<>(); + } + if (!fcontexts.containsKey(version)) { PackageCacheManager pcm; try { pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION); - fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); + IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version)); fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml"))); fcontext.setExpansionProfile(new Parameters()); + fcontexts.put(version, fcontext); } catch (Exception e) { throw new Error(e); } - } - return fcontext; + return fcontexts.get(version); } static public boolean silent; diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java index 9c1bfd7e1..e61e74d2e 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java @@ -108,6 +108,8 @@ public class SnapShotGenerationTests { private boolean fail; private boolean newSliceProcessing; private boolean debug; + private String version; + private List rules = new ArrayList<>(); private StructureDefinition source; private StructureDefinition included; @@ -121,6 +123,11 @@ public class SnapShotGenerationTests { fail = "true".equals(test.getAttribute("fail")); newSliceProcessing = !"false".equals(test.getAttribute("new-slice-processing")); debug = "true".equals(test.getAttribute("debug")); + if (test.hasAttribute("version")) { + version = test.getAttribute("version"); + } else { + version = "4.0.1"; + } id = test.getAttribute("id"); include = test.getAttribute("include"); @@ -493,7 +500,7 @@ public class SnapShotGenerationTests { throw new Exception("URL mismatch on base: "+base.getUrl()+" wanting "+test.getSource().getBaseDefinition()); StructureDefinition output = test.getSource().copy(); - ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), messages , new TestPKP()); + ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(test.version), messages , new TestPKP()); pu.setNewSlicingProcessing(test.isNewSliceProcessing()); pu.setThrowException(false); pu.setDebug(test.isDebug());