enhance snapshot generation tests to allow specifying version for the base

This commit is contained in:
Grahame Grieve 2020-02-28 15:57:21 +11:00
parent a3d7acdf35
commit 95959ed01a
2 changed files with 22 additions and 7 deletions

View File

@ -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<String, IWorkerContext> 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;

View File

@ -108,6 +108,8 @@ public class SnapShotGenerationTests {
private boolean fail;
private boolean newSliceProcessing;
private boolean debug;
private String version;
private List<Rule> 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());