Skip to content

Commit

Permalink
#768: finished e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanStrehlerCGI committed Nov 29, 2023
1 parent e960f73 commit 6051b91
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import de.muenchen.oss.digiwf.okewo.integration.application.in.SearchPersonInPort;
import de.muenchen.oss.digiwf.okewo.integration.application.out.IntegrationOutPort;
import de.muenchen.oss.digiwf.okewo.integration.client.model.*;
import de.muenchen.oss.digiwf.okewo.integration.domain.model.request.OkEwoEventRequest;
import de.muenchen.oss.digiwf.okewo.integration.domain.model.request.OkEwoOmBasedRequest;
import de.muenchen.oss.digiwf.okewo.integration.domain.model.request.OkEwoSearchPersonExtendedRequest;
import de.muenchen.oss.digiwf.okewo.integration.domain.model.request.OkEwoSearchPersonRequest;
import de.muenchen.oss.digiwf.okewo.integration.domain.model.request.OrdnungsmerkmalDto;
Expand Down Expand Up @@ -37,22 +37,21 @@ public class MessageProcessor {
private final SearchPersonErweitertInPort searchPersonErweitertInPort;

/**
* The Consumer expects an {@link OkEwoEventRequest} which represents an {@link OrdnungsmerkmalDto} for OK.EWO.
* The Consumer expects an {@link OkEwoOmBasedRequest} which represents an {@link OrdnungsmerkmalDto} for OK.EWO.
* <p>
* After successfully requesting OK.EWO a JSON representing a {@link Person} is returned.
* <p>
* In case of an error the error message is returned as a JSON representing {@link OkEwoErrorDto}.
*/
@Bean
public Consumer<Message<OkEwoEventRequest<Map<String, String>>>> getPerson() {
public Consumer<Message<OkEwoOmBasedRequest>> getPerson() {
return message -> {
log.debug("Processing new request \"getPerson\" from eventbus: {}", message);
val payload = message.getPayload();
val headers = message.getHeaders();
val request = payload.getRequest();
val om = request.get("ordnungsmerkmal");
try {
val response = getPersonInPort.getPerson(om);
val response = getPersonInPort.getPerson(request.getOrdnungsmerkmal());
Map<String, Object> result = Map.of(RESPONSE, response);
integration.correlateProcessMessage(headers, result);
} catch (Exception e) {
Expand All @@ -63,7 +62,7 @@ public Consumer<Message<OkEwoEventRequest<Map<String, String>>>> getPerson() {
}

/**
* The Consumer expects a {@link OkEwoEventRequest} which represents the {@link SuchePersonAnfrage} for OK.EWO.
* The Consumer expects a {@link OkEwoOmBasedRequest} which represents the {@link SuchePersonAnfrage} for OK.EWO.
* <p>
* After successfully requesting OK.EWO a JSON representing a {@link SuchePersonAntwort} is returned.
* <p>
Expand All @@ -88,23 +87,22 @@ public Consumer<Message<OkEwoSearchPersonRequest>> searchPerson() {


/**
* The Consumer expects an {@link OkEwoEventRequest} which represents an {@link OrdnungsmerkmalDto} for OK.EWO.
* The Consumer expects an {@link OkEwoOmBasedRequest} which represents an {@link OrdnungsmerkmalDto} for OK.EWO.
* <p>
* After successfully requesting OK.EWO a JSON representing a {@link de.muenchen.oss.digiwf.okewo.integration.client.model.PersonErweitert} is returned.
* <p>
* In case of an error the error message is returned as a JSON representing {@link OkEwoErrorDto}.
*/
@Bean
public Consumer<Message<OkEwoEventRequest<Map<String, String>>>> getPersonErweitert() {
public Consumer<Message<OkEwoOmBasedRequest>> getPersonErweitert() {
return message -> {
log.debug("Processing new request \"getPersonErweitert\" from eventbus: {}", message);
val payload = message.getPayload();
val headers = message.getHeaders();

val request = payload.getRequest();
val om = request.get("ordnungsmerkmal");
try {
val response = getPersonErweitertInPort.getPerson(om);
val response = getPersonErweitertInPort.getPerson(request.getOrdnungsmerkmal());
Map<String, Object> result = Map.of(RESPONSE, response);
integration.correlateProcessMessage(headers, result);
} catch (Exception e) {
Expand All @@ -115,7 +113,7 @@ public Consumer<Message<OkEwoEventRequest<Map<String, String>>>> getPersonErweit


/**
* The Consumer expects a {@link OkEwoEventRequest} which represents the {@link SuchePersonerweitertAnfrage} for OK.EWO.
* The Consumer expects a {@link OkEwoOmBasedRequest} which represents the {@link SuchePersonerweitertAnfrage} for OK.EWO.
* <p>
* After successfully requesting OK.EWO a JSON representing a {@link SuchePersonerweitertAntwort} is returned.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import lombok.Data;

@Data
public class OkEwoEventRequest<T> {
public class OkEwoOmBasedRequest {

/**
* The payload to request OK.EWO.
*/
private T request;
private OrdnungsmerkmalDto request;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
import com.github.tomakehurst.wiremock.matching.ContentPattern;
import de.muenchen.oss.digiwf.okewo.integration.client.model.*;
import de.muenchen.oss.digiwf.okewo.integration.domain.model.request.OkEwoEventRequest;
import de.muenchen.oss.digiwf.okewo.integration.domain.model.request.OkEwoOmBasedRequest;
import de.muenchen.oss.digiwf.okewo.integration.domain.model.request.OkEwoSearchPersonExtendedRequest;
import de.muenchen.oss.digiwf.okewo.integration.domain.model.request.OkEwoSearchPersonRequest;
import de.muenchen.oss.digiwf.okewo.integration.domain.model.request.OrdnungsmerkmalDto;
import de.muenchen.oss.digiwf.okewo.integration.utility.DigiWFIntegrationE2eTest;
import lombok.val;
Expand Down Expand Up @@ -59,11 +60,11 @@ public void shouldStart() {
void shouldProcessGetPersonEvent() throws InterruptedException, JsonProcessingException {
val ordnungsmerkmal = new OrdnungsmerkmalDto();
ordnungsmerkmal.setOrdnungsmerkmal("om");
val request = new OkEwoEventRequest<OrdnungsmerkmalDto>();
val request = new OkEwoOmBasedRequest();
request.setRequest(ordnungsmerkmal);

val person = new Person().ordnungsmerkmal("om");
this.setupGetPathOfWiremock("/personen/2.0/rest/person/om?benutzerId=benutzerId", objectMapper.writeValueAsString(person));
this.setupGetPathOfWiremock("/personen/2.0/rest/person/om?benutzerId=benutzerId", "username", "password", objectMapper.writeValueAsString(person));

// send and receive messages
final Map<String, Object> payload = super.runIntegration(request, processInstanceId, "getPerson");
Expand All @@ -78,14 +79,14 @@ void shouldProcessGetPersonEvent() throws InterruptedException, JsonProcessingEx
void shouldProcessSearchPersonEvent() throws InterruptedException, JsonProcessingException {
val ordnungsmerkmal = new OrdnungsmerkmalDto();
ordnungsmerkmal.setOrdnungsmerkmal("om");
val request = new OkEwoEventRequest<SuchePersonAnfrage>();
val request = new OkEwoSearchPersonRequest();
val searchRequest = new SuchePersonAnfrage();
searchRequest.setBenutzer(new BenutzerType().benutzerId("benutzerId"));
request.setRequest(searchRequest);
val person = new Person().ordnungsmerkmal("om");
val apiResponse = new SuchePersonAntwort().personen(List.of(person));

this.setupPostPathOfWiremock("/personen/2.0/rest/person/search", objectMapper.writeValueAsString(searchRequest),objectMapper.writeValueAsString(apiResponse));
this.setupPostPathOfWiremock("/personen/2.0/rest/person/search", objectMapper.writeValueAsString(searchRequest), "username", "password", objectMapper.writeValueAsString(apiResponse));

// send and receive messages
final Map<String, Object> payload = super.runIntegration(request, processInstanceId, "searchPerson");
Expand All @@ -100,11 +101,11 @@ void shouldProcessSearchPersonEvent() throws InterruptedException, JsonProcessin
void shouldProcessGetPersonErweitertEvent() throws InterruptedException, JsonProcessingException {
val ordnungsmerkmal = new OrdnungsmerkmalDto();
ordnungsmerkmal.setOrdnungsmerkmal("om");
val request = new OkEwoEventRequest<OrdnungsmerkmalDto>();
val request = new OkEwoOmBasedRequest();
request.setRequest(ordnungsmerkmal);

val person = new PersonErweitert().ordnungsmerkmal("om");
this.setupGetPathOfWiremock("/personen/2.0/rest/personErweitert/om?benutzerId=benutzerId", objectMapper.writeValueAsString(person));
this.setupGetPathOfWiremock("/personen/2.0/rest/personErweitert/om?benutzerId=benutzerId", "username", "password", objectMapper.writeValueAsString(person));

// send and receive messages
final Map<String, Object> payload = super.runIntegration(request, processInstanceId, "getPersonErweitert");
Expand All @@ -119,14 +120,14 @@ void shouldProcessGetPersonErweitertEvent() throws InterruptedException, JsonPro
void shouldProcessSearchPersonErweitertEvent() throws InterruptedException, JsonProcessingException {
val ordnungsmerkmal = new OrdnungsmerkmalDto();
ordnungsmerkmal.setOrdnungsmerkmal("om");
val request = new OkEwoEventRequest<SuchePersonerweitertAnfrage>();
val request = new OkEwoSearchPersonExtendedRequest();
val searchRequest = new SuchePersonerweitertAnfrage();
searchRequest.setBenutzer(new BenutzerType().benutzerId("benutzerId"));
request.setRequest(searchRequest);
val person = new PersonErweitert().ordnungsmerkmal("om");
val apiResponse = new SuchePersonerweitertAntwort().personen(List.of(person));

this.setupPostPathOfWiremock("/personen/2.0/rest/personErweitert/search", objectMapper.writeValueAsString(searchRequest),objectMapper.writeValueAsString(apiResponse));
this.setupPostPathOfWiremock("/personen/2.0/rest/personErweitert/search", objectMapper.writeValueAsString(searchRequest), "username", "password", objectMapper.writeValueAsString(apiResponse));

// send and receive messages
final Map<String, Object> payload = super.runIntegration(request, processInstanceId, "searchPersonErweitert");
Expand All @@ -137,20 +138,22 @@ void shouldProcessSearchPersonErweitertEvent() throws InterruptedException, Json
assertEquals(1, personenResponse.size());
}

private void setupGetPathOfWiremock(final String url, final String expectedResponse) {
private void setupGetPathOfWiremock(final String url, final String username, final String password, final String expectedResponse) {
WireMock.stubFor(WireMock
.get(url)
// .withBasicAuth()
.withBasicAuth(username, password)
.willReturn(WireMock
.aResponse()
.withBody(expectedResponse)
.withHeader("Content-Type", "application/json")
.withStatus(200)));
}
private void setupPostPathOfWiremock(final String url, final String requestBody, final String expectedResponse) {

private void setupPostPathOfWiremock(final String url, final String requestBody, final String username, final String password, final String expectedResponse) {
WireMock.stubFor(WireMock
.post(url)
.withRequestBody(equalToJson(requestBody))
.withRequestBody(equalToJson(requestBody))
.withBasicAuth(username, password)
.willReturn(WireMock
.aResponse()
.withBody(expectedResponse)
Expand Down

0 comments on commit 6051b91

Please sign in to comment.