From 4793e574b1285247c9636e3a204ce1623f4838d2 Mon Sep 17 00:00:00 2001 From: "dotasek.dev" Date: Wed, 20 Mar 2024 18:52:20 -0400 Subject: [PATCH] Break out helper classes --- .../special/TxServiceTestHelper.java | 51 ------------------- .../fhir/validation/special/TxTestData.java | 47 +++++++++++++++++ .../fhir/validation/special/TxTestSetup.java | 17 +++++++ .../tests/TerminologyServiceTests.java | 29 +++-------- 4 files changed, 70 insertions(+), 74 deletions(-) create mode 100644 org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTestData.java create mode 100644 org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTestSetup.java diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxServiceTestHelper.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxServiceTestHelper.java index b23a2f80d..ae074748f 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxServiceTestHelper.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxServiceTestHelper.java @@ -24,57 +24,6 @@ import java.util.*; public class TxServiceTestHelper { - public static class TestSetup { - public TestSetup(JsonObject suite, JsonObject test) { - this.suite = suite; - this.test = test; - } - @Getter - private JsonObject suite; - @Getter - private JsonObject test; - - } - - public static class TestData { - - @Getter - private final JsonObject manifest; - - @Getter - private final JsonObject externals; - - @Getter - private final List testData; - - public TestData() throws IOException { - String contents = TestingUtilities.loadTestResource("tx", "test-cases.json"); - String externalSource = TestingUtilities.loadTestResource("tx", "messages-tx.fhir.org.json"); - externals = org.hl7.fhir.utilities.json.parser.JsonParser.parseObject(externalSource); - - Map examples = new HashMap(); - manifest = org.hl7.fhir.utilities.json.parser.JsonParser.parseObject(contents); - for (org.hl7.fhir.utilities.json.model.JsonObject suite : manifest.getJsonObjects("suites")) { - if (!"tx.fhir.org".equals(suite.asString("mode"))) { - String sn = suite.asString("name"); - for (org.hl7.fhir.utilities.json.model.JsonObject test : suite.getJsonObjects("tests")) { - String tn = test.asString("name"); - examples.put(sn+"."+tn, new TestSetup(suite, test)); - } - } - } - - List names = new ArrayList(examples.size()); - names.addAll(examples.keySet()); - Collections.sort(names); - - testData = new ArrayList(examples.size()); - for (String id : names) { - testData.add(new Object[]{id, examples.get(id)}); - } - } - } - public static String getDiffForValidation(IWorkerContext context, String name, Resource requestParameters, String expectedResponse, String lang, String fp, JsonObject externals, boolean isCodeSystem) throws JsonSyntaxException, FileNotFoundException, IOException { org.hl7.fhir.r5.model.Parameters p = (org.hl7.fhir.r5.model.Parameters) requestParameters; ValueSet vs = null; diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTestData.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTestData.java new file mode 100644 index 000000000..e8652f3db --- /dev/null +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTestData.java @@ -0,0 +1,47 @@ +package org.hl7.fhir.validation.special; + +import lombok.Getter; +import org.hl7.fhir.r5.test.utils.TestingUtilities; +import org.hl7.fhir.utilities.json.model.JsonObject; + +import java.io.IOException; +import java.util.*; + +public class TxTestData { + + @Getter + private final JsonObject manifest; + + @Getter + private final JsonObject externals; + + @Getter + private final List testData; + + public TxTestData() throws IOException { + String contents = TestingUtilities.loadTestResource("tx", "test-cases.json"); + String externalSource = TestingUtilities.loadTestResource("tx", "messages-tx.fhir.org.json"); + externals = org.hl7.fhir.utilities.json.parser.JsonParser.parseObject(externalSource); + + Map examples = new HashMap(); + manifest = org.hl7.fhir.utilities.json.parser.JsonParser.parseObject(contents); + for (JsonObject suite : manifest.getJsonObjects("suites")) { + if (!"tx.fhir.org".equals(suite.asString("mode"))) { + String sn = suite.asString("name"); + for (JsonObject test : suite.getJsonObjects("tests")) { + String tn = test.asString("name"); + examples.put(sn + "." + tn, new TxTestSetup(suite, test)); + } + } + } + + List names = new ArrayList(examples.size()); + names.addAll(examples.keySet()); + Collections.sort(names); + + testData = new ArrayList(examples.size()); + for (String id : names) { + testData.add(new Object[]{id, examples.get(id)}); + } + } +} diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTestSetup.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTestSetup.java new file mode 100644 index 000000000..6937aaf0f --- /dev/null +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/TxTestSetup.java @@ -0,0 +1,17 @@ +package org.hl7.fhir.validation.special; + +import lombok.Getter; +import org.hl7.fhir.utilities.json.model.JsonObject; + +public class TxTestSetup { + public TxTestSetup(JsonObject suite, JsonObject test) { + this.suite = suite; + this.test = test; + } + + @Getter + private JsonObject suite; + @Getter + private JsonObject test; + +} diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/terminology/tests/TerminologyServiceTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/terminology/tests/TerminologyServiceTests.java index 9c6fbf71e..d16544e43 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/terminology/tests/TerminologyServiceTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/terminology/tests/TerminologyServiceTests.java @@ -4,11 +4,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.apache.commons.io.IOUtils; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_50; @@ -21,35 +16,26 @@ import org.hl7.fhir.exceptions.FHIRFormatError; import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.formats.JsonParser; import org.hl7.fhir.r5.formats.XmlParser; -import org.hl7.fhir.r5.model.CanonicalType; import org.hl7.fhir.r5.model.CodeType; -import org.hl7.fhir.r5.model.StringType; -import org.hl7.fhir.r5.model.CodeableConcept; -import org.hl7.fhir.r5.model.Coding; import org.hl7.fhir.r5.model.Constants; import org.hl7.fhir.r5.model.OperationOutcome; import org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity; import org.hl7.fhir.r5.model.OperationOutcome.IssueType; import org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent; -import org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent; import org.hl7.fhir.r5.model.Resource; -import org.hl7.fhir.r5.model.UriType; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent; import org.hl7.fhir.r5.terminologies.expansion.ValueSetExpansionOutcome; -import org.hl7.fhir.r5.terminologies.utilities.TerminologyServiceErrorClass; -import org.hl7.fhir.r5.terminologies.utilities.ValidationResult; import org.hl7.fhir.r5.test.utils.CompareUtilities; import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.utilities.FhirPublication; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; -import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.json.model.JsonObject; -import org.hl7.fhir.utilities.validation.ValidationOptions; import org.hl7.fhir.validation.ValidationEngine; import org.hl7.fhir.validation.special.TxServiceTestHelper; -import org.hl7.fhir.validation.special.TxServiceTestHelper.TestSetup; +import org.hl7.fhir.validation.special.TxTestSetup; +import org.hl7.fhir.validation.special.TxTestData; import org.hl7.fhir.validation.special.TxTesterScrubbers; import org.hl7.fhir.validation.special.TxTesterSorters; import org.hl7.fhir.validation.tests.utilities.TestUtilities; @@ -61,9 +47,6 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import com.google.common.base.Charsets; -import com.google.gson.JsonSyntaxException; - -import org.hl7.fhir.r5.context.IWorkerContext; import static org.junit.Assert.assertNull; @@ -72,22 +55,22 @@ import static org.junit.Assert.assertNull; public class TerminologyServiceTests { -private static TxServiceTestHelper.TestData testData; +private static TxTestData testData; @Parameters(name = "{index}: id {0}") public static Iterable data() throws IOException { - testData = new TxServiceTestHelper.TestData(); + testData = new TxTestData(); return testData.getTestData(); } - private final TestSetup setup; + private final TxTestSetup setup; private final String version; private final String name; private static ValidationEngine baseEngine; - public TerminologyServiceTests(String name, TestSetup setup) { + public TerminologyServiceTests(String name, TxTestSetup setup) { this.name = name; this.setup = setup; version = "5.0.0";