├── testprojects ├── minio │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ └── kotlin │ │ │ │ └── io │ │ │ │ └── cloudflight │ │ │ │ └── testresources │ │ │ │ └── springboot │ │ │ │ └── minio │ │ │ │ └── Application.kt │ │ └── test │ │ │ └── kotlin │ │ │ └── io │ │ │ └── cloudflight │ │ │ └── testresources │ │ │ └── springboot │ │ │ └── minio │ │ │ └── ApplicationTest.kt │ └── build.gradle.kts ├── jdbc │ ├── mssql │ │ ├── src │ │ │ ├── main │ │ │ │ ├── resources │ │ │ │ │ └── application.yml │ │ │ │ └── kotlin │ │ │ │ │ └── io │ │ │ │ │ └── cloudflight │ │ │ │ │ └── testresources │ │ │ │ │ └── springboot │ │ │ │ │ └── jdbc │ │ │ │ │ └── mssql │ │ │ │ │ └── Application.kt │ │ │ └── test │ │ │ │ └── kotlin │ │ │ │ └── io │ │ │ │ └── cloudflight │ │ │ │ └── testresources │ │ │ │ └── springboot │ │ │ │ └── jdbc │ │ │ │ └── mssql │ │ │ │ └── ApplicationTest.kt │ │ └── build.gradle.kts │ ├── mariadb │ │ ├── src │ │ │ ├── main │ │ │ │ ├── resources │ │ │ │ │ └── application.yml │ │ │ │ └── kotlin │ │ │ │ │ └── io │ │ │ │ │ └── cloudflight │ │ │ │ │ └── testresources │ │ │ │ │ └── springboot │ │ │ │ │ └── jdbc │ │ │ │ │ └── mariadb │ │ │ │ │ └── Application.kt │ │ │ └── test │ │ │ │ └── kotlin │ │ │ │ └── io │ │ │ │ └── cloudflight │ │ │ │ └── testresources │ │ │ │ └── springboot │ │ │ │ └── jdbc │ │ │ │ └── mariadb │ │ │ │ └── ApplicationTest.kt │ │ └── build.gradle.kts │ └── postgres │ │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ └── kotlin │ │ │ │ └── io │ │ │ │ └── cloudflight │ │ │ │ └── testresources │ │ │ │ └── springboot │ │ │ │ └── jdbc │ │ │ │ └── postgres │ │ │ │ └── Application.kt │ │ └── test │ │ │ └── kotlin │ │ │ └── io │ │ │ └── cloudflight │ │ │ └── testresources │ │ │ └── springboot │ │ │ └── jdbc │ │ │ └── postgres │ │ │ └── ApplicationTest.kt │ │ └── build.gradle.kts ├── build.gradle.kts ├── redis │ ├── src │ │ ├── main │ │ │ └── kotlin │ │ │ │ └── io │ │ │ │ └── cloudflight │ │ │ │ └── testresources │ │ │ │ └── springboot │ │ │ │ └── redis │ │ │ │ └── Application.kt │ │ └── test │ │ │ └── kotlin │ │ │ └── io │ │ │ └── cloudflight │ │ │ └── testresources │ │ │ └── springboot │ │ │ └── redis │ │ │ └── ApplicationTest.kt │ └── build.gradle.kts ├── mailhog │ ├── src │ │ ├── main │ │ │ └── kotlin │ │ │ │ └── io │ │ │ │ └── cloudflight │ │ │ │ └── testresources │ │ │ │ └── springboot │ │ │ │ └── mailhog │ │ │ │ └── Application.kt │ │ └── test │ │ │ └── kotlin │ │ │ └── io │ │ │ └── cloudflight │ │ │ └── testresources │ │ │ └── springboot │ │ │ └── mailhog │ │ │ └── ApplicationTest.kt │ └── build.gradle.kts ├── azurite │ ├── src │ │ ├── main │ │ │ ├── kotlin │ │ │ │ └── io │ │ │ │ │ └── cloudflight │ │ │ │ │ └── testresources │ │ │ │ │ └── springboot │ │ │ │ │ └── azurite │ │ │ │ │ └── Application.kt │ │ │ └── resources │ │ │ │ └── application.yaml │ │ └── test │ │ │ └── kotlin │ │ │ └── io │ │ │ └── cloudflight │ │ │ └── testresources │ │ │ └── springboot │ │ │ └── azurite │ │ │ └── ApplicationTest.kt │ └── build.gradle.kts ├── rabbitmq │ ├── build.gradle.kts │ └── src │ │ ├── test │ │ └── kotlin │ │ │ └── io │ │ │ └── cloudflight │ │ │ └── testresources │ │ │ └── springboot │ │ │ └── rabbitmq │ │ │ └── ApplicationTest.kt │ │ └── main │ │ └── kotlin │ │ └── io │ │ └── cloudflight │ │ └── testresources │ │ └── springboot │ │ └── rabbitmq │ │ └── Application.kt └── elasticsearch │ ├── build.gradle.kts │ └── src │ ├── main │ └── kotlin │ │ └── io │ │ └── cloudflight │ │ └── testresources │ │ └── springboot │ │ └── elasticsearch │ │ └── Application.kt │ └── test │ └── kotlin │ └── io │ └── cloudflight │ └── testresources │ └── springboot │ └── elasticsearch │ └── ApplicationTest.kt ├── gradle.properties ├── springboot-testresources-azurite ├── build.gradle.kts └── src │ └── main │ ├── resources │ └── META-INF │ │ └── services │ │ └── io.micronaut.testresources.core.TestResourcesResolver │ └── java │ └── io │ └── cloudflight │ └── testresources │ └── springboot │ └── azurite │ └── AzuriteTestResourceProvider.java ├── springboot-testresources-redis ├── build.gradle.kts └── src │ └── main │ ├── resources │ └── META-INF │ │ └── services │ │ └── io.micronaut.testresources.core.TestResourcesResolver │ └── java │ └── io │ └── cloudflight │ └── testresources │ └── springboot │ └── redis │ └── RedisTestResourceProvider.java ├── springboot-testresources-mailhog ├── build.gradle.kts └── src │ └── main │ ├── resources │ └── META-INF │ │ └── services │ │ └── io.micronaut.testresources.core.TestResourcesResolver │ └── java │ └── io │ └── cloudflight │ └── testresources │ └── springboot │ └── mailhog │ └── MailhogTestResourceProvider.java ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── libs.versions.toml ├── springboot-testresources-minio ├── build.gradle.kts └── src │ ├── main │ ├── resources │ │ └── META-INF │ │ │ └── services │ │ │ └── io.micronaut.testresources.core.TestResourcesResolver │ └── java │ │ └── io │ │ └── cloudflight │ │ └── testresources │ │ └── springboot │ │ └── minio │ │ └── MinioTestResourcesProvider.java │ └── test │ └── java │ └── io │ └── cloudflight │ └── testresources │ └── springboot │ └── minio │ └── MinioTestResourcesProviderTest.java ├── springboot-testresources-rabbitmq ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── services │ │ │ └── io.micronaut.testresources.core.TestResourcesResolver │ │ └── java │ │ └── io │ │ └── cloudflight │ │ └── testresources │ │ └── springboot │ │ └── rabbitmq │ │ └── RabbitMQTestResourceProvider.java └── build.gradle.kts ├── springboot-testresources-elasticsearch ├── build.gradle.kts └── src │ └── main │ ├── resources │ └── META-INF │ │ └── services │ │ └── io.micronaut.testresources.core.TestResourcesResolver │ └── java │ └── io │ └── cloudflight │ └── testresources │ └── springboot │ └── elasticsearch │ └── ElasticSearchTestResourceProvider.java ├── springboot-testresources-client ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ │ └── java │ │ └── io │ │ └── cloudflight │ │ └── testresources │ │ └── springboot │ │ └── client │ │ ├── micronaut │ │ ├── ConfigFinder.java │ │ └── TestResourcesClientFactory.java │ │ ├── TestResourcesEnvironmentPostProcessor.java │ │ └── TestResourcesPropertySource.java └── build.gradle.kts ├── springboot-testresources-jdbc ├── build.gradle.kts ├── springboot-testresources-jdbc-mariadb │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── META-INF │ │ │ │ │ └── services │ │ │ │ │ └── io.micronaut.testresources.core.TestResourcesResolver │ │ │ └── java │ │ │ │ └── io │ │ │ │ └── cloudflight │ │ │ │ └── testresources │ │ │ │ └── springboot │ │ │ │ └── jdbc │ │ │ │ └── mariadb │ │ │ │ └── MariaDbTestResourcesProvider.java │ │ └── test │ │ │ └── java │ │ │ └── io │ │ │ └── cloudflight │ │ │ └── testresources │ │ │ └── springboot │ │ │ └── jdbc │ │ │ └── mariadb │ │ │ └── MariaDbTestResourcesProviderTest.java │ └── build.gradle.kts ├── springboot-testresources-jdbc-mssql │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── META-INF │ │ │ │ │ └── services │ │ │ │ │ └── io.micronaut.testresources.core.TestResourcesResolver │ │ │ └── java │ │ │ │ └── io │ │ │ │ └── cloudflight │ │ │ │ └── testresources │ │ │ │ └── springboot │ │ │ │ └── jdbc │ │ │ │ └── mssql │ │ │ │ └── MssqlServerTestResourcesProvider.java │ │ └── test │ │ │ └── java │ │ │ └── io │ │ │ └── cloudflight │ │ │ └── testresources │ │ │ └── springboot │ │ │ └── jdbc │ │ │ └── mariadb │ │ │ └── MssqlServerTestResourcesProviderTest.java │ └── build.gradle.kts ├── springboot-testresources-jdbc-postgres │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── services │ │ │ │ └── io.micronaut.testresources.core.TestResourcesResolver │ │ │ └── java │ │ │ └── io │ │ │ └── cloudflight │ │ │ └── testresources │ │ │ └── springboot │ │ │ └── jdbc │ │ │ └── postgres │ │ │ └── PostgresTestResourcesProvider.java │ └── build.gradle.kts └── src │ └── main │ └── java │ └── io │ └── cloudflight │ └── testresources │ └── springboot │ └── jdbc │ └── AbstractJdbcTestResourceProvider.java ├── .gitignore ├── settings.gradle.kts ├── .github └── workflows │ ├── github-build.yml │ └── github-publish.yml ├── gradlew.bat ├── gradlew ├── LICENSE └── README.md /testprojects/minio/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | 3 | micronautVersion=3.8.7 -------------------------------------------------------------------------------- /springboot-testresources-azurite/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Spring Boot TestResourceProvider for Azurite" -------------------------------------------------------------------------------- /springboot-testresources-redis/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Spring Boot TestResourceProvider for Redis" 2 | -------------------------------------------------------------------------------- /springboot-testresources-mailhog/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Spring Boot TestResourceProvider for Mailhog" 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudflightio/springboot-testresources/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /springboot-testresources-minio/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Spring Boot TestResourceProvider for MinIO" 2 | 3 | dependencies { 4 | testImplementation(libs.micronaut.core) 5 | } 6 | -------------------------------------------------------------------------------- /springboot-testresources-minio/src/main/resources/META-INF/services/io.micronaut.testresources.core.TestResourcesResolver: -------------------------------------------------------------------------------- 1 | io.cloudflight.testresources.springboot.minio.MinioTestResourcesProvider -------------------------------------------------------------------------------- /springboot-testresources-redis/src/main/resources/META-INF/services/io.micronaut.testresources.core.TestResourcesResolver: -------------------------------------------------------------------------------- 1 | io.cloudflight.testresources.springboot.redis.RedisTestResourceProvider -------------------------------------------------------------------------------- /springboot-testresources-azurite/src/main/resources/META-INF/services/io.micronaut.testresources.core.TestResourcesResolver: -------------------------------------------------------------------------------- 1 | io.cloudflight.testresources.springboot.azurite.AzuriteTestResourceProvider -------------------------------------------------------------------------------- /springboot-testresources-mailhog/src/main/resources/META-INF/services/io.micronaut.testresources.core.TestResourcesResolver: -------------------------------------------------------------------------------- 1 | io.cloudflight.testresources.springboot.mailhog.MailhogTestResourceProvider 2 | -------------------------------------------------------------------------------- /springboot-testresources-rabbitmq/src/main/resources/META-INF/services/io.micronaut.testresources.core.TestResourcesResolver: -------------------------------------------------------------------------------- 1 | io.cloudflight.testresources.springboot.rabbitmq.RabbitMQTestResourceProvider -------------------------------------------------------------------------------- /springboot-testresources-elasticsearch/build.gradle.kts: -------------------------------------------------------------------------------- 1 | 2 | description = "Spring Boot TestResourceProvider for Elasticsearc" 3 | 4 | dependencies { 5 | implementation(libs.testcontainers.elasticsearch) 6 | } -------------------------------------------------------------------------------- /springboot-testresources-elasticsearch/src/main/resources/META-INF/services/io.micronaut.testresources.core.TestResourcesResolver: -------------------------------------------------------------------------------- 1 | io.cloudflight.testresources.springboot.elasticsearch.ElasticSearchTestResourceProvider -------------------------------------------------------------------------------- /testprojects/jdbc/mssql/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | test-resources: 2 | containers: 3 | mssql: 4 | accept-license: true 5 | 6 | spring: 7 | jpa: 8 | hibernate: 9 | ddl-auto: create-drop -------------------------------------------------------------------------------- /springboot-testresources-client/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.env.EnvironmentPostProcessor=\ 2 | io.cloudflight.testresources.springboot.client.TestResourcesEnvironmentPostProcessor 3 | -------------------------------------------------------------------------------- /testprojects/jdbc/mariadb/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | jpa: 3 | hibernate: 4 | ddl-auto: create-drop 5 | 6 | test-resources: 7 | containers: 8 | mariadb: 9 | image-name: mariadb:10.3 -------------------------------------------------------------------------------- /springboot-testresources-jdbc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Base library for TestProvider libraries based on JDBC" 2 | 3 | dependencies { 4 | implementation(libs.testcontainers.jdbc) 5 | testImplementation(libs.micronaut.core) 6 | } -------------------------------------------------------------------------------- /springboot-testresources-jdbc/springboot-testresources-jdbc-mariadb/src/main/resources/META-INF/services/io.micronaut.testresources.core.TestResourcesResolver: -------------------------------------------------------------------------------- 1 | io.cloudflight.testresources.springboot.jdbc.mariadb.MariaDbTestResourcesProvider -------------------------------------------------------------------------------- /springboot-testresources-jdbc/springboot-testresources-jdbc-mssql/src/main/resources/META-INF/services/io.micronaut.testresources.core.TestResourcesResolver: -------------------------------------------------------------------------------- 1 | io.cloudflight.testresources.springboot.jdbc.mssql.MssqlServerTestResourcesProvider -------------------------------------------------------------------------------- /springboot-testresources-jdbc/springboot-testresources-jdbc-postgres/src/main/resources/META-INF/services/io.micronaut.testresources.core.TestResourcesResolver: -------------------------------------------------------------------------------- 1 | io.cloudflight.testresources.springboot.jdbc.postgres.PostgresTestResourcesProvider -------------------------------------------------------------------------------- /springboot-testresources-rabbitmq/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Spring Boot TestResourceProvider for RabbitMQ" 2 | 3 | dependencies { 4 | implementation(libs.testcontainers.rabbitmq) 5 | testImplementation(libs.micronaut.core) 6 | } 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists -------------------------------------------------------------------------------- /testprojects/build.gradle.kts: -------------------------------------------------------------------------------- 1 | subprojects { 2 | afterEvaluate { 3 | if (this.subprojects.isEmpty()) { 4 | dependencies { 5 | "implementation"(platform(libs.spring.bootbom)) 6 | } 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /testprojects/redis/src/main/kotlin/io/cloudflight/testresources/springboot/redis/Application.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.redis 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication 4 | 5 | @SpringBootApplication 6 | class Application 7 | -------------------------------------------------------------------------------- /springboot-testresources-jdbc/springboot-testresources-jdbc-mariadb/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Spring Boot TestResourceProvider for MariaDB" 2 | 3 | dependencies { 4 | implementation(project(":springboot-testresources-jdbc")) 5 | implementation(libs.testcontainers.mariadb) 6 | } -------------------------------------------------------------------------------- /testprojects/mailhog/src/main/kotlin/io/cloudflight/testresources/springboot/mailhog/Application.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.mailhog 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication 4 | 5 | @SpringBootApplication 6 | class Application 7 | -------------------------------------------------------------------------------- /springboot-testresources-jdbc/springboot-testresources-jdbc-postgres/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Spring Boot TestResourceProvider for Postgres" 2 | 3 | dependencies { 4 | implementation(project(":springboot-testresources-jdbc")) 5 | implementation(libs.testcontainers.postgresql) 6 | } -------------------------------------------------------------------------------- /testprojects/azurite/src/main/kotlin/io/cloudflight/testresources/springboot/azurite/Application.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.azurite 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication 4 | 5 | @SpringBootApplication 6 | class Application 7 | 8 | -------------------------------------------------------------------------------- /springboot-testresources-jdbc/springboot-testresources-jdbc-mssql/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Spring Boot TestResourceProvider for Microsoft SQL Server" 2 | 3 | dependencies { 4 | implementation(project(":springboot-testresources-jdbc")) 5 | implementation(libs.testcontainers.mssqlserver) 6 | } 7 | -------------------------------------------------------------------------------- /testprojects/jdbc/postgres/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | jpa: 3 | hibernate: 4 | ddl-auto: create-drop 5 | database-platform: org.hibernate.dialect.PostgreSQLDialect 6 | 7 | test-resources: 8 | containers: 9 | postgres: 10 | image-name: postgres:16-alpine -------------------------------------------------------------------------------- /springboot-testresources-client/build.gradle.kts: -------------------------------------------------------------------------------- 1 | description = "Client library for Spring Boot integration tests to connect to the TestResources Server" 2 | 3 | dependencies { 4 | implementation(libs.micronaut.testresources.client) 5 | implementation(libs.micronaut.http.client) 6 | 7 | compileOnly(libs.spring.boot) 8 | } -------------------------------------------------------------------------------- /testprojects/azurite/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | azure: 4 | storage: 5 | blob: 6 | enabled: true 7 | compatibility-verifier: 8 | enabled: false # TODO remove as soon as the ms-azurite library is final in version 6.0.0, see https://github.com/Azure/azure-sdk-for-java/wiki/Spring-Versions-Mapping -------------------------------------------------------------------------------- /testprojects/minio/src/main/kotlin/io/cloudflight/testresources/springboot/minio/Application.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.minio 2 | 3 | import org.springframework.beans.factory.annotation.Value 4 | import org.springframework.boot.autoconfigure.SpringBootApplication 5 | import org.springframework.stereotype.Service 6 | 7 | @SpringBootApplication 8 | class Application 9 | 10 | @Service 11 | class StorageService(@Value("\${minio.url}") val url: String) { 12 | 13 | 14 | } -------------------------------------------------------------------------------- /testprojects/minio/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.micronaut.test-resources") 3 | } 4 | 5 | dependencies { 6 | implementation("org.springframework.boot:spring-boot-starter-web") 7 | 8 | testImplementation("org.springframework.boot:spring-boot-starter-test") 9 | 10 | testRuntimeOnly(project(":springboot-testresources-client")) 11 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 12 | testResourcesImplementation(project(":springboot-testresources-minio")) 13 | } -------------------------------------------------------------------------------- /testprojects/redis/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.micronaut.test-resources") 3 | } 4 | 5 | dependencies { 6 | implementation("org.springframework.boot:spring-boot-starter-data-redis") 7 | 8 | testImplementation("org.springframework.boot:spring-boot-starter-test") 9 | 10 | testRuntimeOnly(project(":springboot-testresources-client")) 11 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 12 | testResourcesImplementation(project(":springboot-testresources-redis")) 13 | } -------------------------------------------------------------------------------- /testprojects/azurite/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.micronaut.test-resources") 3 | } 4 | 5 | dependencies { 6 | implementation(libs.spring.cloud.azure.starter.storage.blob) 7 | runtimeOnly("org.jetbrains.kotlin:kotlin-reflect") 8 | 9 | testImplementation("org.springframework.boot:spring-boot-starter-test") 10 | 11 | testRuntimeOnly(project(":springboot-testresources-client")) 12 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 13 | testResourcesImplementation(project(":springboot-testresources-azurite")) 14 | } -------------------------------------------------------------------------------- /testprojects/rabbitmq/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.micronaut.test-resources") 3 | } 4 | 5 | dependencies { 6 | implementation("org.springframework.boot:spring-boot-starter-amqp") 7 | 8 | testImplementation("org.springframework.boot:spring-boot-starter-test") 9 | testImplementation("org.awaitility:awaitility") 10 | 11 | testRuntimeOnly(project(":springboot-testresources-client")) 12 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 13 | testResourcesImplementation(project(":springboot-testresources-rabbitmq")) 14 | } -------------------------------------------------------------------------------- /testprojects/jdbc/mariadb/src/test/kotlin/io/cloudflight/testresources/springboot/jdbc/mariadb/ApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.jdbc.mariadb 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.springframework.beans.factory.annotation.Autowired 5 | import org.springframework.boot.test.context.SpringBootTest 6 | 7 | @SpringBootTest 8 | class ApplicationTest( 9 | @Autowired private val repository: PersonRepository 10 | ) { 11 | 12 | @Test 13 | fun enterData() { 14 | repository.save(Person(name = "Person1")) 15 | } 16 | } -------------------------------------------------------------------------------- /testprojects/jdbc/mssql/src/test/kotlin/io/cloudflight/testresources/springboot/jdbc/mssql/ApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.jdbc.mssql 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.springframework.beans.factory.annotation.Autowired 5 | import org.springframework.boot.test.context.SpringBootTest 6 | 7 | @SpringBootTest 8 | class ApplicationTest( 9 | @Autowired private val repository: PersonRepository 10 | ) { 11 | 12 | @Test 13 | fun enterData() { 14 | repository.save(Person(name = "Person1")) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /testprojects/jdbc/postgres/src/test/kotlin/io/cloudflight/testresources/springboot/jdbc/postgres/ApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.jdbc.postgres 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.springframework.beans.factory.annotation.Autowired 5 | import org.springframework.boot.test.context.SpringBootTest 6 | 7 | @SpringBootTest 8 | class ApplicationTest( 9 | @Autowired private val repository: PersonRepository 10 | ) { 11 | 12 | @Test 13 | fun enterData() { 14 | repository.save(Person(name = "Person1")) 15 | } 16 | } -------------------------------------------------------------------------------- /testprojects/elasticsearch/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.micronaut.test-resources") 3 | } 4 | 5 | dependencies { 6 | implementation("org.springframework.boot:spring-boot-starter-data-elasticsearch") 7 | 8 | runtimeOnly("org.jetbrains.kotlin:kotlin-reflect") 9 | 10 | testImplementation("org.springframework.boot:spring-boot-starter-test") 11 | 12 | testRuntimeOnly(project(":springboot-testresources-client")) 13 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 14 | testResourcesImplementation(project(":springboot-testresources-elasticsearch")) 15 | } -------------------------------------------------------------------------------- /testprojects/minio/src/test/kotlin/io/cloudflight/testresources/springboot/minio/ApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.minio 2 | 3 | import org.assertj.core.api.Assertions.assertThat 4 | import org.junit.jupiter.api.Test 5 | import org.springframework.beans.factory.annotation.Autowired 6 | import org.springframework.boot.test.context.SpringBootTest 7 | 8 | @SpringBootTest 9 | class ApplicationTest( 10 | @Autowired private val storageService: StorageService 11 | ) { 12 | 13 | @Test 14 | fun minioIsAlive() { 15 | assertThat(storageService.url).isNotBlank 16 | } 17 | } -------------------------------------------------------------------------------- /testprojects/jdbc/postgres/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.micronaut.test-resources") 3 | } 4 | 5 | dependencies { 6 | implementation("org.springframework.boot:spring-boot-starter-data-jpa") 7 | runtimeOnly("org.jetbrains.kotlin:kotlin-reflect") 8 | 9 | testImplementation("org.springframework.boot:spring-boot-starter-test") 10 | 11 | runtimeOnly("org.postgresql:postgresql") 12 | 13 | testRuntimeOnly(project(":springboot-testresources-client")) 14 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 15 | testResourcesImplementation(project(":springboot-testresources-jdbc:springboot-testresources-jdbc-postgres")) 16 | } -------------------------------------------------------------------------------- /springboot-testresources-client/src/main/java/io/cloudflight/testresources/springboot/client/micronaut/ConfigFinder.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.client.micronaut; 2 | 3 | /** 4 | * This class has been partly copied from {@link io.micronaut.testresources.client.ConfigFinder} 5 | * (required, because the original class is package-private) 6 | */ 7 | class ConfigFinder { 8 | public static final String SYSTEM_PROP_PREFIX = "micronaut.test.resources"; 9 | 10 | private ConfigFinder() { 11 | } 12 | 13 | static String systemPropertyNameOf(String propertyName) { 14 | return SYSTEM_PROP_PREFIX + "." + propertyName; 15 | } 16 | } -------------------------------------------------------------------------------- /testprojects/jdbc/mariadb/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.micronaut.test-resources") 3 | } 4 | 5 | dependencies { 6 | implementation("org.springframework.boot:spring-boot-starter-data-jpa") 7 | runtimeOnly("org.jetbrains.kotlin:kotlin-reflect") 8 | 9 | testImplementation("org.springframework.boot:spring-boot-starter-test") 10 | 11 | runtimeOnly("org.mariadb.jdbc:mariadb-java-client") 12 | 13 | testRuntimeOnly(project(":springboot-testresources-client")) 14 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 15 | testResourcesImplementation(project(":springboot-testresources-jdbc:springboot-testresources-jdbc-mariadb")) 16 | } -------------------------------------------------------------------------------- /testprojects/jdbc/mariadb/src/main/kotlin/io/cloudflight/testresources/springboot/jdbc/mariadb/Application.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.jdbc.mariadb 2 | 3 | import jakarta.persistence.Entity 4 | import jakarta.persistence.GeneratedValue 5 | import jakarta.persistence.Id 6 | import org.springframework.boot.autoconfigure.SpringBootApplication 7 | import org.springframework.data.jpa.repository.JpaRepository 8 | 9 | @SpringBootApplication 10 | class Application 11 | 12 | @Entity 13 | class Person(var name: String) { 14 | 15 | @Id 16 | @GeneratedValue 17 | var id: Long = 0 18 | } 19 | 20 | interface PersonRepository : JpaRepository -------------------------------------------------------------------------------- /testprojects/jdbc/mssql/src/main/kotlin/io/cloudflight/testresources/springboot/jdbc/mssql/Application.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.jdbc.mssql 2 | 3 | import jakarta.persistence.Entity 4 | import jakarta.persistence.GeneratedValue 5 | import jakarta.persistence.Id 6 | import org.springframework.boot.autoconfigure.SpringBootApplication 7 | import org.springframework.data.jpa.repository.JpaRepository 8 | 9 | @SpringBootApplication 10 | class Application 11 | 12 | @Entity 13 | class Person(var name: String) { 14 | 15 | @Id 16 | @GeneratedValue 17 | var id: Long = 0 18 | } 19 | 20 | interface PersonRepository : JpaRepository 21 | -------------------------------------------------------------------------------- /testprojects/jdbc/postgres/src/main/kotlin/io/cloudflight/testresources/springboot/jdbc/postgres/Application.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.jdbc.postgres 2 | 3 | import jakarta.persistence.Entity 4 | import jakarta.persistence.GeneratedValue 5 | import jakarta.persistence.Id 6 | import org.springframework.boot.autoconfigure.SpringBootApplication 7 | import org.springframework.data.jpa.repository.JpaRepository 8 | 9 | @SpringBootApplication 10 | class Application 11 | 12 | @Entity 13 | class Person(var name: String) { 14 | 15 | @Id 16 | @GeneratedValue 17 | var id: Long = 0 18 | } 19 | 20 | interface PersonRepository : JpaRepository -------------------------------------------------------------------------------- /testprojects/jdbc/mssql/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.micronaut.test-resources") 3 | } 4 | 5 | dependencies { 6 | implementation("org.springframework.boot:spring-boot-starter-data-jpa") 7 | implementation("com.microsoft.sqlserver:mssql-jdbc:11.2.3.jre17") 8 | 9 | runtimeOnly("org.jetbrains.kotlin:kotlin-reflect") 10 | 11 | testImplementation("org.springframework.boot:spring-boot-starter-test") 12 | 13 | testRuntimeOnly(project(":springboot-testresources-client")) 14 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 15 | testResourcesImplementation(project(":springboot-testresources-jdbc:springboot-testresources-jdbc-mssql")) 16 | } 17 | -------------------------------------------------------------------------------- /testprojects/redis/src/test/kotlin/io/cloudflight/testresources/springboot/redis/ApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.redis 2 | 3 | import org.assertj.core.api.Assertions.assertThat 4 | import org.junit.jupiter.api.Test 5 | import org.springframework.beans.factory.annotation.Autowired 6 | import org.springframework.boot.test.context.SpringBootTest 7 | import org.springframework.data.redis.core.RedisTemplate 8 | 9 | @SpringBootTest 10 | class ApplicationTest( 11 | @Autowired private val redisTemplate: RedisTemplate 12 | ) { 13 | 14 | @Test 15 | fun redisIsAlive() { 16 | redisTemplate.opsForValue().set("test", "me") 17 | assertThat(redisTemplate.opsForValue().get("test")).isEqualTo("me") 18 | } 19 | } -------------------------------------------------------------------------------- /testprojects/mailhog/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.micronaut.test-resources") 3 | kotlin("plugin.serialization") version "1.7.21" 4 | } 5 | 6 | dependencies { 7 | implementation("org.springframework.boot:spring-boot-autoconfigure") 8 | 9 | testImplementation("org.springframework.boot:spring-boot-starter-test") 10 | testImplementation("org.springframework.boot:spring-boot-starter-mail") 11 | testImplementation("org.springframework.boot:spring-boot-starter-web") 12 | 13 | testImplementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1") 14 | 15 | testRuntimeOnly(project(":springboot-testresources-client")) 16 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 17 | testResourcesImplementation(project(":springboot-testresources-mailhog")) 18 | 19 | } 20 | -------------------------------------------------------------------------------- /springboot-testresources-minio/src/test/java/io/cloudflight/testresources/springboot/minio/MinioTestResourcesProviderTest.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.minio; 2 | 3 | import io.cloudflight.testresources.springboot.minio.MinioTestResourcesProvider; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.Collections; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | public class MinioTestResourcesProviderTest { 11 | 12 | private final MinioTestResourcesProvider provider = new MinioTestResourcesProvider(); 13 | 14 | @Test 15 | void getResolvableProperties() { 16 | assertThat(provider.getResolvableProperties(Collections.emptyMap(), Collections.emptyMap())) 17 | .contains("minio.secret-key", "minio.url", "minio.region", "minio.access-key"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /testprojects/elasticsearch/src/main/kotlin/io/cloudflight/testresources/springboot/elasticsearch/Application.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.elasticsearch 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication 4 | import org.springframework.data.annotation.Id 5 | import org.springframework.data.elasticsearch.annotations.Document 6 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository 7 | import org.springframework.stereotype.Repository 8 | 9 | 10 | @SpringBootApplication 11 | class Application 12 | 13 | @Document(indexName = "test_index") 14 | class TestDocument( @Id var key: String? = null, var title: String? = null) { 15 | } 16 | 17 | @Repository 18 | interface TestDocumentRepository : ElasticsearchRepository { 19 | fun findByTitle(title: String?): List? 20 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Java ### 2 | # Compiled class file 3 | *.class 4 | 5 | # Log file 6 | *.log 7 | 8 | # BlueJ files 9 | *.ctxt 10 | 11 | # Mobile Tools for Java (J2ME) 12 | .mtj.tmp/ 13 | 14 | # Package Files # 15 | *.jar 16 | *.war 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | .idea/* 23 | !.idea/runConfigurations 24 | !.idea/jsLinters 25 | 26 | /build/** 27 | *.xlsx 28 | /out/** 29 | 30 | node_modules 31 | 32 | *.iml 33 | 34 | target 35 | 36 | ### Gradle ### 37 | .gradle 38 | **/build/ 39 | 40 | data 41 | 42 | # Ignore Gradle GUI config 43 | gradle-app.setting 44 | 45 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 46 | !gradle-wrapper.jar 47 | 48 | # Cache of project 49 | .gradletasknamecache 50 | 51 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 52 | # gradle/wrapper/gradle-wrapper.properties 53 | 54 | # End of https://www.gitignore.io/api/gradle 55 | -------------------------------------------------------------------------------- /testprojects/rabbitmq/src/test/kotlin/io/cloudflight/testresources/springboot/rabbitmq/ApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.rabbitmq 2 | 3 | import org.awaitility.Awaitility.await 4 | import org.junit.jupiter.api.Test 5 | import org.springframework.amqp.rabbit.core.RabbitTemplate 6 | import org.springframework.beans.factory.annotation.Autowired 7 | import org.springframework.boot.test.context.SpringBootTest 8 | import java.time.Duration.ofSeconds 9 | 10 | @SpringBootTest 11 | class ApplicationTest( 12 | @Autowired private val rabbitTemplate: RabbitTemplate, 13 | @Autowired private val receiver: Receiver 14 | ) { 15 | 16 | @Test 17 | fun `send message via RabbitMQ`() { 18 | rabbitTemplate.convertAndSend("myQueue", "Hello, world!"); 19 | await().atMost(ofSeconds(5)).until { 20 | receiver.messages.size == 1 && receiver.messages.first() == "Hello, world!" 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /testprojects/rabbitmq/src/main/kotlin/io/cloudflight/testresources/springboot/rabbitmq/Application.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.rabbitmq 2 | 3 | import org.springframework.amqp.core.Queue 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener 5 | import org.springframework.boot.autoconfigure.SpringBootApplication 6 | import org.springframework.context.annotation.Bean 7 | import org.springframework.context.annotation.Configuration 8 | import org.springframework.stereotype.Service 9 | 10 | @SpringBootApplication 11 | class Application 12 | 13 | @Configuration 14 | class AmqpConfiguration { 15 | @Bean 16 | fun myQueue(): Queue { 17 | return Queue("myQueue", false) 18 | } 19 | } 20 | 21 | @Service 22 | class Receiver { 23 | 24 | val messages = mutableListOf() 25 | @RabbitListener(queues = ["myQueue"]) 26 | fun listen(message: String) { 27 | messages.add(message) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-testresources-jdbc/springboot-testresources-jdbc-mariadb/src/test/java/io/cloudflight/testresources/springboot/jdbc/mariadb/MariaDbTestResourcesProviderTest.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.jdbc.mariadb; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertFalse; 9 | import static org.junit.jupiter.api.Assertions.assertTrue; 10 | 11 | class MariaDbTestResourcesProviderTest { 12 | 13 | final private MariaDbTestResourcesProvider provider = new MariaDbTestResourcesProvider(); 14 | 15 | @Test 16 | void test() { 17 | List properties = provider.getResolvableProperties(Collections.emptyMap(), Collections.emptyMap()); 18 | assertFalse(properties.isEmpty()); 19 | } 20 | 21 | @Test 22 | void shouldAnswer() { 23 | assertTrue(provider.shouldAnswer("spring.datasource.url", Collections.emptyMap(), Collections.emptyMap())); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.cloudflight.autoconfigure-settings") version "0.9.1" 3 | } 4 | 5 | rootProject.name = "springboot-testresources" 6 | 7 | include("springboot-testresources-azurite") 8 | include("springboot-testresources-client") 9 | include("springboot-testresources-minio") 10 | include("springboot-testresources-jdbc") 11 | include("springboot-testresources-jdbc:springboot-testresources-jdbc-mariadb") 12 | include("springboot-testresources-jdbc:springboot-testresources-jdbc-mssql") 13 | include("springboot-testresources-jdbc:springboot-testresources-jdbc-postgres") 14 | include("springboot-testresources-rabbitmq") 15 | include("springboot-testresources-redis") 16 | include("springboot-testresources-mailhog") 17 | include("springboot-testresources-elasticsearch") 18 | 19 | include("testprojects:jdbc:mariadb") 20 | include("testprojects:jdbc:mssql") 21 | include("testprojects:jdbc:postgres") 22 | include("testprojects:azurite") 23 | include("testprojects:minio") 24 | include("testprojects:rabbitmq") 25 | include("testprojects:redis") 26 | include("testprojects:mailhog") 27 | include("testprojects:elasticsearch") 28 | -------------------------------------------------------------------------------- /springboot-testresources-jdbc/springboot-testresources-jdbc-mssql/src/test/java/io/cloudflight/testresources/springboot/jdbc/mariadb/MssqlServerTestResourcesProviderTest.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.jdbc.mariadb; 2 | 3 | import io.cloudflight.testresources.springboot.jdbc.mssql.MssqlServerTestResourcesProvider; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.Collections; 7 | import java.util.List; 8 | 9 | import static org.junit.jupiter.api.Assertions.assertFalse; 10 | import static org.junit.jupiter.api.Assertions.assertTrue; 11 | 12 | class MssqlServerTestResourcesProviderTest { 13 | 14 | final private MssqlServerTestResourcesProvider provider = new MssqlServerTestResourcesProvider(); 15 | 16 | @Test 17 | void test() { 18 | List properties = provider.getResolvableProperties(Collections.emptyMap(), Collections.emptyMap()); 19 | assertFalse(properties.isEmpty()); 20 | } 21 | 22 | @Test 23 | void shouldAnswer() { 24 | assertTrue(provider.shouldAnswer("spring.datasource.url", Collections.emptyMap(), Collections.emptyMap())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-testresources-jdbc/springboot-testresources-jdbc-mariadb/src/main/java/io/cloudflight/testresources/springboot/jdbc/mariadb/MariaDbTestResourcesProvider.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.jdbc.mariadb; 2 | 3 | import io.cloudflight.testresources.springboot.jdbc.AbstractJdbcTestResourceProvider; 4 | import org.testcontainers.containers.MariaDBContainer; 5 | import org.testcontainers.utility.DockerImageName; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * Test container provider for MariaDB. 11 | */ 12 | public class MariaDbTestResourcesProvider extends AbstractJdbcTestResourceProvider> { 13 | 14 | private static final String DEFAULT_IMAGE = "mariadb"; 15 | private static final String SIMPLE_NAME = "mariadb"; 16 | 17 | 18 | @Override 19 | protected String getSimpleName() { 20 | return SIMPLE_NAME; 21 | } 22 | 23 | @Override 24 | protected String getDefaultImageName() { 25 | return DEFAULT_IMAGE; 26 | } 27 | 28 | @Override 29 | protected MariaDBContainer createContainer(DockerImageName imageName, Map requestedProperties, Map testResourcesConfiguration) { 30 | return new MariaDBContainer<>(imageName); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /springboot-testresources-jdbc/springboot-testresources-jdbc-postgres/src/main/java/io/cloudflight/testresources/springboot/jdbc/postgres/PostgresTestResourcesProvider.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.jdbc.postgres; 2 | 3 | import io.cloudflight.testresources.springboot.jdbc.AbstractJdbcTestResourceProvider; 4 | import org.testcontainers.containers.PostgreSQLContainer; 5 | import org.testcontainers.utility.DockerImageName; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * Test container provider for PostgreSQL. 11 | */ 12 | public class PostgresTestResourcesProvider extends AbstractJdbcTestResourceProvider> { 13 | 14 | private static final String DEFAULT_IMAGE = "postgres"; 15 | private static final String SIMPLE_NAME = "postgres"; 16 | 17 | @Override 18 | protected String getSimpleName() { 19 | return SIMPLE_NAME; 20 | } 21 | 22 | @Override 23 | protected String getDefaultImageName() { 24 | return DEFAULT_IMAGE; 25 | } 26 | 27 | @Override 28 | protected PostgreSQLContainer createContainer(DockerImageName imageName, Map requestedProperties, Map testResourcesConfiguration) { 29 | return new PostgreSQLContainer<>(imageName); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /.github/workflows/github-build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - name: Clone repository 11 | uses: actions/checkout@v3 12 | with: 13 | fetch-depth: 0 14 | - name: Set up Java 15 | uses: actions/setup-java@v3 16 | with: 17 | java-version: '17' 18 | distribution: 'temurin' 19 | - name: Validate Gradle wrapper 20 | uses: gradle/wrapper-validation-action@v1 21 | - name : Retrieve module version from Reckon 22 | run: echo "VERSION_NAME=$(${{github.workspace}}/gradlew -q clfPrintVersion)" >> $GITHUB_OUTPUT 23 | id: retrieve_version 24 | - name: Publish module version to Github Step Summary 25 | run: | 26 | echo "# ${{steps.retrieve_version.outputs.VERSION_NAME}}" >> $GITHUB_STEP_SUMMARY 27 | - name: Build with Gradle 28 | uses: gradle/gradle-build-action@v2 29 | with: 30 | arguments: build 31 | - name: Publish Test Report 32 | uses: mikepenz/action-junit-report@v3 33 | if: always() # always run even if the previous step fails 34 | with: 35 | report_paths: '**/build/test-results/test/TEST-*.xml' 36 | include_passed: true -------------------------------------------------------------------------------- /testprojects/elasticsearch/src/test/kotlin/io/cloudflight/testresources/springboot/elasticsearch/ApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.elasticsearch 2 | 3 | import org.assertj.core.api.Assertions.assertThat 4 | import org.junit.jupiter.api.Test 5 | import org.springframework.beans.factory.annotation.Autowired 6 | import org.springframework.beans.factory.annotation.Value 7 | import org.springframework.boot.test.context.SpringBootTest 8 | 9 | @SpringBootTest 10 | class ApplicationTest( 11 | @Value("\${spring.elasticsearch.uris}") private val uris: String, 12 | @Autowired private val testDocumentRepository: TestDocumentRepository 13 | ) { 14 | 15 | @Test 16 | fun urisPropertyIsBound() { 17 | assertThat(uris).matches("^localhost:[1-9][0-9]{3,4}\$") 18 | } 19 | 20 | @Test 21 | fun springDataShouldWork() { 22 | val key = "test::1" 23 | val title = "myvalue" 24 | assertThat(testDocumentRepository).isNotNull() 25 | assertThat(testDocumentRepository.findById(key).isPresent()).isFalse() 26 | val testDocument = TestDocument(key, title) 27 | testDocumentRepository.save(testDocument) 28 | val foundDocument = testDocumentRepository.findById(key).get() 29 | assertThat(foundDocument.key).isEqualTo(key) 30 | assertThat(foundDocument.title).isEqualTo(title) 31 | } 32 | } -------------------------------------------------------------------------------- /testprojects/azurite/src/test/kotlin/io/cloudflight/testresources/springboot/azurite/ApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.azurite 2 | 3 | import com.azure.storage.blob.BlobServiceClientBuilder 4 | import org.assertj.core.api.Assertions.assertThat 5 | import org.junit.jupiter.api.Test 6 | import org.springframework.beans.factory.annotation.Autowired 7 | import org.springframework.boot.test.context.SpringBootTest 8 | import java.util.* 9 | 10 | @SpringBootTest 11 | class ApplicationTest( 12 | @param:Autowired private val blobServiceClientBuilder: BlobServiceClientBuilder 13 | ) { 14 | 15 | @Test 16 | fun accountName() { 17 | val blobServiceClient = blobServiceClientBuilder.buildClient() 18 | assertThat(blobServiceClient.accountName).isEqualTo("devstoreaccount1") 19 | } 20 | 21 | @Test 22 | fun `do some basic operations to show that azurite is running and working correctly`() { 23 | val blobServiceClient = blobServiceClientBuilder.buildClient() 24 | val containersBefore = blobServiceClient.listBlobContainers().stream().count() 25 | val container = blobServiceClient.createBlobContainer(UUID.randomUUID().toString()) 26 | assertThat(container.listBlobs().stream()).isEmpty() 27 | assertThat(blobServiceClient.listBlobContainers().stream().count()).isEqualTo(containersBefore + 1) 28 | container.delete() 29 | assertThat(blobServiceClient.listBlobContainers().stream().count()).isEqualTo(containersBefore) 30 | } 31 | } -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | micronaut-testresources = "1.2.6" 3 | spring-boot = "3.5.7" 4 | quarkus-junit-mock = "3.30.3" 5 | micronaut = "3.8.7" 6 | 7 | junit = "5.9.1" 8 | assertj = "3.27.6" 9 | azurite = "5.24.1" 10 | 11 | [libraries] 12 | 13 | micronaut-testresources-client = { module = "io.micronaut.testresources:micronaut-test-resources-client", version.ref = "micronaut-testresources" } 14 | micronaut-testresources-testcontainers = { module = "io.micronaut.testresources:micronaut-test-resources-testcontainers", version.ref = "micronaut-testresources" } 15 | micronaut-core = { module = "io.micronaut:micronaut-core", version.ref = "micronaut" } 16 | micronaut-http-client = { module = "io.micronaut:micronaut-http-client", version.ref = "micronaut" } 17 | 18 | spring-boot = { module = "org.springframework.boot:spring-boot", version.ref = "spring-boot" } 19 | spring-bootbom = { module = "org.springframework.boot:spring-boot-dependencies", version.ref = "spring-boot" } 20 | 21 | jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" } 22 | jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" } 23 | 24 | assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" } 25 | testcontainers-elasticsearch = { module = "org.testcontainers:elasticsearch" } 26 | testcontainers-jdbc = { module = "org.testcontainers:jdbc" } 27 | testcontainers-mariadb = { module = "org.testcontainers:mariadb" } 28 | testcontainers-mssqlserver = { module = "org.testcontainers:mssqlserver" } 29 | testcontainers-postgresql = { module = "org.testcontainers:postgresql" } 30 | testcontainers-rabbitmq = { module = "org.testcontainers:rabbitmq" } 31 | testcontainers-junit4-mock = { module = "io.quarkus:quarkus-junit4-mock", version.ref = "quarkus-junit-mock" } 32 | 33 | spring-cloud-azure-starter-storage-blob = { module = "com.azure.spring:spring-cloud-azure-starter-storage-blob", version.ref = "azurite" } 34 | -------------------------------------------------------------------------------- /testprojects/mailhog/src/test/kotlin/io/cloudflight/testresources/springboot/mailhog/ApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.mailhog 2 | 3 | import kotlinx.serialization.SerialName 4 | import kotlinx.serialization.Serializable 5 | import kotlinx.serialization.json.Json 6 | import org.assertj.core.api.Assertions.assertThat 7 | import org.junit.jupiter.api.Test 8 | import org.springframework.beans.factory.annotation.Autowired 9 | import org.springframework.beans.factory.annotation.Value 10 | import org.springframework.boot.test.context.SpringBootTest 11 | import org.springframework.http.MediaType 12 | import org.springframework.http.converter.KotlinSerializationStringHttpMessageConverter 13 | import org.springframework.mail.MailSender 14 | import org.springframework.mail.SimpleMailMessage 15 | import org.springframework.web.client.RestTemplate 16 | 17 | @SpringBootTest 18 | class ApplicationTest( 19 | @Autowired private val mailSender: MailSender, 20 | @Value("\${test-resources.mailhog.api-url}") private val mailhogApiUrl: String, 21 | ) { 22 | @Serializable 23 | data class MailhogResponse(val count: Int) 24 | 25 | val restTemplate = RestTemplate(listOf(object : KotlinSerializationStringHttpMessageConverter(Json { 26 | ignoreUnknownKeys = true 27 | }, MediaType("text", "json")) {})) 28 | 29 | @Test 30 | fun isShouldBeAbleToSendAnEmailViaSmtp() { 31 | restTemplate.getForEntity("$mailhogApiUrl/api/v2/messages", MailhogResponse::class.java).apply { 32 | assertThat(body).isNotNull 33 | assertThat(body!!.count).isEqualTo(0) 34 | } 35 | 36 | mailSender.send(SimpleMailMessage().apply { 37 | from = "me@example.com" 38 | setTo("you@example.com") 39 | subject = "One test email" 40 | text = "Content here" 41 | }) 42 | 43 | restTemplate.getForEntity("$mailhogApiUrl/api/v2/messages", MailhogResponse::class.java).apply { 44 | assertThat(body).isNotNull 45 | assertThat(body!!.count).isEqualTo(1) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /.github/workflows/github-publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to Maven Central 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | scope: 7 | description: 'the scope of the version' 8 | required: true 9 | default: 'patch' 10 | type: choice 11 | options: 12 | - patch 13 | - minor 14 | - major 15 | 16 | jobs: 17 | publish: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Clone repository 21 | uses: actions/checkout@v3 22 | with: 23 | fetch-depth: 0 24 | - name: Set up Java 25 | uses: actions/setup-java@v3 26 | with: 27 | java-version: '17' 28 | distribution: 'temurin' 29 | - name: Validate Gradle wrapper 30 | uses: gradle/wrapper-validation-action@v1 31 | - name : Retrieve module version from Reckon 32 | run: echo "VERSION_NAME=$(${{github.workspace}}/gradlew -q clfPrintVersion -Preckon.stage=final -Preckon.scope=${{ inputs.scope }})" >> $GITHUB_OUTPUT 33 | id: retrieve_version 34 | - name: Publish module version to Github Step Summary 35 | run: | 36 | echo "# ${{steps.retrieve_version.outputs.VERSION_NAME}}" >> $GITHUB_STEP_SUMMARY 37 | - name: Publish and Create Tag 38 | uses: gradle/gradle-build-action@v2 39 | with: 40 | arguments: check reckonTagPush publishToSonatype closeAndReleaseSonatypeStagingRepository -Preckon.stage=final -Preckon.scope=${{ inputs.scope }} 41 | env: 42 | MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} 43 | MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} 44 | PGP_SECRET: ${{ secrets.PGP_SECRET }} 45 | PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} 46 | - name: Publish Test Report 47 | uses: mikepenz/action-junit-report@v3 48 | if: always() # always run even if the previous step fails 49 | with: 50 | report_paths: '**/build/test-results/test/TEST-*.xml' 51 | include_passed: true 52 | - name: Create Release on GitHub 53 | uses: softprops/action-gh-release@v1 54 | with: 55 | name: ${{steps.retrieve_version.outputs.VERSION_NAME}} 56 | tag_name: ${{steps.retrieve_version.outputs.VERSION_NAME}} 57 | generate_release_notes: true 58 | append_body: true -------------------------------------------------------------------------------- /springboot-testresources-client/src/main/java/io/cloudflight/testresources/springboot/client/micronaut/TestResourcesClientFactory.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.client.micronaut; 2 | 3 | import io.micronaut.http.client.DefaultHttpClientConfiguration; 4 | import io.micronaut.http.client.HttpClient; 5 | import io.micronaut.http.client.HttpClientConfiguration; 6 | import io.micronaut.testresources.client.DefaultTestResourcesClient; 7 | import io.micronaut.testresources.client.TestResourcesClient; 8 | 9 | import java.net.MalformedURLException; 10 | import java.net.URL; 11 | import java.time.Duration; 12 | import java.time.temporal.ChronoUnit; 13 | import java.util.Optional; 14 | 15 | /** 16 | * This class has been partly copied from {@link io.micronaut.testresources.client.TestResourcesClientFactory} 17 | * (required, because the original class is package-private) 18 | */ 19 | public class TestResourcesClientFactory { 20 | 21 | /** 22 | * Tries to create a {@link TestResourcesClient} from the system properties. 23 | * @return The {@link TestResourcesClient} if it could be created, otherwise {@link Optional#empty()} 24 | */ 25 | public static Optional fromSystemProperties() { 26 | String serverUri = System.getProperty(ConfigFinder.systemPropertyNameOf(TestResourcesClient.SERVER_URI)); 27 | if (serverUri != null) { 28 | String accessToken = System.getProperty(ConfigFinder.systemPropertyNameOf(TestResourcesClient.ACCESS_TOKEN)); 29 | String clientTimeoutString = System.getProperty(ConfigFinder.systemPropertyNameOf(TestResourcesClient.CLIENT_READ_TIMEOUT), DEFAULT_TIMEOUT_SECONDS); 30 | int clientReadTimeout = Integer.parseInt(clientTimeoutString); 31 | HttpClientConfiguration config = new DefaultHttpClientConfiguration(); 32 | config.setReadTimeout(Duration.of(clientReadTimeout, ChronoUnit.SECONDS)); 33 | HttpClient client; 34 | try { 35 | client = HttpClient.create(new URL(serverUri), config); 36 | } catch (MalformedURLException e) { 37 | return Optional.empty(); 38 | } 39 | return Optional.of(new DefaultTestResourcesClient(client, accessToken)); 40 | } 41 | return Optional.empty(); 42 | } 43 | 44 | private static final String DEFAULT_TIMEOUT_SECONDS = "60"; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /springboot-testresources-client/src/main/java/io/cloudflight/testresources/springboot/client/TestResourcesEnvironmentPostProcessor.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.client; 2 | 3 | import io.cloudflight.testresources.springboot.client.micronaut.TestResourcesClientFactory; 4 | import io.micronaut.testresources.client.TestResourcesClient; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.env.EnvironmentPostProcessor; 7 | import org.springframework.context.ApplicationContextException; 8 | import org.springframework.core.Ordered; 9 | import org.springframework.core.annotation.Order; 10 | import org.springframework.core.env.ConfigurableEnvironment; 11 | 12 | import java.util.Optional; 13 | 14 | /** 15 | * The TestResourcesEnvironmentPostProcessor class is a Spring EnvironmentPostProcessor 16 | * that integrates with the test resources service and modifies the application's 17 | * environment configuration accordingly. 18 | * 19 | * This processor attempts to instantiate a TestResourcesClient from system 20 | * properties using the {@link TestResourcesClientFactory#fromSystemProperties()} 21 | * method. If successful, it adds a custom {@link TestResourcesPropertySource} 22 | * to the environment's property sources to resolve properties from the test 23 | * resources service. 24 | * 25 | * If the TestResourcesClient cannot be created, an ApplicationContextException 26 | * is thrown indicating that the TestResources service is unavailable, and the 27 | * Test-Resources Build plugin for Maven or Gradle may not be active. 28 | * 29 | * The processor is set to execute with the lowest precedence to ensure it interacts 30 | * with an already configured environment. 31 | */ 32 | @Order(Ordered.LOWEST_PRECEDENCE) 33 | public class TestResourcesEnvironmentPostProcessor implements EnvironmentPostProcessor { 34 | @Override 35 | public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { 36 | Optional resourcesClient = TestResourcesClientFactory.fromSystemProperties(); 37 | if (resourcesClient.isPresent()) { 38 | environment.getPropertySources().addFirst(new TestResourcesPropertySource(resourcesClient.get(), environment)); 39 | } else { 40 | throw new ApplicationContextException("TestResources Service could not be found. Is the Test-Resources Build plugin for Maven or Gradle active?"); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /springboot-testresources-redis/src/main/java/io/cloudflight/testresources/springboot/redis/RedisTestResourceProvider.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.redis; 2 | 3 | import io.micronaut.testresources.testcontainers.AbstractTestContainersProvider; 4 | import org.testcontainers.containers.GenericContainer; 5 | import org.testcontainers.utility.DockerImageName; 6 | 7 | import java.util.*; 8 | 9 | /** 10 | * Test container provider for Redis. 11 | */ 12 | public class RedisTestResourceProvider extends AbstractTestContainersProvider> { 13 | 14 | /** 15 | * Redis URI. 16 | */ 17 | public static final String REDIS_URI = "spring.data.redis.url"; 18 | /** 19 | * Default image name. 20 | */ 21 | public static final String DEFAULT_IMAGE = "redis"; 22 | /** 23 | * Simple name of the test resource. 24 | */ 25 | public static final String SIMPLE_NAME = "redis"; 26 | /** 27 | * Redis port. 28 | */ 29 | public static final int REDIS_PORT = 6379; 30 | 31 | private static final Set SUPPORTED_PROPERTIES; 32 | 33 | static { 34 | SUPPORTED_PROPERTIES = Set.of(REDIS_URI); 35 | } 36 | 37 | @Override 38 | public List getResolvableProperties(Map> propertyEntries, Map testResourcesConfig) { 39 | return Collections.singletonList(REDIS_URI); 40 | } 41 | 42 | @Override 43 | protected String getSimpleName() { 44 | return SIMPLE_NAME; 45 | } 46 | 47 | @Override 48 | protected String getDefaultImageName() { 49 | return DEFAULT_IMAGE; 50 | } 51 | 52 | @Override 53 | protected GenericContainer createContainer(DockerImageName imageName, Map requestedProperties, Map testResourcesConfiguration) { 54 | GenericContainer container = new GenericContainer<>(imageName); 55 | container.withExposedPorts(REDIS_PORT); 56 | return container; 57 | } 58 | 59 | @Override 60 | protected Optional resolveProperty(String propertyName, GenericContainer container) { 61 | if (REDIS_URI.equals(propertyName)) { 62 | return Optional.of("redis://" + container.getHost() + ":" + container.getMappedPort(REDIS_PORT)); 63 | } 64 | return Optional.empty(); 65 | } 66 | 67 | @Override 68 | protected boolean shouldAnswer(String propertyName, Map requestedProperties, Map testResourcesConfiguration) { 69 | return SUPPORTED_PROPERTIES.contains(propertyName); 70 | } 71 | } -------------------------------------------------------------------------------- /springboot-testresources-jdbc/springboot-testresources-jdbc-mssql/src/main/java/io/cloudflight/testresources/springboot/jdbc/mssql/MssqlServerTestResourcesProvider.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.jdbc.mssql; 2 | 3 | import io.cloudflight.testresources.springboot.jdbc.AbstractJdbcTestResourceProvider; 4 | import org.testcontainers.containers.MSSQLServerContainer; 5 | import org.testcontainers.containers.wait.strategy.Wait; 6 | import org.testcontainers.utility.DockerImageName; 7 | import org.testcontainers.utility.LicenseAcceptance; 8 | 9 | import java.time.Duration; 10 | import java.util.Map; 11 | 12 | /** 13 | * Test container provider for Microsoft SQL Server. 14 | */ 15 | public class MssqlServerTestResourcesProvider extends AbstractJdbcTestResourceProvider> { 16 | 17 | private static final String DEFAULT_IMAGE = "mcr.microsoft.com/mssql/server:2019-CU16-GDR1-ubuntu-20.04"; 18 | private static final String SIMPLE_NAME = "mssql"; 19 | 20 | 21 | @Override 22 | protected String getSimpleName() { 23 | return SIMPLE_NAME; 24 | } 25 | 26 | @Override 27 | protected String getDefaultImageName() { 28 | return DEFAULT_IMAGE; 29 | } 30 | 31 | @Override 32 | protected MSSQLServerContainer createContainer(DockerImageName imageName, Map requestedProperties, Map testResourcesConfiguration) { 33 | return createMSSQLContainer(imageName, getSimpleName(), testResourcesConfiguration); 34 | } 35 | 36 | /** 37 | * Creates a new Microsoft SQL Server container. 38 | * @param imageName . 39 | * @param simpleName . 40 | * @param testResourcesConfiguration . 41 | * @return The created container. 42 | */ 43 | public static MSSQLServerContainer createMSSQLContainer(DockerImageName imageName, String simpleName, Map testResourcesConfiguration) { 44 | MSSQLServerContainer container = new MSSQLServerContainer<>(imageName); 45 | String licenseKey = "containers." + simpleName + ".accept-license"; 46 | Boolean acceptLicense = (Boolean) testResourcesConfiguration.get(licenseKey); 47 | if (Boolean.TRUE.equals(acceptLicense)) { 48 | container.acceptLicense(); 49 | } else { 50 | try { 51 | LicenseAcceptance.assertLicenseAccepted(imageName.toString()); 52 | } catch (IllegalStateException ex) { 53 | throw new IllegalStateException("You must set the property 'test-resources." + licenseKey + "' to true in order to use a Microsoft SQL Server test container", ex); 54 | } 55 | } 56 | return container; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /springboot-testresources-client/src/main/java/io/cloudflight/testresources/springboot/client/TestResourcesPropertySource.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.client; 2 | 3 | import io.micronaut.testresources.client.TestResourcesClient; 4 | import org.springframework.core.env.ConfigurableEnvironment; 5 | import org.springframework.core.env.EnumerablePropertySource; 6 | import org.springframework.core.env.Environment; 7 | import org.springframework.core.env.PropertySource; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | import static java.util.Collections.emptyMap; 13 | 14 | /** 15 | * Property source that exposes the test resources configuration as properties. 16 | */ 17 | public class TestResourcesPropertySource extends PropertySource { 18 | 19 | private static final String NAME = "testresources"; 20 | private static final String TEST_RESOURCES_PROPERTY_PREFIX = "test-resources."; 21 | private final ConfigurableEnvironment environment; 22 | private static Map testResourcesConfiguration; 23 | 24 | /** 25 | * Constructor. 26 | * @param client . 27 | * @param environment . 28 | */ 29 | public TestResourcesPropertySource(TestResourcesClient client, ConfigurableEnvironment environment) { 30 | super(NAME, client); 31 | this.environment = environment; 32 | } 33 | 34 | @Override 35 | public Object getProperty(String name) { 36 | if (source.getResolvableProperties().contains(name)) { 37 | return source.resolve(name, emptyMap(), getTestResourcesConfiguration(environment)).orElse(null); 38 | } else { 39 | return null; 40 | } 41 | } 42 | 43 | private synchronized static Map getTestResourcesConfiguration(Environment env) { 44 | if (testResourcesConfiguration == null) { 45 | testResourcesConfiguration = new HashMap<>(); 46 | if (env instanceof ConfigurableEnvironment) { 47 | for (PropertySource propertySource : ((ConfigurableEnvironment) env).getPropertySources()) { 48 | if (propertySource instanceof EnumerablePropertySource) { 49 | for (String key : ((EnumerablePropertySource) propertySource).getPropertyNames()) { 50 | if (key.startsWith(TEST_RESOURCES_PROPERTY_PREFIX)) { 51 | testResourcesConfiguration.put(key.substring(TEST_RESOURCES_PROPERTY_PREFIX.length()), propertySource.getProperty(key)); 52 | } 53 | } 54 | } 55 | } 56 | } 57 | } 58 | return testResourcesConfiguration; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /springboot-testresources-rabbitmq/src/main/java/io/cloudflight/testresources/springboot/rabbitmq/RabbitMQTestResourceProvider.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.rabbitmq; 2 | 3 | import io.micronaut.testresources.testcontainers.AbstractTestContainersProvider; 4 | import org.testcontainers.containers.RabbitMQContainer; 5 | import org.testcontainers.utility.DockerImageName; 6 | 7 | import java.util.*; 8 | 9 | /** 10 | * Test container provider for RabbitMQ. 11 | */ 12 | public class RabbitMQTestResourceProvider extends AbstractTestContainersProvider { 13 | 14 | private static final String RABBITMQ_HOST = "spring.rabbitmq.host"; 15 | private static final String RABBITMQ_PORT = "spring.rabbitmq.port"; 16 | private static final String RABBITMQ_USERNAME = "spring.rabbitmq.username"; 17 | private static final String RABBITMQ_PASSWORD = "spring.rabbitmq.password"; 18 | private static final String DEFAULT_IMAGE = "rabbitmq"; 19 | private static final String SIMPLE_NAME = "rabbitmq"; 20 | 21 | private static final List SUPPORTED_KEYS = List.of(RABBITMQ_HOST, RABBITMQ_PORT, RABBITMQ_USERNAME, RABBITMQ_PASSWORD); 22 | private static final Set SUPPORTED_KEYSET = Set.copyOf(SUPPORTED_KEYS); 23 | 24 | @Override 25 | public List getResolvableProperties(Map> propertyEntries, Map testResourcesConfig) { 26 | return SUPPORTED_KEYS; 27 | } 28 | 29 | @Override 30 | protected String getSimpleName() { 31 | return SIMPLE_NAME; 32 | } 33 | 34 | @Override 35 | protected String getDefaultImageName() { 36 | return DEFAULT_IMAGE; 37 | } 38 | 39 | @Override 40 | protected RabbitMQContainer createContainer(DockerImageName imageName, Map requestedProperties, Map testResourcesConfiguration) { 41 | return new RabbitMQContainer(imageName); 42 | } 43 | 44 | @Override 45 | protected Optional resolveProperty(String propertyName, RabbitMQContainer container) { 46 | switch (propertyName) { 47 | case RABBITMQ_HOST -> { 48 | return Optional.of(container.getHost()); 49 | } 50 | case RABBITMQ_PORT -> { 51 | return Optional.of(container.getAmqpPort().toString()); 52 | } 53 | case RABBITMQ_USERNAME -> { 54 | return Optional.of(container.getAdminUsername()); 55 | } 56 | case RABBITMQ_PASSWORD -> { 57 | return Optional.of(container.getAdminPassword()); 58 | } 59 | default -> { 60 | return Optional.empty(); 61 | } 62 | } 63 | } 64 | 65 | @Override 66 | protected boolean shouldAnswer(String propertyName, Map requestedProperties, Map testResourcesConfiguration) { 67 | return SUPPORTED_KEYSET.contains(propertyName); 68 | } 69 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /springboot-testresources-elasticsearch/src/main/java/io/cloudflight/testresources/springboot/elasticsearch/ElasticSearchTestResourceProvider.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.elasticsearch; 2 | 3 | import io.micronaut.testresources.testcontainers.AbstractTestContainersProvider; 4 | import org.testcontainers.elasticsearch.ElasticsearchContainer; 5 | import org.testcontainers.utility.DockerImageName; 6 | 7 | import java.util.*; 8 | import java.util.stream.Collectors; 9 | 10 | /** 11 | * Test container provider for ElasticSearch. 12 | */ 13 | public class ElasticSearchTestResourceProvider extends AbstractTestContainersProvider { 14 | 15 | private static final String SIMPLE_NAME = "elasticsearch"; 16 | private static final String DEFAULT_IMAGE = "docker.elastic.co/elasticsearch/elasticsearch"; 17 | private static final String DEFAULT_TAG = "8.4.3"; 18 | private static final String PREFIX = "spring.elasticsearch"; 19 | private static final String URIS = "uris"; 20 | private static final String PASSWORD = "password"; 21 | private static final String ENV_PASSWORD = "ELASTIC_PASSWORD"; 22 | private static final List SUPPORTED_LIST = Collections.unmodifiableList( 23 | Arrays.asList(URIS, PASSWORD) 24 | ); 25 | 26 | @Override 27 | protected String getSimpleName() { 28 | return SIMPLE_NAME; 29 | } 30 | 31 | @Override 32 | protected String getDefaultImageName() { 33 | return DEFAULT_IMAGE; 34 | } 35 | 36 | @Override 37 | protected ElasticsearchContainer createContainer(DockerImageName imageName, Map requestedProperties, Map testResourcesConfiguration) { 38 | if ("latest".equals(imageName.getVersionPart())) { 39 | // ElasticSearch does't provide a latest tag, so we use a hardcoded version 40 | imageName = imageName.withTag(DEFAULT_TAG); 41 | } 42 | ElasticsearchContainer container = new ElasticsearchContainer(imageName); 43 | container.withEnv("xpack.security.enabled", "false"); 44 | return container; 45 | } 46 | 47 | @Override 48 | protected Optional resolveProperty(String propertyName, ElasticsearchContainer container) { 49 | String value = switch (configurationPropertyFrom(propertyName)) { 50 | case URIS -> container.getHttpHostAddress(); 51 | case PASSWORD -> container.getEnvMap().get(ENV_PASSWORD); 52 | default -> null; 53 | }; 54 | return Optional.ofNullable(value); 55 | } 56 | 57 | private String configurationPropertyFrom(String expression) { 58 | String[] propertyParts = expression.split("\\."); 59 | return propertyParts[propertyParts.length - 1]; 60 | } 61 | 62 | @Override 63 | public boolean shouldAnswer(String propertyName, Map requestedProperties, Map testResourcesConfiguration) { 64 | return propertyName.startsWith(PREFIX); 65 | } 66 | 67 | @Override 68 | public List getResolvableProperties(Map> propertyEntries, Map testResourcesConfig) { 69 | return SUPPORTED_LIST.stream().map(p -> PREFIX + "." + p).collect(Collectors.toList()); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /springboot-testresources-minio/src/main/java/io/cloudflight/testresources/springboot/minio/MinioTestResourcesProvider.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.minio; 2 | 3 | import io.micronaut.testresources.testcontainers.AbstractTestContainersProvider; 4 | import org.testcontainers.containers.GenericContainer; 5 | import org.testcontainers.utility.DockerImageName; 6 | 7 | import java.util.*; 8 | 9 | /** 10 | * Test container provider for Minio. 11 | */ 12 | public class MinioTestResourcesProvider extends AbstractTestContainersProvider> { 13 | 14 | private static final String MINIO_URL = "minio.url"; 15 | private static final String MINIO_ACCESS_KEY = "minio.access-key"; 16 | private static final String MINIO_SECRET_KEY = "minio.secret-key"; 17 | private static final String MINIO_REGION = "minio.region"; 18 | private static final String DEFAULT_IMAGE = "minio/minio"; 19 | private static final String SIMPLE_NAME = "minio"; 20 | private static final int MINIO_PORT = 9000; 21 | private static final int MINIO_CONSOLE_PORT = 9001; 22 | 23 | private static final Set SUPPORTED_PROPERTIES; 24 | 25 | static { 26 | SUPPORTED_PROPERTIES = Set.of(MINIO_URL, MINIO_ACCESS_KEY, MINIO_SECRET_KEY, MINIO_REGION); 27 | } 28 | 29 | @Override 30 | public List getResolvableProperties(Map> propertyEntries, Map testResourcesConfig) { 31 | return SUPPORTED_PROPERTIES.stream().toList(); 32 | } 33 | 34 | @Override 35 | protected String getSimpleName() { 36 | return SIMPLE_NAME; 37 | } 38 | 39 | @Override 40 | protected String getDefaultImageName() { 41 | return DEFAULT_IMAGE; 42 | } 43 | 44 | @Override 45 | protected GenericContainer createContainer(DockerImageName imageName, Map requestedProperties, Map testResourcesConfiguration) { 46 | GenericContainer container = new GenericContainer<>(imageName); 47 | container.withExposedPorts(MINIO_PORT, MINIO_CONSOLE_PORT); 48 | container.withCommand("server", "/data", "--console-address", ":" + MINIO_CONSOLE_PORT); 49 | container.withEnv("MINIO_ROOT_USER", "minio"); 50 | container.withEnv("MINIO_ROOT_PASSWORD", "minio123"); 51 | container.withEnv("MINIO_SITE_REGION", "eu-central-1"); 52 | return container; 53 | } 54 | 55 | @Override 56 | protected Optional resolveProperty(String propertyName, GenericContainer container) { 57 | 58 | if (MINIO_URL.equals(propertyName)) { 59 | return Optional.of("http://" + container.getHost() + ":" + container.getMappedPort(MINIO_PORT)); 60 | } 61 | if (MINIO_ACCESS_KEY.equals(propertyName)) { 62 | return Optional.of("minio"); 63 | } 64 | if (MINIO_SECRET_KEY.equals(propertyName)) { 65 | return Optional.of("minio123"); 66 | } 67 | if (MINIO_REGION.equals(propertyName)) { 68 | return Optional.of("eu-central-1"); 69 | } 70 | return Optional.empty(); 71 | } 72 | 73 | @Override 74 | protected boolean shouldAnswer(String propertyName, Map requestedProperties, Map testResourcesConfiguration) { 75 | return SUPPORTED_PROPERTIES.contains(propertyName); 76 | } 77 | } -------------------------------------------------------------------------------- /springboot-testresources-azurite/src/main/java/io/cloudflight/testresources/springboot/azurite/AzuriteTestResourceProvider.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.azurite; 2 | 3 | import io.micronaut.testresources.testcontainers.AbstractTestContainersProvider; 4 | import org.testcontainers.containers.GenericContainer; 5 | import org.testcontainers.utility.DockerImageName; 6 | 7 | import java.util.*; 8 | 9 | /** 10 | * Test container provider for Azure Blob Storage Emulator. 11 | */ 12 | public class AzuriteTestResourceProvider extends AbstractTestContainersProvider> { 13 | 14 | private static final String PREFIX = "spring.cloud.azure.storage.blob."; 15 | private static final String ACCOUNT_NAME_PROPERTY = PREFIX + "account-name"; 16 | private static final String ACCOUNT_KEY_PROPERTY = PREFIX + "account-key"; 17 | private static final String ACCOUNT_ENDPOINT_PROPERTY = PREFIX + "endpoint"; 18 | private static final String DEFAULT_IMAGE = "mcr.microsoft.com/azure-storage/azurite"; 19 | private static final String SIMPLE_NAME = "azurite"; 20 | 21 | /** 22 | * can't be changed, see https://github.com/Azure/Azurite#default-storage-account 23 | */ 24 | private static final String ACCOUNT_NAME = "devstoreaccount1"; 25 | 26 | /** 27 | * can't be changed, see https://github.com/Azure/Azurite#default-storage-account 28 | */ 29 | private static final String ACCOUNT_KEY = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="; 30 | 31 | private static final int AZURITE_PORT = 10000; 32 | 33 | private static final Set SUPPORTED_PROPERTIES; 34 | 35 | static { 36 | SUPPORTED_PROPERTIES = Set.of(ACCOUNT_NAME_PROPERTY, ACCOUNT_KEY_PROPERTY, ACCOUNT_ENDPOINT_PROPERTY); 37 | } 38 | 39 | @Override 40 | public List getResolvableProperties(Map> propertyEntries, Map testResourcesConfig) { 41 | return SUPPORTED_PROPERTIES.stream().toList(); 42 | } 43 | 44 | @Override 45 | protected String getSimpleName() { 46 | return SIMPLE_NAME; 47 | } 48 | 49 | @Override 50 | protected String getDefaultImageName() { 51 | return DEFAULT_IMAGE; 52 | } 53 | 54 | @Override 55 | protected GenericContainer createContainer(DockerImageName imageName, Map requestedProperties, Map testResourcesConfiguration) { 56 | GenericContainer container = new GenericContainer<>(imageName); 57 | container.withExposedPorts(AZURITE_PORT); 58 | return container; 59 | } 60 | 61 | @Override 62 | protected Optional resolveProperty(String propertyName, GenericContainer container) { 63 | String value = switch (propertyName) { 64 | case ACCOUNT_ENDPOINT_PROPERTY -> "http://" + container.getHost() + ":" + container.getMappedPort(AZURITE_PORT) + "/" + ACCOUNT_NAME; 65 | case ACCOUNT_NAME_PROPERTY -> ACCOUNT_NAME; 66 | case ACCOUNT_KEY_PROPERTY -> ACCOUNT_KEY; 67 | default -> null; 68 | }; 69 | return Optional.ofNullable(value); 70 | } 71 | 72 | @Override 73 | protected boolean shouldAnswer(String propertyName, Map requestedProperties, Map testResourcesConfiguration) { 74 | return SUPPORTED_PROPERTIES.contains(propertyName); 75 | } 76 | } -------------------------------------------------------------------------------- /springboot-testresources-mailhog/src/main/java/io/cloudflight/testresources/springboot/mailhog/MailhogTestResourceProvider.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.mailhog; 2 | 3 | import io.micronaut.testresources.testcontainers.AbstractTestContainersProvider; 4 | import org.testcontainers.containers.GenericContainer; 5 | import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; 6 | import org.testcontainers.utility.DockerImageName; 7 | 8 | import java.util.*; 9 | 10 | /** 11 | * Test container provider for Mailhog. 12 | */ 13 | public class MailhogTestResourceProvider extends AbstractTestContainersProvider> { 14 | /** 15 | * Host name 16 | */ 17 | public static final String MAILHOG_HOST = "spring.mail.host"; 18 | /** 19 | * SMTP port 20 | */ 21 | public static final String MAILHOG_SMTP_PORT = "spring.mail.port"; 22 | /** 23 | * API URL 24 | */ 25 | public static final String MAILHOG_API_URL = TEST_RESOURCES_PROPERTY + ".mailhog.api-url"; 26 | /** 27 | * Simple name of the test resource. 28 | */ 29 | public static final String SIMPLE_NAME = "mailhog"; 30 | /** 31 | * Default Mailhog image. 32 | */ 33 | public static final String DEFAULT_IMAGE = "mailhog/mailhog"; 34 | 35 | /** 36 | * Mailhog SMTP port. 37 | */ 38 | public static final int SMTP_PORT = 1025; 39 | /** 40 | * Mailhog API port. 41 | */ 42 | public static final int API_PORT = 8025; 43 | 44 | private static final Set SUPPORTED_PROPERTIES = Set.of( 45 | MAILHOG_HOST, 46 | MAILHOG_API_URL, 47 | MAILHOG_SMTP_PORT 48 | ); 49 | 50 | @Override 51 | public List getResolvableProperties(Map> propertyEntries, Map testResourcesConfig) { 52 | return SUPPORTED_PROPERTIES.stream().toList(); 53 | } 54 | 55 | @Override 56 | protected String getSimpleName() { 57 | return SIMPLE_NAME; 58 | } 59 | 60 | @Override 61 | protected String getDefaultImageName() { 62 | return DEFAULT_IMAGE; 63 | } 64 | 65 | @Override 66 | protected GenericContainer createContainer(DockerImageName imageName, Map requestedProperties, Map testResourcesConfiguration) { 67 | var readyCheck = new HttpWaitStrategy() 68 | .forPort(API_PORT) 69 | .forPath("/api/v2/messages"); 70 | 71 | return new GenericContainer<>(imageName) 72 | .withExposedPorts(SMTP_PORT, API_PORT) 73 | .waitingFor(readyCheck) 74 | .withEnv("MH_SMTP_BIND_ADDR", "0.0.0.0:%d".formatted(SMTP_PORT)) 75 | .withEnv("MH_API_BIND_ADDR", "0.0.0.0:%d".formatted(API_PORT)); 76 | } 77 | 78 | @Override 79 | protected Optional resolveProperty(String propertyName, GenericContainer container) { 80 | if (MAILHOG_HOST.equals(propertyName)) { 81 | return Optional.of(container.getHost()); 82 | } 83 | if (MAILHOG_SMTP_PORT.equals(propertyName)) { 84 | return Optional.of(container.getMappedPort(SMTP_PORT).toString()); 85 | } 86 | if (MAILHOG_API_URL.equals(propertyName)) { 87 | return Optional.of("http://%s:%s".formatted(container.getHost(), container.getMappedPort(API_PORT).toString())); 88 | } 89 | 90 | return Optional.empty(); 91 | } 92 | 93 | @Override 94 | protected boolean shouldAnswer(String propertyName, Map requestedProperties, Map testResourcesConfiguration) { 95 | return SUPPORTED_PROPERTIES.contains(propertyName); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /springboot-testresources-jdbc/src/main/java/io/cloudflight/testresources/springboot/jdbc/AbstractJdbcTestResourceProvider.java: -------------------------------------------------------------------------------- 1 | package io.cloudflight.testresources.springboot.jdbc; 2 | 3 | import io.micronaut.testresources.testcontainers.AbstractTestContainersProvider; 4 | import org.testcontainers.containers.JdbcDatabaseContainer; 5 | 6 | import java.util.*; 7 | import java.util.function.Consumer; 8 | import java.util.stream.Collectors; 9 | 10 | /** 11 | * Superclass for JDBC test containers providers. 12 | * 13 | * @param the type of the container 14 | */ 15 | public abstract class AbstractJdbcTestResourceProvider> extends AbstractTestContainersProvider { 16 | private static final String PREFIX = "spring.datasource"; 17 | private static final String URL = "url"; 18 | private static final String USERNAME = "username"; 19 | private static final String PASSWORD = "password"; 20 | private static final String DRIVER = "driver-class-name"; 21 | private static final String DB_NAME = "db-name"; 22 | private static final String INIT_SCRIPT = "init-script-path"; 23 | 24 | private static final List SUPPORTED_LIST = Collections.unmodifiableList( 25 | Arrays.asList(URL, USERNAME, PASSWORD, DRIVER) 26 | ); 27 | 28 | @Override 29 | public List getResolvableProperties(Map> propertyEntries, Map testResourcesConfig) { 30 | return SUPPORTED_LIST.stream().map(p -> PREFIX + "." + p).collect(Collectors.toList()); 31 | } 32 | 33 | @Override 34 | public List getRequiredPropertyEntries() { 35 | return Collections.singletonList(PREFIX); 36 | } 37 | 38 | @Override 39 | public boolean shouldAnswer(String propertyName, Map requestedProperties, Map testResourcesConfiguration) { 40 | return propertyName.startsWith(PREFIX); 41 | } 42 | 43 | @Override 44 | protected Optional resolveProperty(String expression, T container) { 45 | String value = switch (datasourcePropertyFrom(expression)) { 46 | case URL -> container.getJdbcUrl(); 47 | case USERNAME -> container.getUsername(); 48 | case PASSWORD -> container.getPassword(); 49 | case DRIVER -> container.getDriverClassName(); 50 | default -> null; 51 | }; 52 | return Optional.ofNullable(value); 53 | } 54 | 55 | @Override 56 | protected void configureContainer(T container, Map properties, Map testResourcesConfiguration) { 57 | super.configureContainer(container, properties, testResourcesConfiguration); 58 | ifPresent(INIT_SCRIPT, testResourcesConfiguration, container::withInitScript); 59 | ifPresent(USERNAME, testResourcesConfiguration, container::withUsername); 60 | ifPresent(PASSWORD, testResourcesConfiguration, container::withPassword); 61 | ifPresent(DB_NAME, testResourcesConfiguration, container::withDatabaseName); 62 | } 63 | 64 | private void ifPresent(String key, Map testResourcesConfiguration, Consumer consumer) { 65 | Object value = testResourcesConfiguration.get("containers." + getSimpleName() + "." + key); 66 | if (value != null) { 67 | consumer.accept(value.toString()); 68 | } 69 | } 70 | 71 | /** 72 | * Extracts the datasource property from the given expression. 73 | * @param expression . 74 | * @return The datasource property. 75 | */ 76 | protected static String datasourcePropertyFrom(String expression) { 77 | String remainder = expression.substring(1 + expression.indexOf('.')); 78 | return remainder.substring(1 + remainder.indexOf(".")); 79 | } 80 | } -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2022 Cloudflight GmbH 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot TestResources 2 | 3 | [![License](https://img.shields.io/badge/License-Apache_2.0-green.svg)](https://opensource.org/licenses/Apache-2.0) 4 | [![Maven Central](https://img.shields.io/maven-central/v/io.cloudflight.testresources.springboot/springboot-testresources-client.svg?label=Maven%20Central)](https://search.maven.org/artifact/io.cloudflight.testresources.springboot/springboot-testresources-client) 5 | 6 | This project is a POC to combine [Micronaut's Test Resources](https://micronaut-projects.github.io/micronaut-test-resources/latest/guide/) project with Spring Boot. 7 | The project is still in very early stage and subject to bigger changes. 8 | 9 | # Concept 10 | 11 | [TestContainers](https://www.testcontainers.org/) is a great framework for testing your application code against infrastructure 12 | components like databases, message brokers and so forth. If you are developing [Spring Boot](https://spring.io/projects/spring-boot) 13 | applications, the [PlayTika TestContainers library](https://github.com/PlaytikaOSS/testcontainers-spring-boot/) is a helpful assistent 14 | to connect your Spring Application context with the TestContainers. 15 | 16 | Micronaut released a sub-project called [Test Resources](https://micronaut-projects.github.io/micronaut-test-resources/latest/guide/) which 17 | also comes with TestContainers under the hood but it provides a [test resources server](https://micronaut-projects.github.io/micronaut-test-resources/latest/guide/#architecture-server) 18 | which takes care of provisioning your containers during the build. This server can run standalone and 19 | can therefore survive independent builds and keep your containers alive. This in turn can significantly 20 | reduce your build times. 21 | 22 | This library combines those two approaches by implementing instances of [TestResourcesResolver](https://micronaut-projects.github.io/micronaut-test-resources/latest/guide/#implementing-test-resources), mapping 23 | to the default properties of Spring Boot, i.e. `spring.datasource.url`. A special `PropertySource` fetches the properties 24 | from the resource server. 25 | 26 | That way, together with the build plugins from Micronaut for Gradle and Maven, you can **easily test 27 | your Spring Boot applications using Micronaut Test Resources and TestContainers** and benefit 28 | from keeping your containers alive during builds. 29 | 30 | # How it works 31 | 32 | This library consists of two parts: 33 | 34 | * a thin client layer to be packaged with your Spring Boot application (for test cases) which configures your ApplicationContext 35 | * plugins for the test resources server for the various modules (MariaDB, MinIO) which configure the containers based on Spring Boot properties 36 | 37 | Follow the following steps, to get it running: 38 | 39 | First thing is to add the [Gradle Plugin](https://micronaut-projects.github.io/micronaut-gradle-plugin/latest/#test-resources) to your build. If you use Maven, 40 | please consult the [official documentation](https://micronaut-projects.github.io/micronaut-maven-plugin/latest/examples/test-resources.html). 41 | 42 | Go to your `build.gradle.kts`: 43 | 44 | ````kotlin 45 | plugins { 46 | id("io.micronaut.test-resources") version "3.7.7" 47 | } 48 | ```` 49 | 50 | In multi-module projects ensure that the plugin is applied on every module (especially on the one which is holding your Spring Boot application tests). 51 | 52 | Then, add this to your `gradle.properties`: 53 | 54 | ````properties 55 | micronautVersion=3.8.7 56 | ```` 57 | 58 | Next thing is to go to the module which contains your Spring Boot application 59 | and your `@SpringBootTest` and add the module `springboot-testresources-client` to the test-scope in your `build.gradle.kts`: 60 | 61 | ````kotlin 62 | dependencies { 63 | testRuntimeOnly("io.cloudflight.testresources.springboot:springboot-testresources-client:0.0.2") 64 | } 65 | ```` 66 | 67 | We strongly recommend to use `testRuntimeOnly` instead of `testImplementation` in order to avoid having Micronaut 68 | on your implementation classpath. 69 | 70 | Then, as a last step, you need to add one or more of our test modules to the `testResourcesImplementation` scope, which 71 | has been created by the Micronaut Test Resources plugin. 72 | 73 | Suppose you need a container for MariaDB, then add the following line: 74 | 75 | ````kotlin 76 | dependencies { 77 | testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-jdbc-mariadb:0.0.2") 78 | } 79 | ```` 80 | 81 | That's it. You can now run your `@SpringBootTest`. 82 | 83 | ## Full example 84 | 85 | To give you an even better overview, here is a full example of a minimalistic Spring Boot application with Spring Data + MariaDB. 86 | 87 | `build.gradle.kts` 88 | 89 | ````kotlin 90 | plugins { 91 | id("io.cloudflight.autoconfigure-gradle") version "0.9.4" 92 | id("io.micronaut.test-resources") version "3.7.7" 93 | } 94 | 95 | version = "0.1" 96 | group = "io.cloudflight" 97 | 98 | repositories { 99 | mavenCentral() 100 | } 101 | 102 | autoConfigure { 103 | java { 104 | languageVersion.set(JavaLanguageVersion.of(17)) 105 | } 106 | } 107 | 108 | dependencies { 109 | implementation("org.springframework.boot:spring-boot-starter-data-jpa:3.0.1") 110 | runtimeOnly("org.jetbrains.kotlin:kotlin-reflect") 111 | 112 | testImplementation("org.springframework.boot:spring-boot-starter-test:3.0.1") 113 | 114 | runtimeOnly("org.mariadb.jdbc:mariadb-java-client:3.0.6") 115 | 116 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1") 117 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1") 118 | testRuntimeOnly("io.cloudflight.testresources.springboot:springboot-testresources-client:0.0.2") 119 | testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-jdbc-mariadb:0.0.2") 120 | } 121 | ```` 122 | 123 | Then, create a `src/main/kotlin/io/cloudflight/Application.kt` 124 | 125 | ````kotlin 126 | package io.cloudflight 127 | 128 | import jakarta.persistence.Entity 129 | import jakarta.persistence.GeneratedValue 130 | import jakarta.persistence.Id 131 | import org.springframework.boot.autoconfigure.SpringBootApplication 132 | import org.springframework.boot.runApplication 133 | import org.springframework.data.jpa.repository.JpaRepository 134 | 135 | @SpringBootApplication 136 | class Application 137 | 138 | fun main(vararg args: String) { 139 | runApplication(args) 140 | } 141 | 142 | @Entity 143 | class Person(var name: String) { 144 | 145 | @Id 146 | @GeneratedValue 147 | var id: Long = 0 148 | } 149 | 150 | interface PersonRepository : JpaRepository 151 | ```` 152 | 153 | Configure the application to create a database on startup with Hibernate Auto-DDL in `src/main/resources/application.yaml`: 154 | 155 | ````yaml 156 | spring: 157 | jpa: 158 | hibernate: 159 | ddl-auto: create-drop 160 | ```` 161 | 162 | And finally, create a `src/test/kotlin/io/cloudflight/ApplicationTest.kt`: 163 | 164 | ````kotlin 165 | package io.cloudflight 166 | 167 | import org.junit.jupiter.api.Test 168 | import org.springframework.beans.factory.annotation.Autowired 169 | import org.springframework.boot.test.context.SpringBootTest 170 | 171 | @SpringBootTest 172 | class ApplicationTest( 173 | @Autowired private val repository: PersonRepository 174 | ) { 175 | 176 | @Test 177 | fun enterData() { 178 | repository.save(Person(name = "Klaus")) 179 | } 180 | } 181 | ```` 182 | 183 | If you now run the test, the following happens: 184 | 185 | 1. The Micronaut Test Resources starts the test resources server which can handle requests to configure a MariaDB docker container 186 | 2. The `ApplicationTest` picks up the [TestResourcesEnvironmentPostProcessor](https://github.com/cloudflightio/springboot-testresources/blob/master/springboot-testresources-client/src/main/java/io/cloudflight/testresources/springboot/client/TestResourcesEnvironmentPostProcessor.java) which uses the [TestResourcesPropertySource](https://github.com/cloudflightio/springboot-testresources/blob/master/springboot-testresources-client/src/main/java/io/cloudflight/testresources/springboot/client/TestResourcesPropertySource.java) to automatically configure properties like `spring.datasource.url` or `spring.datasource.username` based on the settings from the docker container. 187 | 3. The [MariaDbTestResourcesProvider](https://github.com/cloudflightio/springboot-testresources/blob/master/springboot-testresources-jdbc-mariadb/src/main/java/io/cloudflight/testresources/springboot/MariaDbTestResourcesProvider.java) starts the `MariaDBContainer` from the TestContainers project 188 | 4. The `ApplicationTest` connects its `PersonRepository` to exactly that database and can insert data to the DB. 189 | 190 | As you see, we did not have to configure properties like `spring.datasource.url` manually, that was all provided automatically. 191 | 192 | 193 | # Requirements 194 | 195 | Spring Boot Test Resources is compatible with Spring Boot 3.x but also with 2.7. 196 | It requires a JDK 17 (we could also easily publish it for JDK 11 or below, but we want you to push towards the latest LTS) 197 | 198 | Additionally, you need a plugin to start the test resources server. We have tested our library with the Micronaut Test Resources [Gradle Plugin](https://micronaut-projects.github.io/micronaut-gradle-plugin/latest/#test-resources), but it should also work fine for [Maven](https://micronaut-projects.github.io/micronaut-maven-plugin/latest/examples/test-resources.html). 199 | 200 | 201 | # Modules 202 | 203 | We currently only provide some few modules, as this library is still in a PoC phase, but the number of modules will grow over time. 204 | 205 | ## Common configuration 206 | 207 | For each module you can override the default image which is being pulled by adding 208 | 209 | ````yaml 210 | test-resources: 211 | containers: 212 | mariadb: 213 | image-name: mariadb:10.3 214 | ```` 215 | 216 | You can also always override any of the provided properties by adding any of those properties below `test-resources.containers.mariadb`. For example, 217 | if you want to use another `username` than the default one, you can add: 218 | 219 | ````yaml 220 | test-resources: 221 | containers: 222 | mariadb: 223 | image-name: mariadb:10.3 224 | username: myusername 225 | ```` 226 | 227 | This will create a MariaDB container based on `mariadb:10.3` with the default username `myusername`. 228 | 229 | ## MariaDB 230 | 231 | * **Module-ID**: mariadb 232 | * **Default-Image**: mariadb 233 | 234 | ````kotlin 235 | dependencies { 236 | testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-jdbc-mariadb:0.2.1") 237 | } 238 | ```` 239 | 240 | * **Provided properties**: 241 | * `spring.datasource.url` 242 | * `spring.datasource.username` 243 | * `spring.datasource.password` 244 | * `spring.datasource.driver-class-name` 245 | 246 | ## Microsoft SQL Server 247 | 248 | ### MSSQL specific: 249 | Make sure to add the following property to your ```application-test.yml``` to accept the MSSQL Server License Agreement: 250 | ```yml 251 | test-resources: 252 | containers: 253 | mssql: 254 | accept-license: true 255 | ``` 256 | 257 | * **Module-ID**: mssql 258 | * **Default-Image**: mcr.microsoft.com/mssql/server:2019-CU16-GDR1-ubuntu-20.04 259 | 260 | ````kotlin 261 | dependencies { 262 | testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-jdbc-mssql:0.2.1") 263 | } 264 | ```` 265 | 266 | * **Provided properties**: 267 | * `spring.datasource.url` 268 | * `spring.datasource.username` 269 | * `spring.datasource.password` 270 | * `spring.datasource.driver-class-name` 271 | 272 | ## Postgres 273 | 274 | * **Module-ID**: postgres 275 | * **Default-Image**: postgres 276 | 277 | ````kotlin 278 | dependencies { 279 | testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-jdbc-postgres:0.2.1") 280 | } 281 | ```` 282 | 283 | * **Provided properties**: 284 | * `spring.datasource.url` 285 | * `spring.datasource.username` 286 | * `spring.datasource.password` 287 | * `spring.datasource.driver-class-name` 288 | 289 | 290 | ## MinIO 291 | 292 | * **Module-ID**: minio 293 | * **Default-Image**: minio/minio 294 | 295 | ````kotlin 296 | dependencies { 297 | testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-minio:0.2.1") 298 | } 299 | ```` 300 | 301 | * **Provided properties**: 302 | * `minio.url` 303 | * `minio.access-key` 304 | * `minio.secret-key` 305 | * `minio.region` 306 | 307 | ## RabbitMQ 308 | 309 | * **Module-ID**: rabbitmq 310 | * **Default-Image**: rabbitmq 311 | 312 | ````kotlin 313 | dependencies { 314 | testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-rabbitmq:0.2.1") 315 | } 316 | ```` 317 | 318 | * **Provided properties**: 319 | * `spring.rabbitmq.host` 320 | * `spring.rabbitmq.port` 321 | * `spring.rabbitmq.username` 322 | * `spring.rabbitmq.password` 323 | 324 | ## Redis 325 | 326 | * **Module-ID**: redis 327 | * **Default-Image**: redis 328 | 329 | ````kotlin 330 | dependencies { 331 | testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-redis:0.2.1") 332 | } 333 | ```` 334 | 335 | * **Provided properties**: 336 | * `spring.data.redis.url` 337 | 338 | ## Azurite 339 | 340 | * **Module-ID**: azurite 341 | * **Default-Image**: mcr.microsoft.com/azure-storage/azurite 342 | 343 | ````kotlin 344 | dependencies { 345 | testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-azurite:0.2.1") 346 | } 347 | ```` 348 | 349 | * **Provided properties**: 350 | * `spring.cloud.azure.storage.blob.account-name` 351 | * `spring.cloud.azure.storage.blob.account-key` 352 | * `spring.cloud.azure.storage.blob.endpoint` 353 | 354 | ## Mailhog 355 | 356 | * **Module-ID**: mailhog 357 | * **Default-Image**: mailhog/mailhog 358 | 359 | ````kotlin 360 | dependencies { 361 | testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-mailhog:0.2.1") 362 | } 363 | ```` 364 | 365 | * **Provided properties**: 366 | * `spring.mail.host` 367 | * `spring.mail.port` 368 | * `test-resources.mailhog.api-url` 369 | 370 | ## Elasticsearch 371 | 372 | * **Module-ID**: elasticsearch 373 | * **Default-Image**: docker.elastic.co/elasticsearch/elasticsearch 374 | 375 | ````kotlin 376 | dependencies { 377 | testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-elasticsearch:0.2.1") 378 | } 379 | ```` 380 | 381 | * **Provided properties**: 382 | * `spring.elasticsearch.uris` 383 | * `spring.elasticsearch.password` --------------------------------------------------------------------------------