Implemented a narrow integration-test: DemoApplicationIT
[demos/testing] / src / test / java / de / juplo / demo / IntegrationTestBase.java
diff --git a/src/test/java/de/juplo/demo/IntegrationTestBase.java b/src/test/java/de/juplo/demo/IntegrationTestBase.java
new file mode 100644 (file)
index 0000000..2135a6d
--- /dev/null
@@ -0,0 +1,51 @@
+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();
+  }
+}