Skip to content

Commit

Permalink
Merge pull request #480 from medizininformatik-initiative/478-use-mai…
Browse files Browse the repository at this point in the history
…ntained-webserver-mocking-lib

Use WireMock instead of Mockserver
  • Loading branch information
knoppiks authored Dec 18, 2024
2 parents e3e1f21 + 02c696d commit 4d0ae94
Show file tree
Hide file tree
Showing 43 changed files with 1,322 additions and 1,260 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
codeql:
env:
MAVEN_ARGS: -B -T1C -Dmockserver.logLevel=WARN -Dfts.retryTimeout=false
MAVEN_ARGS: -B -T1C -Dfts.retryTimeout=false
GITHUB_TOKEN: ${{ github.token }}
permissions:
security-events: write
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
test:
env:
MAVEN_ARGS: -B -T1C -Dmockserver.logLevel=WARN -Dfts.retryTimeout=false
MAVEN_ARGS: -B -T1C -Dfts.retryTimeout=false
GITHUB_TOKEN: ${{ github.token }}
runs-on: ubuntu-24.04
strategy:
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
build-jar:
needs: [ test ]
env:
MAVEN_ARGS: -B -T1C -Dmockserver.logLevel=WARN -Dfts.retryTimeout=false
MAVEN_ARGS: -B -T1C -Dfts.retryTimeout=false
GITHUB_TOKEN: ${{ github.token }}
COMMIT_TAG: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
runs-on: ubuntu-24.04
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import static care.smith.fts.test.MockServerUtil.clientConfig;
import static care.smith.fts.test.TestPatientGenerator.generateOnePatient;
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
import static com.github.tomakehurst.wiremock.client.WireMock.jsonResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.ok;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.typesafe.config.ConfigFactory.parseResources;
import static java.time.Duration.ofDays;
import static org.mockserver.matchers.MatchType.ONLY_MATCHING_FIELDS;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;
import static org.mockserver.model.JsonBody.json;
import static reactor.test.StepVerifier.create;

import care.smith.fts.api.ConsentedPatient;
Expand All @@ -16,46 +16,45 @@
import care.smith.fts.cda.services.deidentifhir.DeidentifhirUtils;
import care.smith.fts.util.WebClientFactory;
import care.smith.fts.util.tca.TCADomains;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
import io.micrometer.core.instrument.MeterRegistry;
import java.io.IOException;
import org.hl7.fhir.r4.model.Bundle;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockserver.client.MockServerClient;
import org.mockserver.junit.jupiter.MockServerExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest(classes = ClinicalDomainAgent.class)
@ExtendWith(MockServerExtension.class)
@WireMockTest
class DeidentifhirStepTest {

@Autowired MeterRegistry meterRegistry;
private DeidentifhirStep step;
private WireMock wireMock;

@BeforeEach
void setUp(MockServerClient mockServer, @Autowired WebClientFactory clientFactory) {
void setUp(WireMockRuntimeInfo wireMockRuntime, @Autowired WebClientFactory clientFactory) {
var scraperConfig = parseResources(DeidentifhirUtils.class, "IDScraper.profile");
var deidentifhirConfig = parseResources(DeidentifhirUtils.class, "CDtoTransport.profile");
var domains = new TCADomains("domain", "domain", "domain");
var client = clientFactory.create(clientConfig(mockServer));
var client = clientFactory.create(clientConfig(wireMockRuntime));
wireMock = wireMockRuntime.getWireMock();
step =
new DeidentifhirStep(
client, domains, ofDays(14), deidentifhirConfig, scraperConfig, meterRegistry);
}

@Test
void correctRequestSent(MockServerClient mockServer) throws IOException {
mockServer
.when(
request()
.withMethod("POST")
.withPath("/api/v2/cd/transport-mapping")
.withBody(
json(
"""
void correctRequestSent() throws IOException {
wireMock.register(
post("/api/v2/cd/transport-mapping")
.withRequestBody(
equalToJson(
"""
{
"patientId" : "id1",
"resourceIds" : [ "id1.identifier.identifierSystem:id1", "id1.Patient:id1" ],
Expand All @@ -67,8 +66,9 @@ void correctRequestSent(MockServerClient mockServer) throws IOException {
"maxDateShift" : 1209600.0
}
""",
ONLY_MATCHING_FIELDS)))
.respond(response().withStatusCode(200));
true,
true))
.willReturn(ok()));

var consentedPatient = new ConsentedPatient("id1");
var bundle = generateOnePatient("id1", "2024", "identifierSystem");
Expand All @@ -78,10 +78,8 @@ void correctRequestSent(MockServerClient mockServer) throws IOException {
}

@Test
void emptyTCAResponseYieldsEmptyResult(MockServerClient mockServer) throws IOException {
mockServer
.when(request().withMethod("POST").withPath("/api/v2/cd/transport-mapping"))
.respond(response().withStatusCode(200));
void emptyTCAResponseYieldsEmptyResult() throws IOException {
wireMock.register(post("/api/v2/cd/transport-mapping").willReturn(ok()));

var consentedPatient = new ConsentedPatient("id1");
var bundle = generateOnePatient("id1", "2024", "identifierSystem");
Expand All @@ -91,22 +89,20 @@ void emptyTCAResponseYieldsEmptyResult(MockServerClient mockServer) throws IOExc
}

@Test
void deidentifySucceeds(MockServerClient mockServer) throws IOException {
mockServer
.when(request().withMethod("POST").withPath("/api/v2/cd/transport-mapping"))
.respond(
response()
.withBody(
json(
"""
void deidentifySucceeds() throws IOException {
wireMock.register(
post("/api/v2/cd/transport-mapping")
.willReturn(
jsonResponse(
"""
{
"transferId": "transferId",
"transportMapping": { "id1.identifier.identifierSystem:id1": "tident1",
"id1.Patient:id1": "tid1" },
"dateShiftValue": 1209600.000000000
}
"""))
.withStatusCode(200));
""",
200)));

var consentedPatient = new ConsentedPatient("id1");
var bundle = generateOnePatient("id1", "2024", "identifierSystem");
Expand All @@ -123,7 +119,7 @@ void emptyIdsYieldEmptyMono() {
}

@AfterEach
void tearDown(MockServerClient mockServer) {
mockServer.reset();
void tearDown() {
wireMock.resetMappings();
}
}
Loading

0 comments on commit 4d0ae94

Please sign in to comment.