Adding back in local file read

This commit is contained in:
markiantorno 2020-06-02 09:40:33 -04:00
parent 8a7737cac0
commit 8aee1e2e6b
1 changed files with 23 additions and 10 deletions

View File

@ -14,17 +14,30 @@ public class BaseTestingUtilities {
static public boolean silent;
public static String loadTestResource(String... paths) throws IOException {
// resolve from the package
String contents;
String classpath = ("/org/hl7/fhir/testcases/" + Utilities.pathURL(paths));
try (InputStream inputStream = BaseTestingUtilities.class.getResourceAsStream(classpath)) {
if (inputStream == null) {
throw new IOException("Can't find file on classpath: " + classpath);
/**
* This 'if' condition checks to see if the fhir-test-cases project (https://github.com/FHIR/fhir-test-cases) is
* installed locally at the same directory level as the core library project is. If so, the test case data is read
* directly from that project, instead of the imported maven dependency jar. It is important, that if you want to
* test against the dependency imported from sonatype nexus, instead of your local copy, you need to either change
* the name of the project directory to something other than 'fhir-test-cases', or move it to another location, not
* at the same directory level as the core project.
*/
if (new File("../../fhir-test-cases").exists() && isTryToLoadFromFileSystem()) {
String n = Utilities.path(System.getProperty("user.dir"), "..", "..", "fhir-test-cases", Utilities.path(paths));
// ok, we'll resolve this locally
return TextFile.fileToString(new File(n));
} else {
// resolve from the package
String contents;
String classpath = ("/org/hl7/fhir/testcases/" + Utilities.pathURL(paths));
try (InputStream inputStream = BaseTestingUtilities.class.getResourceAsStream(classpath)) {
if (inputStream == null) {
throw new IOException("Can't find file on classpath: " + classpath);
}
contents = IOUtils.toString(inputStream, java.nio.charset.StandardCharsets.UTF_8);
}
contents = IOUtils.toString(inputStream, java.nio.charset.StandardCharsets.UTF_8);
return contents;
}
return contents;
}
public static InputStream loadTestResourceStream(String... paths) throws IOException {
@ -76,4 +89,4 @@ public class BaseTestingUtilities {
}
}
}