# DigiWF Integration E2E Test Library

Mit Hilfe der DigiWF Integration E2E Test Library können Integrationen End-to-End getestet werden. Hierfür wird ein Embedded-Kafka gestartet und über Spring Cloud Stream eine Verbindung zu diesem hergestellt. Anschließend kann die Integration in End-to-End Tests getestet werden, indem Nachrichten an den Embedded-Kafka gesendet werden und die Antworten überprüft werden.

Externe Schnittstellen können zudem über Wiremock simuliert werden.

Um dieses Setup zu vereinfachen, stellt die DigiWF Integration E2E Test Library Hilfsklassen, Annotations und Configs zur Verfügung.

# Verwendung

Die Bibliothek muss in der Anwendung als Test-Dependency deklariert werden:


<dependency>
    <groupId>de.muenchen.oss.digiwf</groupId>
    <artifactId>digiwf-e2e-test-starter</artifactId>
    <version>${latest.digiwf.version}</version>
    <scope>test</scope>
</dependency>
1
2
3
4
5
6
7

Anschließend kann die Bibliothek in einem End-to-End Test verwendet werden:


@DigiwfE2eTest
class ExampleIntegrationE2eTest {
    private String processInstanceId;

    @Autowired
    private DigiWFIntegrationE2eTestUtility digiWFIntegrationE2eTestUtility;

    @BeforeEach
    void setup() {
        this.processInstanceId = UUID.randomUUID().toString();
    }

    @Test
    void testExampleFeature() {
        // create integration input data
        final ExampleIntegrationInputData testData = new ExampleIntegrationInputData();
        final String type = "integrationType";

        // run the integration
        final Map<String, Object> payload = this.digiWFIntegrationE2eTestUtility.runIntegration(testData,
                processInstanceId, type);

        // verify the payload with asserts
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

Die Annotation @DigiwfE2eTest dient als Helper-Annotation, um die Spring-Boot-Test-Annotationen @SpringBootTest, @EmbeddedKafka, @ActiveProfiles("itest") und @DirtiesContext zu kombinieren.

Hinweis: Die E2E-Tests müssen mit dem Profil itest ausgeführt werden.

# Konfiguration

spring:
  cloud:
    stream:
      bindings:
        functionRouter-in-0:
          destination: "dwf-example-integration-test"
1
2
3
4
5
6

In der application-itest.yml muss die Destination (Kafka Topic) für den Function Router angegeben werden. Weitere Konfigurationen werden direkt über die Bibliothek bereitgestellt.

# Wiremock

Um externe (REST) Schnittstellen zu simulieren, kann Wiremock verwendet werden. Für das Wiremock-Setup stellt die Bibliothek ebenfalls eine Hilfsklasse DigiWFWiremockUtility bereit.

WARNING

Zusätzlich muss die Annotation @WireMockTest(httpPort = 8089) verwendet werden, um Wiremock zu starten. Die DigiWFWiremockUtility kann erst nach dem Start von Wiremock verwendet werden.

// GET Requests without Basic Auth
DigiWFWiremockUtility.setupGET("/some/url", expectedResponse);

        // GET Requests with Basic Auth
        DigiWFWiremockUtility.setupGETWithBasicAuth("/some/url", "johndoe", "password", expectedResponse);

        // POST Requests without Basic Auth
        DigiWFWiremockUtility.setupPOST("/some/url", requestBody, expectedResponse);

        // POST Requests with Basic Auth
        DigiWFWiremockUtility.setupPOSTWithBasicAuth("/some/url", requestBody, "johndoe", "password", expectedResponse);
1
2
3
4
5
6
7
8
9
10
11

Nachfolgend ist ein vollständiges Beispiel für einen End-to-End Test mit Wiremock aufgeführt:


@DigiwfE2eTest
@WireMockTest(httpPort = 8089)
class ExampleIntegrationE2eTestWithWiremock {
    private String processInstanceId;

    @Autowired
    private DigiWFIntegrationE2eTestUtility digiWFIntegrationE2eTestUtility;

    @BeforeEach
    void setup() {
        this.processInstanceId = UUID.randomUUID().toString();
    }

    @Test
    void testExampleFeature() {
        // create integration input data
        final ExampleIntegrationInputData testData = new ExampleIntegrationInputData();
        final String type = "integrationType";

        // setup wiremock
        DigiWFWiremockUtility.setupGET("/url/", "{\"foo\": \"bar\"}");

        // run the integration
        final Map<String, Object> payload = this.digiWFIntegrationE2eTestUtility.runIntegration(testData,
                processInstanceId, type);

        // verify the payload with asserts
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30