Separate loading logic from data
This commit is contained in:
parent
4793e574b1
commit
0549903ade
|
@ -17,6 +17,7 @@ import org.hl7.fhir.utilities.i18n.I18nConstants;
|
|||
import org.hl7.fhir.utilities.json.model.JsonObject;
|
||||
import org.hl7.fhir.utilities.validation.ValidationOptions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
@ -176,8 +177,12 @@ public class TxServiceTestHelper {
|
|||
TxTesterScrubbers.scrubParams(res);
|
||||
|
||||
String actualResponse = new JsonParser().setOutputStyle(IParser.OutputStyle.PRETTY).composeString(res);
|
||||
|
||||
|
||||
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(expectedResponse, actualResponse, externals);
|
||||
if (diff != null) {
|
||||
dumparoo("/Users/david.otasek/IN/2024-02-05-hapi-core-bump-6-2.16/core-test", name, expectedResponse, actualResponse);
|
||||
Utilities.createDirectory(Utilities.getDirectoryForFile(fp));
|
||||
TextFile.stringToFile(actualResponse, fp);
|
||||
System.out.println("Test "+name+"failed: "+diff);
|
||||
|
@ -185,4 +190,15 @@ public class TxServiceTestHelper {
|
|||
return diff;
|
||||
}
|
||||
}
|
||||
|
||||
public static void dumparoo(String rootDirectory, String testName, String expected, String actual) throws IOException {
|
||||
String fullDirectory = rootDirectory + "/" + testName;
|
||||
File directory = new File(fullDirectory);
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
TextFile.stringToFile(expected, fullDirectory + "/expected.json");
|
||||
TextFile.stringToFile(actual, fullDirectory + "/actual.json");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,19 @@ public class TxTestData {
|
|||
@Getter
|
||||
private final List<Object[]> testData;
|
||||
|
||||
public TxTestData() throws IOException {
|
||||
private TxTestData(List<Object[]> testData, JsonObject manifest, JsonObject externals) throws IOException {
|
||||
this.testData = testData;
|
||||
this.manifest = manifest;
|
||||
this.externals = externals;
|
||||
}
|
||||
|
||||
public static TxTestData loadTestDataFromDefaultClassPath() 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);
|
||||
JsonObject externals = org.hl7.fhir.utilities.json.parser.JsonParser.parseObject(externalSource);
|
||||
|
||||
Map<String, TxTestSetup> examples = new HashMap<String, TxTestSetup>();
|
||||
manifest = org.hl7.fhir.utilities.json.parser.JsonParser.parseObject(contents);
|
||||
JsonObject 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");
|
||||
|
@ -39,9 +45,11 @@ public class TxTestData {
|
|||
names.addAll(examples.keySet());
|
||||
Collections.sort(names);
|
||||
|
||||
testData = new ArrayList<Object[]>(examples.size());
|
||||
List<Object[]> testData = new ArrayList<Object[]>(examples.size());
|
||||
for (String id : names) {
|
||||
testData.add(new Object[]{id, examples.get(id)});
|
||||
}
|
||||
|
||||
return new TxTestData(testData, manifest, externals);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ private static TxTestData testData;
|
|||
|
||||
@Parameters(name = "{index}: id {0}")
|
||||
public static Iterable<Object[]> data() throws IOException {
|
||||
testData = new TxTestData();
|
||||
testData = TxTestData.loadTestDataFromDefaultClassPath();
|
||||
return testData.getTestData();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue