Skip to content

Commit

Permalink
add API tests directly #193
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveregger committed Feb 19, 2024
1 parent 1d693ed commit 3eee802
Show file tree
Hide file tree
Showing 17 changed files with 1,533 additions and 201 deletions.
8 changes: 8 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
"cwd": "${workspaceFolder}/matchbox-server"
},
{
"type": "java",
"name": "Launch Matchbox-Server (test)",
"request": "launch",
"mainClass": "ca.uhn.fhir.jpa.starter.Application",
"projectName": "matchbox-server",
"vmArgs": "-Dspring.config.additional-location=file:/Users/oegger/Documents/github/matchbox/matchbox-server/target/test-classes/application-test.yaml",
"cwd": "${workspaceFolder}/matchbox-server"
}, {
"type": "java",
"name": "Launch Matchbox-Server",
"request": "launch",
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2024/02/xx Release 3.6.0

- TODO: `docker pull europe-west6-docker.pkg.dev/ahdis-ch/ahdis/matchbox:v3.6.0`
- Upgraded to HAPI FHIR 7.0.0 and org.hl7.fhir.core 6.1.2.2 [#191](https://github.com/ahdis/matchbox/issues/191)
- added matchbox validation API tests [#193](https://github.com/ahdis/matchbox/issues/193)

2024/01/31 Release 3.5.4

- `docker pull europe-west6-docker.pkg.dev/ahdis-ch/ahdis/matchbox:v3.5.4`
Expand Down
84 changes: 83 additions & 1 deletion matchbox-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,46 @@
<artifactId>h2</artifactId>
</dependency>

<!-- The following dependencies are only needed for automated unit tests, you do not neccesarily need them to run the example. -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>elasticsearch</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-client</artifactId>
</dependency>

<dependency>
<groupId>org.hl7.fhir.testcases</groupId>
<artifactId>fhir-test-cases</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-test-utilities</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
Expand All @@ -162,14 +197,35 @@
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<!-- dependencies for test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<!-- Tells Maven to name the generated WAR file as ROOT.war -->
<finalName>matchbox</finalName>

<plugins>

<!-- Tell Maven which Java source version you want to use -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -190,10 +246,33 @@
</manifestEntries>
</archive>
<attachClasses>true</attachClasses>
<overlays>
<overlay>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-testpage-overlay</artifactId>
</overlay>
</overlays>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>

<!-- This is to run the integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.basepom.maven</groupId>
<artifactId>duplicate-finder-maven-plugin</artifactId>
Expand Down Expand Up @@ -261,6 +340,9 @@
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/test/resources</directory>
</resource>
<resource>
<directory>${project.build.directory}/generated-sources/properties</directory>
<filtering>false</filtering>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.model.DateTimeType;
import org.hl7.fhir.r5.model.DateType;
import org.hl7.fhir.r5.model.Duration;
import org.hl7.fhir.r5.model.OperationOutcome;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.TimeType;
import org.hl7.fhir.r5.model.UriType;
import org.hl7.fhir.r5.utils.OperationOutcomeUtilities;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.validation.ValidationMessage;
Expand Down Expand Up @@ -73,9 +78,6 @@ public class ValidationProvider {
@Autowired
private FhirContext myContext;

@Autowired
private INpmPackageVersionDao myPackageVersionDao;

// @Operation(name = "$canonical", manualRequest = true, idempotent = true, returnParameters = {
// @OperationParam(name = "return", type = IBase.class, min = 1, max = 1) })
// public IBaseResource canonical(HttpServletRequest theRequest) {
Expand Down Expand Up @@ -183,9 +185,10 @@ public IBaseResource validate(final HttpServletRequest theRequest) {
return this.getOoForError("Error during validation: %s".formatted(e.getMessage()));
}

sw.endCurrentTask();
long millis = sw.getMillis();
log.debug("Validation time: {}", sw);
return this.getOperationOutcome(sha3Hex, messages, profile, engine, sw.formatTaskDurations(), cliContext);

return this.getOperationOutcome(sha3Hex, messages, profile, engine, millis, cliContext);
}

private String getContentString(final HttpServletRequest theRequest,
Expand Down Expand Up @@ -219,7 +222,7 @@ private IBaseResource getOperationOutcome(final String id,
final List<ValidationMessage> messages,
final String profile,
final MatchboxEngine engine,
final String taskDuration,
final long ms,
final CliContext cliContext) {
final var oo = new OperationOutcome();
oo.setId(id);
Expand All @@ -231,6 +234,9 @@ private IBaseResource getOperationOutcome(final String id,
issue.setCode(OperationOutcome.IssueType.INFORMATIONAL);

final StructureDefinition structDef = engine.getStructureDefinition(profile);

final org.hl7.fhir.r5.model.StructureDefinition structDefR5 = (org.hl7.fhir.r5.model.StructureDefinition) VersionConvertorFactory_40_50.convertResource(structDef);

final var profileDate = (structDef.getDateElement() != null)
? " (%s)".formatted(structDef.getDateElement().asStringValue())
: " ";
Expand All @@ -241,10 +247,28 @@ private IBaseResource getOperationOutcome(final String id,
structDef.getVersion(),
profileDate,
String.join(", ", engine.getContext().getLoadedPackages()),
taskDuration,
"" + ms/1000.0+ "s",
VersionUtil.getPoweredBy(),
cliContext.toString()
));

var ext = issue.addExtension().setUrl("http://matchbox.health/validiation");
ext.addExtension("profile", new UriType(structDef.getUrl()));
ext.addExtension("profileVersion", new UriType(structDef.getVersion()));
ext.addExtension("profileDate", structDefR5.getDateElement());

ext.addExtension("total", new Duration().setUnit("ms").setValue(ms) );
if (matchboxEngineSupport.getSessionId(engine) != null) {
ext.addExtension("validatorVersion", new StringType(VersionUtil.getPoweredBy()));
}
cliContext.addContextToExtension(ext);
if (matchboxEngineSupport.getSessionId(engine) != null) {
ext.addExtension("sessionId", new StringType(matchboxEngineSupport.getSessionId(engine)));
}
for(String pkg : engine.getContext().getLoadedPackages()) {
ext.addExtension("package", new StringType(pkg));
}

}

// Map the SingleValidationMessages to OperationOutcomeIssue
Expand Down
Loading

0 comments on commit 3eee802

Please sign in to comment.