fix up NativeHostServive and add tests for it

This commit is contained in:
Grahame Grieve 2019-12-18 11:41:40 +11:00
parent ba3e270c6c
commit 48473f3b5c
4 changed files with 21 additions and 9 deletions

View File

@ -550,7 +550,7 @@ public class ValidationEngine {
version = src.substring(src.indexOf("#")+1); version = src.substring(src.indexOf("#")+1);
} }
if (pcm == null) { if (pcm == null) {
log("Creating Package manager?"); // native host services...
pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION); pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
} }
NpmPackage pi = null; NpmPackage pi = null;

View File

@ -50,6 +50,7 @@ import org.hl7.fhir.exceptions.FHIRException;
*/ */
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser; import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent; import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r5.model.CodeSystem; import org.hl7.fhir.r5.model.CodeSystem;
@ -219,9 +220,16 @@ public class NativeHostServices {
* @param source * @param source
* @throws Exception * @throws Exception
*/ */
public void seeResource(byte[] source) throws Exception { public void seeResource(byte[] source, FhirFormat fmt) throws Exception {
try { try {
Resource r = new XmlParser().parse(source); Resource r;
if (fmt == FhirFormat.JSON) {
r = new JsonParser().parse(source);
} else if (fmt == FhirFormat.JSON) {
r = new XmlParser().parse(source);
} else {
throw new Exception("Unsupported format "+fmt.name());
}
validator.seeResource(r); validator.seeResource(r);
resourceCount++; resourceCount++;
} catch (Exception e) { } catch (Exception e) {

View File

@ -9,7 +9,8 @@ import org.junit.runners.Suite.SuiteClasses;
ValidationTestSuite.class, ValidationTestSuite.class,
ValidationEngineTests.class, ValidationEngineTests.class,
JsonSchemaTests.class, JsonSchemaTests.class,
// CDAValidationTestCase.class, NativeHostServiceTester.class,
// CDAValidationTestCase.class,
ProfileComparisonTests.class}) ProfileComparisonTests.class})
public class AllR5ValidationTests { public class AllR5ValidationTests {

View File

@ -1,21 +1,24 @@
package org.hl7.fhir.validation.tests; package org.hl7.fhir.validation.tests;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.validation.NativeHostServices; import org.hl7.fhir.r5.validation.NativeHostServices;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.validation.tests.utilities.TestUtilities; import org.hl7.fhir.validation.tests.utilities.TestUtilities;
import org.junit.Test;
public class NativeHostServiceTester { public class NativeHostServiceTester {
public static void main(String[] args) throws Exception { @Test
public void test() throws Exception {
System.out.println("starting..."); System.out.println("starting...");
NativeHostServices svc = new NativeHostServices(); NativeHostServices svc = new NativeHostServices();
svc.init("hl7.fhir.core#4.0.0"); svc.init("hl7.fhir.r4.core#4.0.1");
svc.connectToTxSvc("http://tx.fhir.org/r4", null); svc.connectToTxSvc("http://tx.fhir.org/r4", null);
System.out.println("base: "+svc.status()); System.out.println("base: "+svc.status());
svc.seeResource(TestingUtilities.loadTestResourceBytes("validator", "misc", "ValueSet-dicm-2-AnatomicModifier.json")); svc.seeResource(TestingUtilities.loadTestResourceBytes("validator", "misc", "ValueSet-dicm-2-AnatomicModifier.json"), FhirFormat.JSON);
System.out.println("added: "+svc.status()); System.out.println("added: "+svc.status());
svc.dropResource("ValueSet", "dicm-2-AnatomicModifier"); svc.dropResource("ValueSet", "dicm-2-AnatomicModifier");
@ -26,11 +29,11 @@ public class NativeHostServiceTester {
System.out.println(new String(res)); System.out.println(new String(res));
System.out.println("convert:"); System.out.println("convert:");
byte[] r4 = svc.convertResource(TestingUtilities.loadTestResourceBytes("validator", "patient-example.xml"), "xml", "r2"); byte[] r4 = svc.convertResource(TestingUtilities.loadTestResourceBytes("validator", "patient-example.xml"), "xml", "4.0");
System.out.println(new String(r4)); System.out.println(new String(r4));
System.out.println("unconvert:"); System.out.println("unconvert:");
byte[] r2 = svc.convertResource(TestingUtilities.loadTestResourceBytes("validator", "patient-example.xml"), "xml", "r2"); byte[] r2 = svc.convertResource(TestingUtilities.loadTestResourceBytes("validator", "patient-example.xml"), "xml", "1.0");
System.out.println(new String(r2)); System.out.println(new String(r2));