diff --git a/xta-adapter/pom.xml b/xta-adapter/pom.xml index 3826c1456ac89437e24a9c7a81d7e9d0c3947f3f..772694d19667161a78fe7cd036935431333b2dc1 100644 --- a/xta-adapter/pom.xml +++ b/xta-adapter/pom.xml @@ -12,6 +12,7 @@ <properties> <spring-boot.build-image.imageName>docker.ozg-sh.de/xta-adapter:build-latest</spring-boot.build-image.imageName> + <okio.version>4.12.0</okio.version> </properties> <dependencies> @@ -81,6 +82,24 @@ <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> + <dependency> + <groupId>com.squareup.okio</groupId> + <artifactId>okio</artifactId> + <version>3.9.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.squareup.okhttp3</groupId> + <artifactId>mockwebserver</artifactId> + <version>${okio.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.squareup.okhttp3</groupId> + <artifactId>okhttp-tls</artifactId> + <version>${okio.version}</version> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/xta-adapter/src/test/java/de/ozgcloud/eingang/xta/XtaServiceITCase.java b/xta-adapter/src/test/java/de/ozgcloud/eingang/xta/XtaServiceITCase.java new file mode 100644 index 0000000000000000000000000000000000000000..f65beead1563a8ece951653ffce46c68d0c94962 --- /dev/null +++ b/xta-adapter/src/test/java/de/ozgcloud/eingang/xta/XtaServiceITCase.java @@ -0,0 +1,101 @@ +package de.ozgcloud.eingang.xta; + +import static org.junit.jupiter.api.Assertions.*; + +import java.net.InetAddress; +import java.security.KeyStore; +import java.security.cert.X509Certificate; +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +import de.ozgcloud.eingang.Application; +import lombok.SneakyThrows; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.tls.HandshakeCertificates; +import okhttp3.tls.HeldCertificate; + +@ActiveProfiles({ "itcase", "local" }) +@SpringBootTest(classes = Application.class) +class XtaServiceITCase { + + private MockWebServer nachrichtenBrokerMock; + + @Autowired + XtaService xtaService; + + @Autowired + private XtaProperties properties; + + @Autowired + @Qualifier("xtaKeyStore") + KeyStore xtaKeyStore; + + @BeforeEach + @SneakyThrows + public void createServer() { + nachrichtenBrokerMock = new MockWebServer(); + nachrichtenBrokerMock.requireClientAuth(); + { + // Setup trust between client and the NachrichtenbrokerMock for HTTPS + // (See https://github.com/square/okhttp/blob/master/okhttp-tls/README.md) + HeldCertificate localhostCertificate = new HeldCertificate.Builder() + .addSubjectAlternativeName("localhost") + .build(); + + HandshakeCertificates serverCertificates = new HandshakeCertificates.Builder() + .heldCertificate(localhostCertificate) + .addTrustedCertificate((X509Certificate) xtaKeyStore.getCertificate("xtatestkey")) + .build(); + + xtaKeyStore.setCertificateEntry("nachrichtenbroker", localhostCertificate.certificate()); + + nachrichtenBrokerMock.useHttps(serverCertificates.sslSocketFactory(), false); + } + + nachrichtenBrokerMock.start(InetAddress.getByName("127.0.0.1"), 0); + properties.getServer().setAddress(nachrichtenBrokerMock.getHostName() + ":" + nachrichtenBrokerMock.getPort()); + } + + @AfterEach + @SneakyThrows + public void stop() { + nachrichtenBrokerMock.shutdown(); + } + + @DisplayName("get messages") + @Nested + class TestGetMessages { + + @BeforeEach + void enqueueResponse() { + nachrichtenBrokerMock.enqueue(new MockResponse().setBody("<some/>")); + } + + @AfterEach + @SneakyThrows + void verifyRequestCall() { + var request = nachrichtenBrokerMock.takeRequest(1, TimeUnit.SECONDS); + assertNotNull(request); + assertEquals("/MB_XTA-WS/XTA210msgBoxPort.svc", request.getPath()); + } + + @DisplayName("should return empty") + @Test + void shouldReturnEmpty() { + var formDataList = xtaService.getMessages().toList(); + + assertTrue(formDataList.isEmpty()); + } + } + +}