Skip to content
Snippets Groups Projects
Commit 9aab3232 authored by Jan Zickermann's avatar Jan Zickermann
Browse files

OZG-5412 Try first attempt of mantelantrag integration test with MockWebServer

parent 73287a7c
Branches
Tags
No related merge requests found
......@@ -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>
......
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());
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment