Skip to content

Commit 143828e

Browse files
committed
full examples
1 parent 3577f44 commit 143828e

197 files changed

Lines changed: 69155 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package software.nhs.fhirvalidator;
2+
3+
import org.hl7.fhir.r4.model.OperationOutcome;
4+
import org.junit.jupiter.api.BeforeAll;
5+
import org.junit.jupiter.api.DisplayName;
6+
import org.junit.jupiter.api.TestInstance;
7+
import org.junit.jupiter.api.TestInstance.Lifecycle;
8+
import org.junit.jupiter.params.ParameterizedTest;
9+
import org.junit.jupiter.params.provider.MethodSource;
10+
import org.junit.jupiter.params.provider.Arguments;
11+
import org.junit.jupiter.params.provider.ArgumentsProvider;
12+
import org.junit.jupiter.params.provider.ArgumentsSource;
13+
import org.opentest4j.AssertionFailedError;
14+
15+
import software.nhs.fhirvalidator.controller.ValidateController;
16+
17+
import java.io.File;
18+
import java.io.IOException;
19+
import java.net.URL;
20+
import java.nio.file.Files;
21+
import java.util.List;
22+
import java.util.stream.Stream;
23+
24+
class Validator_all_examples_Test {
25+
26+
private final ClassLoader loader = Thread.currentThread().getContextClassLoader();
27+
private static ValidateController testValidateController;
28+
29+
static Stream<File> getExampleFhirFiles() {
30+
try {
31+
URL resource = Thread.currentThread().getContextClassLoader().getResource("examples/full_examples");
32+
if (resource == null) {
33+
throw new IllegalStateException("Could not find examples directory");
34+
}
35+
File dir = new File(resource.getFile());
36+
return Files.walk(dir.toPath())
37+
.filter(Files::isRegularFile)
38+
.map(path -> path.toFile())
39+
.sorted();
40+
} catch (IOException e) {
41+
throw new RuntimeException("Failed to load example files", e);
42+
}
43+
}
44+
45+
@BeforeAll
46+
static void setup() {
47+
String manifest_file = "nhs_digital.manifest.json";
48+
testValidateController = new ValidateController(manifest_file);
49+
}
50+
51+
@DisplayName("Test all valid example files")
52+
@ParameterizedTest(name = "Validating file: {0}")
53+
@MethodSource("getExampleFhirFiles")
54+
void testFhirExamples(File exampleFile) throws IOException {
55+
List<String> lines = Files.readAllLines(exampleFile.toPath());
56+
String fileContent = String.join(" ", lines);
57+
58+
OperationOutcome actualResult = testValidateController.parseAndValidateResource(fileContent);
59+
60+
for (OperationOutcome.OperationOutcomeIssueComponent issue : actualResult.getIssue()) {
61+
if (issue.getSeverity() == OperationOutcome.IssueSeverity.ERROR) {
62+
throw new AssertionFailedError("Error found checking file " + exampleFile.getAbsolutePath() +
63+
". Error: " + issue.getDiagnostics());
64+
}
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)