+package de.juplo.demo;
+
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.mockserver.integration.ClientAndServer;
+import org.testcontainers.containers.NginxContainer;
+import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
+
+
+
+/**
+ * This class starts a
+ * {@link https://www.testcontainers.org/modules/nginx/ NginX-Webserver}
+ * via a {@link https://www.testcontainers.org/ Testcontainer} and a
+ * standalone {@link http://www.mock-server.com/#what-is-mockserver MockServer},
+ * that can be used to intercept requests for assertions / verifications.
+ * <p>
+ * We use the {@link
+ * https://www.testcontainers.org/test_framework_integration/manual_lifecycle_control/#singleton-containers
+ * Singleton Pattern} to start the NginX-Testcontainer and start the MockServer
+ * programmatically via the {@link
+ * http://www.mock-server.com/mock_server/running_mock_server.html#client_api
+ * Client-API}.
+ * @author Kai Moritz
+ */
+public abstract class IntegrationTestBase
+{
+ static final NginxContainer NGINX;
+ static final ClientAndServer MOCK_SERVER;
+
+
+ static
+ {
+ NGINX = new NginxContainer().withCustomContent("src/test/resources/");
+ MOCK_SERVER = ClientAndServer.startClientAndServer();
+ }
+
+
+ @BeforeAll
+ static void startMockServer()
+ {
+ NGINX.waitingFor(new HttpWaitStrategy()).start();
+ }
+
+ @AfterAll
+ static void stopMockServer()
+ {
+ MOCK_SERVER.stop();
+ }
+
+
+ String getNginxIP()
+ {
+ return NGINX.getContainerIpAddress();
+ }
+
+ int getNginxPort()
+ {
+ return NGINX.getMappedPort(80);
+ }
+
+ String getNginxUri()
+ {
+ return "http://" + getNginxIP() + ":" + getNginxPort();
+ }
+
+ int getMockServerPort()
+ {
+ return MOCK_SERVER.getLocalPort();
+ }
+
+ String getMockServerUri()
+ {
+ return "http://localhost:" + getMockServerPort();
+ }
+}