From bd8b8e2274b7f7a5c8a3a6f25c467fdb2493cfb6 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Wed, 6 Sep 2023 03:39:23 +0300 Subject: [PATCH 1/2] [0.7.0-SNAPSHOT] MockServer added --- .github/workflows/publish-release.yml | 2 +- .github/workflows/publish-snapshot.yml | 2 +- .github/workflows/pull-request.yml | 2 +- README.md | 3 +- build.gradle | 1 + cassandra/README.md | 6 +- cockroachdb/README.md | 6 +- common/README.md | 2 +- .../AbstractTestcontainersExtension.java | 8 +- dependencies.gradle | 2 + gradle.properties | 2 +- jdbc/README.md | 2 +- kafka/README.md | 6 +- .../kafka/TestcontainersKafkaExtension.java | 3 - mariadb/README.md | 6 +- mockserver/README.md | 180 ++++++++++++++++++ mockserver/build.gradle | 10 + .../mockserver/ContainerMockserver.java | 13 ++ .../ContainerMockserverConnection.java | 13 ++ .../mockserver/MockserverConnection.java | 46 +++++ .../mockserver/MockserverConnectionImpl.java | 105 ++++++++++ .../mockserver/MockserverMetadata.java | 19 ++ .../mockserver/TestcontainersMockserver.java | 42 ++++ .../TestcontainersMockserverExtension.java | 110 +++++++++++ .../MockserverConnectionAssertsTests.java | 33 ++++ mockserver/src/test/resources/logback.xml | 19 ++ mysql/README.md | 6 +- oracle/README.md | 6 +- postgres/README.md | 6 +- redis/README.md | 6 +- settings.gradle | 1 + 31 files changed, 629 insertions(+), 39 deletions(-) create mode 100644 mockserver/README.md create mode 100644 mockserver/build.gradle create mode 100644 mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/ContainerMockserver.java create mode 100644 mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/ContainerMockserverConnection.java create mode 100644 mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverConnection.java create mode 100644 mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverConnectionImpl.java create mode 100644 mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverMetadata.java create mode 100644 mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/TestcontainersMockserver.java create mode 100644 mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/TestcontainersMockserverExtension.java create mode 100644 mockserver/src/test/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverConnectionAssertsTests.java create mode 100644 mockserver/src/test/resources/logback.xml diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 6916ab0..ff47994 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -1,4 +1,4 @@ -name: Release +name: CI Master on: release: diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml index 6c7c592..e333ebc 100644 --- a/.github/workflows/publish-snapshot.yml +++ b/.github/workflows/publish-snapshot.yml @@ -1,4 +1,4 @@ -name: Publish Snapshot +name: CI Dev on: push: diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 40d331e..b463044 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,4 +1,4 @@ -name: Pull Request +name: CI Pull Request on: pull_request: diff --git a/README.md b/README.md index 5bcf4de..d5bccd4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-postgres/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-postgres) -[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=workflow%3A%22Release%22) +[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/CI%20Master/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=CI+Master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) @@ -20,3 +20,4 @@ Makes testing & asserts with Testcontainers even easier. - [Cockroachdb](cockroachdb) - [Cassandra](cassandra) - [Redis](redis) +- [MockServer](mockserver) diff --git a/build.gradle b/build.gradle index d8eaaba..c775844 100644 --- a/build.gradle +++ b/build.gradle @@ -8,6 +8,7 @@ plugins { id "base" id "jacoco" id "jacoco-report-aggregation" + id "org.sonarqube" version "4.2.1.3168" id "io.github.gradle-nexus.publish-plugin" version "1.3.0" } diff --git a/cassandra/README.md b/cassandra/README.md index 8e642fe..3a80b42 100644 --- a/cassandra/README.md +++ b/cassandra/README.md @@ -2,7 +2,7 @@ [![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-cassandra/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-cassandra) -[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=workflow%3A%22Java+CI%22) +[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=CI+Master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) @@ -18,7 +18,7 @@ Features: **Gradle** ```groovy -testImplementation "io.goodforgod:testcontainers-extensions-cassandra:0.6.2" +testImplementation "io.goodforgod:testcontainers-extensions-cassandra:0.7.0" ``` **Maven** @@ -26,7 +26,7 @@ testImplementation "io.goodforgod:testcontainers-extensions-cassandra:0.6.2" io.goodforgod testcontainers-extensions-cassandra - 0.6.2 + 0.7.0 test ``` diff --git a/cockroachdb/README.md b/cockroachdb/README.md index 562fdb7..02ec3c7 100644 --- a/cockroachdb/README.md +++ b/cockroachdb/README.md @@ -2,7 +2,7 @@ [![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-cockroachdb/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-cockroachdb) -[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=workflow%3A%22Java+CI%22) +[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=CI+Master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) @@ -18,7 +18,7 @@ Features: **Gradle** ```groovy -testImplementation "io.goodforgod:testcontainers-extensions-cockroachdb:0.6.2" +testImplementation "io.goodforgod:testcontainers-extensions-cockroachdb:0.7.0" ``` **Maven** @@ -26,7 +26,7 @@ testImplementation "io.goodforgod:testcontainers-extensions-cockroachdb:0.6.2" io.goodforgod testcontainers-extensions-cockroachdb - 0.6.2 + 0.7.0 test ``` diff --git a/common/README.md b/common/README.md index b845770..c9a68f3 100644 --- a/common/README.md +++ b/common/README.md @@ -2,7 +2,7 @@ [![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-common/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-common) -[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=workflow%3A%22Java+CI%22) +[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=CI+Master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) diff --git a/common/src/main/java/io/goodforgod/testcontainers/extensions/AbstractTestcontainersExtension.java b/common/src/main/java/io/goodforgod/testcontainers/extensions/AbstractTestcontainersExtension.java index 544f697..fed078f 100644 --- a/common/src/main/java/io/goodforgod/testcontainers/extensions/AbstractTestcontainersExtension.java +++ b/common/src/main/java/io/goodforgod/testcontainers/extensions/AbstractTestcontainersExtension.java @@ -255,7 +255,7 @@ private void setupBeforeAll(ExtensionContext context) { var metadata = getMetadata(context); if (metadata.runMode() == ContainerMode.PER_RUN) { var storage = getStorage(context); - var storageConnection = storage.get(getConnectionType(), getConnectionType()); + var storageConnection = getConnectionCurrent(context); if (storageConnection == null) { var containerFromField = getContainerFromField(context); var imageShared = containerFromField @@ -353,8 +353,7 @@ public void beforeAll(ExtensionContext context) { var metadata = getMetadata(context); if (metadata.runMode() == ContainerMode.PER_RUN || metadata.runMode() == ContainerMode.PER_CLASS) { - var storage = getStorage(context); - var connection = storage.get(getConnectionType(), getConnectionType()); + var connection = getConnectionCurrent(context); if (connection != null) { injectConnection(connection, context); } @@ -365,8 +364,7 @@ public void beforeAll(ExtensionContext context) { public void beforeEach(ExtensionContext context) { setupBeforeEach(context); - var storage = getStorage(context); - var connection = storage.get(getConnectionType(), getConnectionType()); + var connection = getConnectionCurrent(context); if (connection != null) { injectConnection(connection, context); } diff --git a/dependencies.gradle b/dependencies.gradle index e7da8c7..901f907 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -28,6 +28,7 @@ dependencyResolutionManagement { DependencyResolutionManagement it -> library("testcontainers-cockroach", "org.testcontainers", "cockroachdb").versionRef("testcontainers") library("testcontainers-kafka", "org.testcontainers", "kafka").versionRef("testcontainers") library("testcontainers-cassandra", "org.testcontainers", "cassandra").versionRef("testcontainers") + library("testcontainers-mockserver", "org.testcontainers", "mockserver").versionRef("testcontainers") library("flyway-core", "org.flywaydb", "flyway-core").versionRef("flyway") library("flyway-mysql", "org.flywaydb", "flyway-mysql").versionRef("flyway") @@ -42,6 +43,7 @@ dependencyResolutionManagement { DependencyResolutionManagement it -> library("driver-cassandra", "com.datastax.oss", "java-driver-core").version("4.17.0") library("driver-kafka", "org.apache.kafka", "kafka-clients").version("3.5.1") library("driver-redis", "redis.clients", "jedis").version("4.4.3") + library("driver-mockserver", "org.mock-server", "mockserver-client-java").version("5.15.0") library("json", "org.json", "json").version("20230618") } diff --git a/gradle.properties b/gradle.properties index acc0749..64470b1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ groupId=io.goodforgod artifactRootId=testcontainers-extensions -artifactVersion=0.6.2-SNAPSHOT +artifactVersion=0.7.0-SNAPSHOT ##### GRADLE ##### diff --git a/jdbc/README.md b/jdbc/README.md index 3f85b2b..57c1602 100644 --- a/jdbc/README.md +++ b/jdbc/README.md @@ -2,7 +2,7 @@ [![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-jdbc/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-jdbc) -[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=workflow%3A%22Java+CI%22) +[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=CI+Master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) diff --git a/kafka/README.md b/kafka/README.md index c75eb6b..633c90e 100644 --- a/kafka/README.md +++ b/kafka/README.md @@ -2,7 +2,7 @@ [![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-kafka/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-kafka) -[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=workflow%3A%22Java+CI%22) +[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=CI+Master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) @@ -18,7 +18,7 @@ Features: **Gradle** ```groovy -testImplementation "io.goodforgod:testcontainers-extensions-kafka:0.6.2" +testImplementation "io.goodforgod:testcontainers-extensions-kafka:0.7.0" ``` **Maven** @@ -26,7 +26,7 @@ testImplementation "io.goodforgod:testcontainers-extensions-kafka:0.6.2" io.goodforgod testcontainers-extensions-kafka - 0.6.2 + 0.7.0 test ``` diff --git a/kafka/src/main/java/io/goodforgod/testcontainers/extensions/kafka/TestcontainersKafkaExtension.java b/kafka/src/main/java/io/goodforgod/testcontainers/extensions/kafka/TestcontainersKafkaExtension.java index e6dfcc0..dca8d2f 100644 --- a/kafka/src/main/java/io/goodforgod/testcontainers/extensions/kafka/TestcontainersKafkaExtension.java +++ b/kafka/src/main/java/io/goodforgod/testcontainers/extensions/kafka/TestcontainersKafkaExtension.java @@ -19,7 +19,6 @@ import org.testcontainers.containers.KafkaContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.output.Slf4jLogConsumer; -import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.utility.DockerImageName; @Internal @@ -62,14 +61,12 @@ protected KafkaContainer getContainerDefault(KafkaMetadata metadata) { .withMdc("image", metadata.image()) .withMdc("alias", metadata.networkAliasOrDefault())) .withEnv("KAFKA_CONFLUENT_SUPPORT_METRICS_ENABLE", "false") - .withEnv("AUTO_CREATE_TOPICS", "true") .withEnv("KAFKA_LOG4J_LOGGERS", "org.apache.zookeeper=ERROR,org.kafka.zookeeper=ERROR,kafka.zookeeper=ERROR,org.apache.kafka=ERROR,kafka=ERROR,kafka.network=ERROR,kafka.cluster=ERROR,kafka.controller=ERROR,kafka.coordinator=INFO,kafka.log=ERROR,kafka.server=ERROR,state.change.logger=ERROR") .withEnv("ZOOKEEPER_LOG4J_LOGGERS", "org.apache.zookeeper=ERROR,org.kafka.zookeeper=ERROR,org.kafka.zookeeper.server=ERROR,kafka.zookeeper=ERROR,org.apache.kafka=ERROR") .withEmbeddedZookeeper() .withExposedPorts(9092, KafkaContainer.KAFKA_PORT) - .waitingFor(Wait.forListeningPort()) .withStartupTimeout(Duration.ofMinutes(5)); container.setNetworkAliases(new ArrayList<>(List.of(metadata.networkAliasOrDefault()))); diff --git a/mariadb/README.md b/mariadb/README.md index aa34e18..60ce8ae 100644 --- a/mariadb/README.md +++ b/mariadb/README.md @@ -2,7 +2,7 @@ [![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-mariadb/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-mariadb) -[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=workflow%3A%22Java+CI%22) +[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=CI+Master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) @@ -18,7 +18,7 @@ Features: **Gradle** ```groovy -testImplementation "io.goodforgod:testcontainers-extensions-mariadb:0.6.2" +testImplementation "io.goodforgod:testcontainers-extensions-mariadb:0.7.0" ``` **Maven** @@ -26,7 +26,7 @@ testImplementation "io.goodforgod:testcontainers-extensions-mariadb:0.6.2" io.goodforgod testcontainers-extensions-mariadb - 0.6.2 + 0.7.0 test ``` diff --git a/mockserver/README.md b/mockserver/README.md new file mode 100644 index 0000000..d7e40d3 --- /dev/null +++ b/mockserver/README.md @@ -0,0 +1,180 @@ +# Testcontainers Extensions MockServer + +[![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/) +[![Maven Central](https://maven-badges.herokuRpp.com/maven-central/io.goodforgod/testcontainers-extensions-mockserver/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-mockserver) +[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=CI+Master) +[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) +[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) +[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) + +Testcontainers MockServer Extension with advanced testing capabilities. + +Features: +- Container easy run *per method*, *per class*, *per execution*. +- Container easy connection injection with asserts. + +## Dependency :rocket: + +**Gradle** +```groovy +testImplementation "io.goodforgod:testcontainers-extensions-mockserver:0.7.0" +``` + +**Maven** +```xml + + io.goodforgod + testcontainers-extensions-mockserver + 0.7.0 + test + +``` + +## Content +- [Container](#container) + - [Manual Container](#manual-container) +- [Connection](#connection) + - [External Connection](#external-connection) +- [Migration](#migration) + +## Container + +`@TestcontainersMockserver` - allow **automatically start container** with specified image in different modes without the need to configure it. + +Available containers modes: + +- `PER_RUN` - start container one time per *test execution*. (Containers must have same `image` and `network` to be reused between test classes) +- `PER_CLASS` - start new container each *test class*. +- `PER_METHOD` - start new container each *test method*. + +Simple example on how to start container per class, **no need to configure** container: +```java +@TestcontainersMockserver(mode = ContainerMode.PER_CLASS) +class ExampleTests { + + @Test + void test(@ContainerMockserverConnection MockserverConnection connection) { + assertNotNull(connection); + } +} +``` + +**That's all** you need. + +It is possible to customize image with annotation `image` parameter. + +Image also can be provided from environment variable: +```java +@TestcontainersMockserver(image = "${MY_IMAGE_ENV|mockserver/mockserver:5.15.0}") +class ExampleTests { + + @Test + void test() { + // test + } +} +``` + +Image syntax: + +- Image can have static value: `mockserver/mockserver:5.15.0` +- Image can be provided via environment variable using syntax: `${MY_IMAGE_ENV}` +- Image environment variable can have default value if empty using syntax: `${MY_IMAGE_ENV|mockserver/mockserver:5.15.0}` + +### Manual Container + +When you need to **manually configure container** with specific options, you can provide such container as instance that will be used by `@TestcontainersMockserver`, +this can be done using `@ContainerMockserver` annotation for container. + +Example: +```java +@TestcontainersMockserver(mode = ContainerMode.PER_CLASS) +class ExampleTests { + + @ContainerMockserver + private static final MockServerContainer container = new MockServerContainer() + .withNetworkAliases("mymockserver") + .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(MockServerContainer.class))) + .withNetwork(Network.SHARED); + + @Test + void test(@ContainerMockserverConnection MockserverConnection connection) { + assertEquals("mymockserver", connection.paramsInNetwork().get().host()); + } +} +``` + +### Network + +In case you want to enable [Network.SHARED](https://java.testcontainers.org/features/networking/) for containers you can do this using `network` & `shared` parameter in annotation: +```java +@TestcontainersMockserver(network = @Network(shared = true)) +class ExampleTests { + + @Test + void test() { + // test + } +} +``` + +`Default alias` will be created by default, even if nothing was specified (depends on implementation). + +You can provide also custom alias for container. +Alias can be extracted from environment variable also or default value can be provided if environment is missing. + +In case specified environment variable is missing `default alias` will be created: +```java +@TestcontainersMockserver(network = @Network(alias = "${MY_ALIAS_ENV|my_default_alias}")) +class ExampleTests { + + @Test + void test() { + // test + } +} +``` + +Image syntax: + +- Image can have static value: `my-alias` +- Image can be provided via environment variable using syntax: `${MY_ALIAS_ENV}` +- Image environment variable can have default value if empty using syntax: `${MY_ALIAS_ENV|my-alias-default}` + +## Connection + +`MockserverConnection` - can be injected to field or method parameter and used to communicate with running container via `@ContainerMockserverConnection` annotation. +`MockserverConnection` provides connection parameters, useful asserts, checks, etc. for easier testing. + +Example: +```java +@TestcontainersMockserver(mode = ContainerMode.PER_CLASS, image = "mockserver/mockserver:5.15.0") +class ExampleTests { + + @ContainerMockserverConnection + private MockserverConnection connectionInField; + + @Test + void test(@ContainerMockserverConnection MockserverConnection connection) { + connection.client().when(HttpRequest.request() + .withMethod("GET") + .withPath("/get")) + .respond(HttpResponse.response() + .withStatusCode(200) + .withBody("OK")); + } +} +``` + +### External Connection + +In case you want to use some external Mockserver instance that is running in CI or other place for tests (due to docker limitations or other), +you can use special *environment variables* and extension will use them to propagate connection and no Mockserver containers will be running in such case. + +Special environment variables: +- `EXTERNAL_TEST_MOCKSERVER_HOST` - Mockserver instance host. +- `EXTERNAL_TEST_MOCKSERVER_PORT` - Mockserver instance port. + +## License + +This project licensed under the Apache License 2.0 - see the [LICENSE](../LICENSE) file for details. diff --git a/mockserver/build.gradle b/mockserver/build.gradle new file mode 100644 index 0000000..5c31cc9 --- /dev/null +++ b/mockserver/build.gradle @@ -0,0 +1,10 @@ +dependencies { + api project(":common") + api libs.testcontainers.mockserver + api libs.driver.mockserver + api libs.json + + implementation libs.slf4j.api + implementation libs.junit.launcher + implementation libs.junit.api +} \ No newline at end of file diff --git a/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/ContainerMockserver.java b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/ContainerMockserver.java new file mode 100644 index 0000000..4e20c56 --- /dev/null +++ b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/ContainerMockserver.java @@ -0,0 +1,13 @@ +package io.goodforgod.testcontainers.extensions.mockserver; + +import java.lang.annotation.*; +import org.testcontainers.containers.MockServerContainer; + +/** + * Indicates that annotated field containers {@link MockServerContainer} instance + * that should be used by {@link TestcontainersMockserver} rather than creating default container + */ +@Documented +@Target({ ElementType.FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface ContainerMockserver {} diff --git a/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/ContainerMockserverConnection.java b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/ContainerMockserverConnection.java new file mode 100644 index 0000000..1bd4cef --- /dev/null +++ b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/ContainerMockserverConnection.java @@ -0,0 +1,13 @@ +package io.goodforgod.testcontainers.extensions.mockserver; + +import java.lang.annotation.*; + +/** + * Indicates that annotated field or parameter should be injected with {@link MockserverConnection} + * value + * of current active container + */ +@Documented +@Target({ ElementType.FIELD, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface ContainerMockserverConnection {} diff --git a/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverConnection.java b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverConnection.java new file mode 100644 index 0000000..beb2eeb --- /dev/null +++ b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverConnection.java @@ -0,0 +1,46 @@ +package io.goodforgod.testcontainers.extensions.mockserver; + +import java.net.URI; +import java.util.Optional; +import org.jetbrains.annotations.NotNull; +import org.mockserver.client.MockServerClient; + +/** + * Describes active Mockserver connection of currently running + * {@link org.testcontainers.containers.MockServerContainer} + */ +public interface MockserverConnection { + + /** + * Mockserver connection parameters + */ + interface Params { + + @NotNull + URI uri(); + + @NotNull + String host(); + + int port(); + } + + /** + * @return connection parameters to container + */ + @NotNull + Params params(); + + /** + * @return connection parameters inside docker network, can be useful when one container require + * params to connect to Mockserver container inside docker network + */ + @NotNull + Optional paramsInNetwork(); + + /** + * @return MockServer Client + */ + @NotNull + MockServerClient client(); +} diff --git a/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverConnectionImpl.java b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverConnectionImpl.java new file mode 100644 index 0000000..cec967c --- /dev/null +++ b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverConnectionImpl.java @@ -0,0 +1,105 @@ +package io.goodforgod.testcontainers.extensions.mockserver; + +import java.net.URI; +import java.util.Objects; +import java.util.Optional; +import org.jetbrains.annotations.ApiStatus.Internal; +import org.jetbrains.annotations.NotNull; +import org.mockserver.client.MockServerClient; + +@Internal +final class MockserverConnectionImpl implements MockserverConnection { + + private static final class ParamsImpl implements Params { + + private final String host; + private final int port; + + ParamsImpl(String host, int port) { + this.host = host; + this.port = port; + } + + @Override + public @NotNull URI uri() { + return URI.create(String.format("http://%s:%d", host, port)); + } + + @Override + public @NotNull String host() { + return host; + } + + @Override + public int port() { + return port; + } + + @Override + public String toString() { + return uri().toString(); + } + } + + private final Params params; + private final Params network; + private final MockServerClient client; + + MockserverConnectionImpl(Params params, Params network) { + this.params = params; + this.network = network; + this.client = new MockServerClient(params.host(), params.port()); + } + + static MockserverConnection forContainer(String host, int port, String hostInNetwork, Integer portInNetwork) { + var params = new ParamsImpl(host, port); + final Params network; + if (hostInNetwork == null) { + network = null; + } else { + network = new ParamsImpl(hostInNetwork, portInNetwork); + } + + return new MockserverConnectionImpl(params, network); + } + + static MockserverConnection forExternal(String host, int port) { + var params = new ParamsImpl(host, port); + return new MockserverConnectionImpl(params, null); + } + + @Override + public @NotNull Params params() { + return params; + } + + @Override + public @NotNull Optional paramsInNetwork() { + return Optional.ofNullable(network); + } + + @Override + public @NotNull MockServerClient client() { + return client; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + MockserverConnectionImpl that = (MockserverConnectionImpl) o; + return Objects.equals(params, that.params) && Objects.equals(network, that.network); + } + + @Override + public int hashCode() { + return Objects.hash(params, network); + } + + @Override + public String toString() { + return params().toString(); + } +} diff --git a/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverMetadata.java b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverMetadata.java new file mode 100644 index 0000000..9e43989 --- /dev/null +++ b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverMetadata.java @@ -0,0 +1,19 @@ +package io.goodforgod.testcontainers.extensions.mockserver; + +import io.goodforgod.testcontainers.extensions.AbstractContainerMetadata; +import io.goodforgod.testcontainers.extensions.ContainerMode; +import org.jetbrains.annotations.ApiStatus.Internal; +import org.jetbrains.annotations.NotNull; + +@Internal +final class MockserverMetadata extends AbstractContainerMetadata { + + MockserverMetadata(boolean network, String alias, String image, ContainerMode runMode) { + super(network, alias, image, runMode); + } + + @Override + public @NotNull String networkAliasDefault() { + return "mockserver-" + System.currentTimeMillis(); + } +} diff --git a/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/TestcontainersMockserver.java b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/TestcontainersMockserver.java new file mode 100644 index 0000000..bee2807 --- /dev/null +++ b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/TestcontainersMockserver.java @@ -0,0 +1,42 @@ +package io.goodforgod.testcontainers.extensions.mockserver; + +import io.goodforgod.testcontainers.extensions.ContainerMode; +import io.goodforgod.testcontainers.extensions.Network; +import java.lang.annotation.*; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.extension.ExtendWith; +import org.testcontainers.containers.MockServerContainer; + +/** + * Extension that is running {@link MockServerContainer} for tests in different modes with database + * schema migration support between test executions + */ +@Order(Order.DEFAULT - 100) // Run before other extensions +@ExtendWith(TestcontainersMockserverExtension.class) +@Documented +@Target({ ElementType.TYPE }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestcontainersMockserver { + + /** + * @see TestcontainersMockserverExtension#getContainerDefault(MockserverMetadata) + * @return Mockserver image + *

+ * 1) Image can have static value: "mockserver/mockserver:5.15.0" + * 2) Image can be provided via environment variable using syntax: "${MY_IMAGE_ENV}" + * 3) Image environment variable can have default value if empty using syntax: + * "${MY_IMAGE_ENV|mockserver/mockserver:5.15.0}" + *

+ */ + String image() default "mockserver/mockserver:5.15.0"; + + /** + * @return when to start container + */ + ContainerMode mode() default ContainerMode.PER_METHOD; + + /** + * @return container network details + */ + Network network() default @Network(shared = false); +} diff --git a/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/TestcontainersMockserverExtension.java b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/TestcontainersMockserverExtension.java new file mode 100644 index 0000000..0dc7c2b --- /dev/null +++ b/mockserver/src/main/java/io/goodforgod/testcontainers/extensions/mockserver/TestcontainersMockserverExtension.java @@ -0,0 +1,110 @@ +package io.goodforgod.testcontainers.extensions.mockserver; + +import io.goodforgod.testcontainers.extensions.AbstractTestcontainersExtension; +import java.lang.annotation.Annotation; +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.jetbrains.annotations.ApiStatus.Internal; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.MockServerContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; + +@Internal +class TestcontainersMockserverExtension extends + AbstractTestcontainersExtension { + + private static final String EXTERNAL_TEST_MOCKSERVER_HOST = "EXTERNAL_TEST_MOCKSERVER_HOST"; + private static final String EXTERNAL_TEST_MOCKSERVER_PORT = "EXTERNAL_TEST_MOCKSERVER_PORT"; + + private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace + .create(TestcontainersMockserverExtension.class); + + protected Class getContainerType() { + return MockServerContainer.class; + } + + protected Class getContainerAnnotation() { + return ContainerMockserver.class; + } + + protected Class getConnectionAnnotation() { + return ContainerMockserverConnection.class; + } + + @Override + protected Class getConnectionType() { + return MockserverConnection.class; + } + + @Override + protected MockServerContainer getContainerDefault(MockserverMetadata metadata) { + var dockerImage = DockerImageName.parse(metadata.image()) + .asCompatibleSubstituteFor(DockerImageName.parse("mockserver/mockserver")); + + var container = new MockServerContainer(dockerImage) + .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(MockServerContainer.class)) + .withMdc("image", metadata.image()) + .withMdc("alias", metadata.networkAliasOrDefault())) + .waitingFor(Wait.forListeningPort()) + .withStartupTimeout(Duration.ofMinutes(5)); + + container.setNetworkAliases(new ArrayList<>(List.of(metadata.networkAliasOrDefault()))); + if (metadata.networkShared()) { + container.withNetwork(Network.SHARED); + } + + return container; + } + + @Override + protected ExtensionContext.Namespace getNamespace() { + return NAMESPACE; + } + + @NotNull + protected Optional findMetadata(@NotNull ExtensionContext context) { + return findAnnotation(TestcontainersMockserver.class, context) + .map(a -> new MockserverMetadata(a.network().shared(), a.network().alias(), a.image(), a.mode())); + } + + @NotNull + protected MockserverConnection getConnectionForContainer(MockserverMetadata metadata, + @NotNull MockServerContainer container) { + final String alias = container.getNetworkAliases().stream() + .filter(a -> a.equals(metadata.networkAliasOrDefault())) + .findFirst() + .or(() -> container.getNetworkAliases().stream().findFirst()) + .orElse(null); + + return MockserverConnectionImpl.forContainer(container.getHost(), + container.getMappedPort(MockServerContainer.PORT), + alias, + MockServerContainer.PORT); + } + + @NotNull + protected Optional getConnectionExternal() { + var host = System.getenv(EXTERNAL_TEST_MOCKSERVER_HOST); + var port = System.getenv(EXTERNAL_TEST_MOCKSERVER_PORT); + + if (host != null && port != null) { + return Optional.of(MockserverConnectionImpl.forExternal(host, Integer.parseInt(port))); + } else + return Optional.empty(); + } + + @Override + public void afterEach(ExtensionContext context) { + super.afterEach(context); + + var connection = getConnectionCurrent(context); + connection.client().reset(); + } +} diff --git a/mockserver/src/test/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverConnectionAssertsTests.java b/mockserver/src/test/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverConnectionAssertsTests.java new file mode 100644 index 0000000..28ea1d6 --- /dev/null +++ b/mockserver/src/test/java/io/goodforgod/testcontainers/extensions/mockserver/MockserverConnectionAssertsTests.java @@ -0,0 +1,33 @@ +package io.goodforgod.testcontainers.extensions.mockserver; + +import io.goodforgod.testcontainers.extensions.ContainerMode; +import org.junit.jupiter.api.Test; +import org.mockserver.model.HttpRequest; +import org.mockserver.model.HttpResponse; + +@TestcontainersMockserver(mode = ContainerMode.PER_CLASS) +class MockserverConnectionAssertsTests { + + @ContainerMockserverConnection + private MockserverConnection connection; + + @Test + void assertCountsAtLeastWhenEquals() { + connection.client().when(HttpRequest.request() + .withMethod("GET") + .withPath("/get")) + .respond(HttpResponse.response() + .withStatusCode(200) + .withBody("OK")); + } + + @Test + void assertCountsExactWhenZero() { + connection.client().when(HttpRequest.request() + .withMethod("GET") + .withPath("/get")) + .respond(HttpResponse.response() + .withStatusCode(200) + .withBody("OK")); + } +} diff --git a/mockserver/src/test/resources/logback.xml b/mockserver/src/test/resources/logback.xml new file mode 100644 index 0000000..4585197 --- /dev/null +++ b/mockserver/src/test/resources/logback.xml @@ -0,0 +1,19 @@ + + + + UTF-8 + %cyan(%d{HH:mm:ss.SSS}) [%cn] %highlight(%-5level) %logger{36} - %msg%n + + + + + + + + + + + + + + diff --git a/mysql/README.md b/mysql/README.md index 4c9ad40..1c9d331 100644 --- a/mysql/README.md +++ b/mysql/README.md @@ -2,7 +2,7 @@ [![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-mysql/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-mysql) -[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=workflow%3A%22Java+CI%22) +[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=CI+Master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) @@ -18,7 +18,7 @@ Features: **Gradle** ```groovy -testImplementation "io.goodforgod:testcontainers-extensions-mysql:0.6.2" +testImplementation "io.goodforgod:testcontainers-extensions-mysql:0.7.0" ``` **Maven** @@ -26,7 +26,7 @@ testImplementation "io.goodforgod:testcontainers-extensions-mysql:0.6.2" io.goodforgod testcontainers-extensions-mysql - 0.6.2 + 0.7.0 test ``` diff --git a/oracle/README.md b/oracle/README.md index 614f395..836a045 100644 --- a/oracle/README.md +++ b/oracle/README.md @@ -2,7 +2,7 @@ [![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-oracle/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-oracle) -[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=workflow%3A%22Java+CI%22) +[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=CI+Master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) @@ -18,7 +18,7 @@ Features: **Gradle** ```groovy -testImplementation "io.goodforgod:testcontainers-extensions-oracle:0.6.2" +testImplementation "io.goodforgod:testcontainers-extensions-oracle:0.7.0" ``` **Maven** @@ -26,7 +26,7 @@ testImplementation "io.goodforgod:testcontainers-extensions-oracle:0.6.2" io.goodforgod testcontainers-extensions-oracle - 0.6.2 + 0.7.0 test ``` diff --git a/postgres/README.md b/postgres/README.md index 78fe4be..cf2dec0 100644 --- a/postgres/README.md +++ b/postgres/README.md @@ -2,7 +2,7 @@ [![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-postgres/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-postgres) -[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=workflow%3A%22Java+CI%22) +[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=CI+Master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) @@ -18,7 +18,7 @@ Features: **Gradle** ```groovy -testImplementation "io.goodforgod:testcontainers-extensions-postgres:0.6.2" +testImplementation "io.goodforgod:testcontainers-extensions-postgres:0.7.0" ``` **Maven** @@ -26,7 +26,7 @@ testImplementation "io.goodforgod:testcontainers-extensions-postgres:0.6.2" io.goodforgod testcontainers-extensions-postgres - 0.6.2 + 0.7.0 test ``` diff --git a/redis/README.md b/redis/README.md index 29b2a88..5044076 100644 --- a/redis/README.md +++ b/redis/README.md @@ -2,7 +2,7 @@ [![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-redis/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/testcontainers-extensions-redis) -[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=workflow%3A%22Java+CI%22) +[![GitHub Action](https://github.com/goodforgod/testcontainers-extensions/workflows/Release/badge.svg)](https://github.com/GoodforGod/testcontainers-extensions/actions?query=CI+Master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_testcontainers-extensions&metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_testcontainers-extensions) @@ -17,7 +17,7 @@ Features: **Gradle** ```groovy -testImplementation "io.goodforgod:testcontainers-extensions-redis:0.6.2" +testImplementation "io.goodforgod:testcontainers-extensions-redis:0.7.0" ``` **Maven** @@ -25,7 +25,7 @@ testImplementation "io.goodforgod:testcontainers-extensions-redis:0.6.2" io.goodforgod testcontainers-extensions-redis - 0.6.2 + 0.7.0 test ``` diff --git a/settings.gradle b/settings.gradle index fa37516..2ab1a63 100644 --- a/settings.gradle +++ b/settings.gradle @@ -18,4 +18,5 @@ include "cockroachdb" include "kafka" include "cassandra" include "redis" +include "mockserver" From b014ebd3cbbc8d29fbb6c432e64905cfae1285ab Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Wed, 6 Sep 2023 03:48:51 +0300 Subject: [PATCH 2/2] [0.7.0-SNAPSHOT] TestcontainersKafkaExtension updated --- .../extensions/kafka/TestcontainersKafkaExtension.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kafka/src/main/java/io/goodforgod/testcontainers/extensions/kafka/TestcontainersKafkaExtension.java b/kafka/src/main/java/io/goodforgod/testcontainers/extensions/kafka/TestcontainersKafkaExtension.java index dca8d2f..e6dfcc0 100644 --- a/kafka/src/main/java/io/goodforgod/testcontainers/extensions/kafka/TestcontainersKafkaExtension.java +++ b/kafka/src/main/java/io/goodforgod/testcontainers/extensions/kafka/TestcontainersKafkaExtension.java @@ -19,6 +19,7 @@ import org.testcontainers.containers.KafkaContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.utility.DockerImageName; @Internal @@ -61,12 +62,14 @@ protected KafkaContainer getContainerDefault(KafkaMetadata metadata) { .withMdc("image", metadata.image()) .withMdc("alias", metadata.networkAliasOrDefault())) .withEnv("KAFKA_CONFLUENT_SUPPORT_METRICS_ENABLE", "false") + .withEnv("AUTO_CREATE_TOPICS", "true") .withEnv("KAFKA_LOG4J_LOGGERS", "org.apache.zookeeper=ERROR,org.kafka.zookeeper=ERROR,kafka.zookeeper=ERROR,org.apache.kafka=ERROR,kafka=ERROR,kafka.network=ERROR,kafka.cluster=ERROR,kafka.controller=ERROR,kafka.coordinator=INFO,kafka.log=ERROR,kafka.server=ERROR,state.change.logger=ERROR") .withEnv("ZOOKEEPER_LOG4J_LOGGERS", "org.apache.zookeeper=ERROR,org.kafka.zookeeper=ERROR,org.kafka.zookeeper.server=ERROR,kafka.zookeeper=ERROR,org.apache.kafka=ERROR") .withEmbeddedZookeeper() .withExposedPorts(9092, KafkaContainer.KAFKA_PORT) + .waitingFor(Wait.forListeningPort()) .withStartupTimeout(Duration.ofMinutes(5)); container.setNetworkAliases(new ArrayList<>(List.of(metadata.networkAliasOrDefault())));