Newer
Older
package de.ozgcloud.xta.client;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.assertj.core.api.Assertions.*;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import de.ozgcloud.xta.client.config.XtaClientConfig;
import de.ozgcloud.xta.client.core.WrappedXtaService;
import de.ozgcloud.xta.client.core.WrappedXtaServiceFactory;
import de.ozgcloud.xta.client.factory.XtaMockServerResponseTestFactory;
import de.ozgcloud.xta.client.model.XtaIdentifier;
import lombok.SneakyThrows;
class XtaSchemaValidationITCase {
WrappedXtaService xtaService;
private static final String XTA_MOCK_SERVER_URL_BASE = "https://localhost:8089";
private static final String XTA_MOCK_SERVER_URL_PATH = "/MB_XTA-WS/XTA210";
private static final String XTA_MOCK_SERVER_URL = XTA_MOCK_SERVER_URL_BASE + XTA_MOCK_SERVER_URL_PATH;
WireMockServer wireMockServer;
@BeforeEach
@SneakyThrows
void setup() {
wireMockServer = new WireMockServer(options()
.port(8088)
.httpsPort(8089)
.keystorePath("store/xta-test-server_keystore.p12")
.keystorePassword("password")
.keystoreType("PKCS12")
.caKeystorePath("store/xta-test_truststore.jks")
.caKeystorePassword("password")
.caKeystoreType("JKS")
);
WireMock.configureFor(8088);
xtaService = WrappedXtaServiceFactory.from(XtaClientConfig.builder()
.schemaValidation(true)
.logSoapResponses(true)
.logSoapRequests(true)
.trustStore(XtaClientConfig.KeyStore.builder()
.content(FileUtils.readFileToByteArray(new File("src/test/resources/store/xta-test_truststore.jks")))
.password("password".toCharArray())
.type("JKS")
.build())
.clientCertKeystore(XtaClientConfig.KeyStore.builder()
.content(FileUtils.readFileToByteArray(new File("src/test/resources/store/xta-test-client-john-smith_keystore.p12")))
.password("password".toCharArray())
.type("PKCS12")
.build())
.managementServiceUrl(wireMockServer.baseUrl() + XTA_MOCK_SERVER_URL_PATH + "managementPort.svc")
.sendServiceUrl(wireMockServer.baseUrl() + XTA_MOCK_SERVER_URL_PATH + "sendPort.svc")
.msgBoxServiceUrl(wireMockServer.baseUrl() + XTA_MOCK_SERVER_URL_PATH + "msgBoxPort.svc")
.build()).create();
}
@AfterEach
void tearDown() {
wireMockServer.stop();
}
@DisplayName("should throw UnmarshallException on bad response")
@Test
@SneakyThrows
void shouldThrowUnmarshallExceptionOnBadResponse() {
wireMockServer.stubFor(post(XTA_MOCK_SERVER_URL_PATH + "msgBoxPort.svc")
XtaMockServerResponseTestFactory.createConstantGetMessageResponse(
"84d0edd7-709b-4a7b-9aac-b3ee82041ef0_Geschaeftsgang.Geschaeftsgang.0201.zip")));
var message = xtaService.getMessage("urn:de:xta:messageid:dataport_xta_210:db6ad282-c510-4154-a167-daaa8b9f345a", XtaIdentifier.builder()
.value("afmsh:ozg-cloud-stage-Utopia")
.build());
assertThat(message).isNotNull();
}
@DisplayName("should not fail on good response")
@Test
void shouldNotFailOnGoodResponse() {
}
}