From 0ad388213293fa1eeb89cc8a1a2072a217484a54 Mon Sep 17 00:00:00 2001 From: Oliver Egger Date: Fri, 1 Nov 2019 15:40:26 +0100 Subject: [PATCH] FML updates for tests and validator --- .../org/hl7/fhir/r4/utils/FHIRPathEngine.java | 12 +++++----- .../r5/test/FHIRMappingLanguageTests.java | 9 ++++---- .../fhir/r5/validation/ValidationEngine.java | 22 +++++++++---------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathEngine.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathEngine.java index 7a4506149..b8a9c1cca 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathEngine.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathEngine.java @@ -248,11 +248,13 @@ public class FHIRPathEngine { public FHIRPathEngine(IWorkerContext worker) { super(); this.worker = worker; - for (StructureDefinition sd : worker.allStructures()) { - if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() != StructureDefinitionKind.LOGICAL) - allTypes.put(sd.getName(), sd); - if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) { - primitiveTypes.add(sd.getName()); + if (this.worker!=null) { + for (StructureDefinition sd : worker.allStructures()) { + if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() != StructureDefinitionKind.LOGICAL) + allTypes.put(sd.getName(), sd); + if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) { + primitiveTypes.add(sd.getName()); + } } } } diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/FHIRMappingLanguageTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/FHIRMappingLanguageTests.java index cc411d57e..3dce48836 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/FHIRMappingLanguageTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/FHIRMappingLanguageTests.java @@ -82,7 +82,7 @@ public class FHIRMappingLanguageTests implements ITransformerServices { static public void setUp() throws Exception { if (context == null) { PackageCacheManager pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION); - context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.0")); + context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.1")); jsonParser = new JsonParser(); jsonParser.setOutputStyle(OutputStyle.PRETTY); } @@ -93,7 +93,7 @@ public class FHIRMappingLanguageTests implements ITransformerServices { InputStream fileSource = TestingUtilities.loadTestResourceStream("r5", "fml", source); InputStream fileMap = TestingUtilities.loadTestResourceStream("r5", "fml", map); - String fileOutput = TestingUtilities.tempFile("fml", output); + String outputJson = TestingUtilities.loadTestResource("r5","fml", output); String fileOutputRes = TestingUtilities.tempFile("fml", output)+".out"; outputs.clear(); @@ -117,9 +117,10 @@ public class FHIRMappingLanguageTests implements ITransformerServices { if (ok) { ByteArrayOutputStream boas = new ByteArrayOutputStream(); jsonParser.compose(boas, resource); - log(boas.toString()); + String result = boas.toString(); + log(result); TextFile.bytesToFile(boas.toByteArray(), fileOutputRes); - msg = TestingUtilities.checkJsonIsSame(fileOutputRes,fileOutput); + msg = TestingUtilities.checkJsonSrcIsSame(result, outputJson); assertTrue(msg, Utilities.noString(msg)); } else assertTrue("Error, but proper output was expected (" + msg + ")", output.equals("$error")); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java index 803428fb9..36af1fdec 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java @@ -293,7 +293,7 @@ public class ValidationEngine implements IValidatorResourceFetcher { } } - + private SimpleWorkerContext context; // private FHIRPathEngine fpe; private Map binaries = new HashMap(); @@ -753,7 +753,7 @@ public class ValidationEngine implements IValidatorResourceFetcher { return FhirFormat.TEXT; return checkIsResource(TextFile.fileToBytes(path), path); - } + } public void connectToTSServer(String url, String log, FhirPublication version) throws URISyntaxException, FHIRException { context.setTlogging(false); @@ -769,7 +769,7 @@ public class ValidationEngine implements IValidatorResourceFetcher { throw e; } } - } + } public void loadProfile(String src) throws Exception { if (context.hasResource(StructureDefinition.class, src)) @@ -808,10 +808,10 @@ public class ValidationEngine implements IValidatorResourceFetcher { } } } - } + } if (canonical != null) grabNatives(source, canonical); - } + } public Resource loadFileWithErrorChecking(String version, Entry t, String fn) { if (debug) @@ -907,10 +907,10 @@ public class ValidationEngine implements IValidatorResourceFetcher { if (e.getKey().endsWith(".zip")) binaries.put(prefix+"#"+e.getKey(), e.getValue()); } - } + } public void setQuestionnaires(List questionnaires) { - } + } public void setNative(boolean doNative) { this.doNative = doNative; @@ -1147,12 +1147,12 @@ public class ValidationEngine implements IValidatorResourceFetcher { private void validateSHEX(String location, List messages) { messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.INFORMATIONAL, location, "SHEX Validation is not done yet", IssueSeverity.INFORMATION)); - } + } private void validateXmlSchema(String location, List messages) throws FileNotFoundException, IOException, SAXException { XmlValidator xml = new XmlValidator(messages, loadSchemas(), loadTransforms()); messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.INFORMATIONAL, location, "XML Schema Validation is not done yet", IssueSeverity.INFORMATION)); - } + } private Map loadSchemas() throws IOException { Map res = new HashMap(); @@ -1176,7 +1176,7 @@ public class ValidationEngine implements IValidatorResourceFetcher { private void validateJsonSchema(String location, List messages) { messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.INFORMATIONAL, location, "JSON Schema Validation is not done yet", IssueSeverity.INFORMATION)); - } + } private List filterMessages(List messages) { List filteredValidation = new ArrayList(); @@ -1208,7 +1208,7 @@ public class ValidationEngine implements IValidatorResourceFetcher { } new NarrativeGenerator("", "", context).generate(null, op); return op; - } + } public static String issueSummary (OperationOutcomeIssueComponent issue) { String source = ToolingExtensions.readStringExtension(issue, ToolingExtensions.EXT_ISSUE_SOURCE);