generated from it-at-m/oss-repository-en-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07dd42c
commit c89c263
Showing
15 changed files
with
443 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
import java.net.URL; | ||
|
||
@Getter | ||
@Setter | ||
@Validated | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
.../src/test/java/de/muenchen/oss/digiwf/okewo/integration/adapter/out/OkEwoAdapterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package de.muenchen.oss.digiwf.okewo.integration.adapter.out; | ||
|
||
import de.muenchen.oss.digiwf.okewo.integration.client.api.PersonApi; | ||
import de.muenchen.oss.digiwf.okewo.integration.client.api.PersonErweitertApi; | ||
import de.muenchen.oss.digiwf.okewo.integration.client.model.*; | ||
import de.muenchen.oss.digiwf.okewo.integration.domain.exception.OkEwoIntegrationClientErrorException; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.reactive.function.client.WebClientResponseException; | ||
import reactor.core.publisher.Mono; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class OkEwoAdapterTest { | ||
|
||
private final PersonErweitertApi personErweitertApi = mock(PersonErweitertApi.class); | ||
private final PersonApi personApi = mock(PersonApi.class); | ||
private final OkEwoAdapter adapter = new OkEwoAdapter( | ||
personErweitertApi, | ||
personApi | ||
); | ||
|
||
private final WebClientResponseException notFoundException = new WebClientResponseException(HttpStatus.NOT_FOUND, "not found", null, null, null, null); | ||
private final WebClientResponseException badRequestException = new WebClientResponseException(HttpStatus.BAD_REQUEST, "bad request", null, null, null, null); | ||
|
||
@Test | ||
void getPerson_shouldReturnPersonWhenRequestWasSuccessfully() throws OkEwoIntegrationClientErrorException { | ||
final Person serverResponse = new Person().ordnungsmerkmal("om"); | ||
when(personApi.deMuenchenEaiEwoRouteROUTEPROCESSGETPERSON("om", "benutzerId")).thenReturn(Mono.just(serverResponse)); | ||
|
||
final Person result = adapter.getPerson("om", "benutzerId"); | ||
assertEquals("om", result.getOrdnungsmerkmal()); | ||
} | ||
|
||
@Test | ||
void getPerson_shouldThrowExceptionIfRequestFailed() { | ||
when(personApi.deMuenchenEaiEwoRouteROUTEPROCESSGETPERSON("om", "benutzerId")).thenThrow(notFoundException); | ||
|
||
final OkEwoIntegrationClientErrorException exception= assertThrows(OkEwoIntegrationClientErrorException.class, () -> { | ||
adapter.getPerson("om", "benutzerId"); | ||
}); | ||
|
||
assertTrue(exception.getMessage().contains("404")); | ||
} | ||
|
||
@Test | ||
void getExtendedPerson_shouldReturnPersonErweitertWhenRequestWasSuccessfully() throws OkEwoIntegrationClientErrorException { | ||
final PersonErweitert serverResponse = new PersonErweitert().ordnungsmerkmal("om"); | ||
when(personErweitertApi.deMuenchenEaiEwoRouteROUTEPROCESSGETPERSONERWEITERT("om", "benutzerId")).thenReturn(Mono.just(serverResponse)); | ||
|
||
final PersonErweitert result = adapter.getExtendedPerson("om", "benutzerId"); | ||
assertEquals("om", result.getOrdnungsmerkmal()); | ||
} | ||
|
||
@Test | ||
void getExtendedPerson_shouldThrowExceptionIfRequestFailed() { | ||
when(personErweitertApi.deMuenchenEaiEwoRouteROUTEPROCESSGETPERSONERWEITERT("om", "benutzerId")).thenThrow(notFoundException); | ||
|
||
final OkEwoIntegrationClientErrorException exception= assertThrows(OkEwoIntegrationClientErrorException.class, () -> { | ||
adapter.getExtendedPerson("om", "benutzerId"); | ||
}); | ||
|
||
assertTrue(exception.getMessage().contains("404")); | ||
} | ||
|
||
@Test | ||
void searchPerson_shouldReturnPersonErweitertWhenRequestWasSuccessfully() throws OkEwoIntegrationClientErrorException { | ||
final SuchePersonAnfrage request = new SuchePersonAnfrage(); | ||
final Person person = new Person().ordnungsmerkmal("om"); | ||
final SuchePersonAntwort serverResponse = new SuchePersonAntwort().addPersonenItem(person); | ||
when(personApi.deMuenchenEaiEwoRouteROUTEPROCESSSEARCHPERSON(request)).thenReturn(Mono.just(serverResponse)); | ||
|
||
final SuchePersonAntwort result = adapter.searchPerson(request); | ||
assertEquals("om", result.getPersonen().get(0).getOrdnungsmerkmal()); | ||
} | ||
|
||
@Test | ||
void searchPerson_shouldThrowExceptionIfRequestFailed() { | ||
final SuchePersonAnfrage request = new SuchePersonAnfrage(); | ||
when(personApi.deMuenchenEaiEwoRouteROUTEPROCESSSEARCHPERSON(request)).thenThrow(badRequestException); | ||
|
||
final OkEwoIntegrationClientErrorException exception= assertThrows(OkEwoIntegrationClientErrorException.class, () -> { | ||
adapter.searchPerson(request); | ||
}); | ||
|
||
assertTrue(exception.getMessage().contains("400")); | ||
} | ||
|
||
@Test | ||
void searchExtendedPerson() throws OkEwoIntegrationClientErrorException { | ||
final SuchePersonerweitertAnfrage request = new SuchePersonerweitertAnfrage(); | ||
final PersonErweitert person = new PersonErweitert().ordnungsmerkmal("om"); | ||
final SuchePersonerweitertAntwort response = new SuchePersonerweitertAntwort().addPersonenItem(person); | ||
when(personErweitertApi.deMuenchenEaiEwoRouteROUTEPROCESSSEARCHPERSONERWEITERT(request)).thenReturn(Mono.just(response)); | ||
|
||
final SuchePersonerweitertAntwort result = adapter.searchExtendedPerson(request); | ||
assertEquals("om", result.getPersonen().get(0).getOrdnungsmerkmal()); | ||
|
||
} | ||
|
||
@Test | ||
void searchExtendedPerson_shouldThrowExceptionIfRequestFailed() { | ||
SuchePersonerweitertAnfrage request = new SuchePersonerweitertAnfrage(); | ||
when(personErweitertApi.deMuenchenEaiEwoRouteROUTEPROCESSSEARCHPERSONERWEITERT(request)).thenThrow(badRequestException); | ||
|
||
final OkEwoIntegrationClientErrorException exception= assertThrows(OkEwoIntegrationClientErrorException.class, () -> { | ||
|
||
adapter.searchExtendedPerson(request); | ||
}); | ||
|
||
assertTrue(exception.getMessage().contains("400")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
...ewo-integration/digiwf-okewo-integration-service/src/main/resources/application-itest.yml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...n-service/src/test/java/de/muenchen/oss/digiwf/okewo/integration/EmbeddedKafkaConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package de.muenchen.oss.digiwf.okewo.integration; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.kafka.test.EmbeddedKafkaBroker; | ||
|
||
@Configuration | ||
public class EmbeddedKafkaConfig { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public EmbeddedKafkaBroker embeddedKafkaConfig() { | ||
return new EmbeddedKafkaBroker( | ||
1, | ||
true, | ||
"dwf-okewo-e2e-test", | ||
"dwf-connector-e2e-test", | ||
"dwf-connector-bpmnerror-e2e-test", | ||
"dwf-connector-incident-e2e-test" | ||
); | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
...est/java/de/muenchen/oss/digiwf/okewo/integration/OkEwoIntegrationApplicationE2eTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package de.muenchen.oss.digiwf.okewo.integration; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockTest; | ||
import de.muenchen.oss.digiwf.okewo.integration.client.model.Person; | ||
import de.muenchen.oss.digiwf.okewo.integration.domain.model.request.OkEwoEventRequest; | ||
import de.muenchen.oss.digiwf.okewo.integration.domain.model.request.OrdnungsmerkmalDto; | ||
import de.muenchen.oss.digiwf.okewo.integration.utility.DigiWFIntegrationE2eTest; | ||
import lombok.val; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.kafka.test.context.EmbeddedKafka; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@ActiveProfiles("itest") | ||
@DirtiesContext | ||
@EmbeddedKafka(partitions = 1, | ||
brokerProperties = {"listeners=PLAINTEXT://localhost:29092"}, | ||
topics = { | ||
"${spring.cloud.stream.bindings.functionRouter-in-0.destination}", | ||
"${spring.cloud.stream.bindings.sendMessage-out-0.destination}", | ||
"${spring.cloud.stream.bindings.integrationTestConsumer-in-0.destination}" | ||
}) | ||
@WireMockTest(httpPort = 8089) | ||
class OkEwoIntegrationApplicationE2eTest extends DigiWFIntegrationE2eTest { | ||
|
||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
private String processInstanceId; | ||
|
||
@BeforeEach | ||
void setup() { | ||
this.processInstanceId = UUID.randomUUID().toString(); | ||
} | ||
|
||
@Test | ||
public void shouldStart() { | ||
// test fails if application context can not start | ||
} | ||
|
||
@Test | ||
void shouldProcessGetPersonEvent() throws InterruptedException, JsonProcessingException { | ||
val ordnungsmerkmal = new OrdnungsmerkmalDto(); | ||
ordnungsmerkmal.setOrdnungsmerkmal("om"); | ||
val request = new OkEwoEventRequest<OrdnungsmerkmalDto>(); | ||
request.setRequest(ordnungsmerkmal); | ||
|
||
val person = new Person().ordnungsmerkmal("om"); | ||
// http://localhost:8089/personen/2.0/rest | ||
// http://localhost:8089/personen/2.0/rest/person/om?benutzerId=benutzerId | ||
this.setupWiremock("/personen/2.0/rest/person/om?benutzerId=benutzerId", objectMapper.writeValueAsString(person)); | ||
|
||
// send and receive messages | ||
final Map<String, Object> payload = super.runIntegration(request, processInstanceId, "getPerson"); | ||
assertNotNull(payload); | ||
|
||
} | ||
|
||
private void setupWiremock(final String url, final String expectedResponse) { | ||
WireMock.stubFor(WireMock | ||
.get(url) | ||
.willReturn(WireMock | ||
.aResponse() | ||
.withBody(expectedResponse) | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200))); | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
...c/test/java/de/muenchen/oss/digiwf/okewo/integration/OkEwoIntegrationApplicationTest.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
...n-service/src/test/java/de/muenchen/oss/digiwf/okewo/integration/TestMessageConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package de.muenchen.oss.digiwf.okewo.integration; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.messaging.Message; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
import static de.muenchen.oss.digiwf.message.common.MessageConstants.DIGIWF_PROCESS_INSTANCE_ID; | ||
|
||
@Component | ||
@Slf4j | ||
public class TestMessageConsumer { | ||
|
||
private final Map<String, Map<String, Object>> receivedMessages = new HashMap<>(); | ||
|
||
@Bean | ||
public Consumer<Message<Map<String, Object>>> integrationTestConsumer() { | ||
return message -> { | ||
log.info("TestMessageConsumer::message: {}", message); | ||
final Map<String, Object> payloadVariables = (Map<String, Object>) message.getPayload().get("payloadVariables"); | ||
receivedMessages.put(message.getHeaders().get(DIGIWF_PROCESS_INSTANCE_ID).toString(), payloadVariables); | ||
}; | ||
} | ||
|
||
public Map<String, Object> receiveMessage(final String processInstanceId) { | ||
return receivedMessages.get(processInstanceId); | ||
} | ||
|
||
} |
Oops, something went wrong.