Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/infobip/infobip-testcontainers-spring-boot-starter
Infobip TestContainers Spring Boot Starter provides Spring Boot starters that ease the use of Testcontainers in test and local development scenarios.
https://github.com/infobip/infobip-testcontainers-spring-boot-starter
Last synced: 4 days ago
JSON representation
Infobip TestContainers Spring Boot Starter provides Spring Boot starters that ease the use of Testcontainers in test and local development scenarios.
- Host: GitHub
- URL: https://github.com/infobip/infobip-testcontainers-spring-boot-starter
- Owner: infobip
- License: apache-2.0
- Created: 2020-12-16T07:40:21.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-07-18T14:59:33.000Z (4 months ago)
- Last Synced: 2024-07-19T15:13:18.559Z (4 months ago)
- Language: Java
- Size: 271 KB
- Stars: 11
- Watchers: 14
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Infobip Testcontainers Spring Boot Starter
[![](https://github.com/infobip/infobip-testcontainers-spring-boot-starter/workflows/maven/badge.svg)](https://github.com/infobip/infobip-testcontainers-spring-boot-starter/actions?query=workflow%3Amaven)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.infobip/infobip-testcontainers-spring-boot-starter/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.infobip/infobip-testcontainers-spring-boot-starter)
[![Coverage Status](https://coveralls.io/repos/github/infobip/infobip-testcontainers-spring-boot-starter/badge.svg?branch=master)](https://coveralls.io/github/infobip/infobip-testcontainers-spring-boot-starter?branch=master)Library containing Spring Boot starters which manage lifecycle (start/stop) of [testcontainers](https://www.testcontainers.org/).
Usual use cases include:
- tests (container is started during test spring context initialization and stopped during context destruction)
- local development (e.g. to remove manual setup of local DB)## Contents
* [Changelog](#Changelog)
* [Usage](#Usage)
* [General](#General)
* [Reusable](#Reusable)
* [MSSQL](#MSSQL)
* [Tests](#MSSQLTests)
* [Local development](#MSSQLLocalDevelopment)
* [Docker image version](#MSSQLDockerImage)
* [Initialization script](#MSSQLInitScript)
* [MySQL](#MySQL)
* [Tests](#MySQLTests)
* [Local development](#MySQLLocalDevelopment)
* [Docker image version](#MySQLDockerImage)
* [Initialization script](#MySQLInitScript)
* [PostgreSQL](#PostgreSQL)
* [Tests](#PostgreSQLTests)
* [Local development](#PostgreSQLLocalDevelopment)
* [Docker image version](#PostgreSQLDockerImage)
* [Initialization script](#PostgreSQLInitScript)
* [Redis](#Redis)
* [Tests](#RedisTests)
* [Local development](#RedisDevelopment)
* [Docker image version](#RedisDockerImage)
* [Kafka](#Kafka)
* [Automatic topic creation](#KafkaTopic)
* [Tests](#KafkaTests)
* [Local development](#KafkaLocalDevelopment)
* [Docker image version](#KafkaDockerImageVersion)
* [RabbitMQ](#RabbitMq)
* [Tests](#RabbitMqTests)
* [Local development](#RabbitMqLocalDevelopment)
* [Docker image version](#RabbitMqDockerImage)
* [ClickHouse](#ClickHouse)
* [Tests](#ClickHouseTests)
* [Local development](#ClickHouseLocalDevelopment)
* [Docker image version](#ClickHouseDockerImage)
* [Initialization script](#ClickHouseInitScript)For changes check the [changelog](CHANGELOG.md).
This library tries to reuse existing Spring Boot configuration classes and enhance their behaviour by performing some extra steps around them.
Generally, in cases where port placeholders are used (``), the library will make sure that the appropriate Docker container is started on
a randomly selected open port and that the selected value will be used by the configuration in the runtime.
You can use a concrete value instead of the placeholder - in that case the library will attempt to start the container on the specified port.
### Reusable
If [reuse is enabled](https://java.testcontainers.org/features/reuse/) this project automatically marks all created containers for reuse.**Disclaimer**: by using this testcontainer you accept the EULA for mssql docker image as [required here](https://hub.docker.com/_/microsoft-mssql-server).
Include the dependency:
```xml
com.infobip
infobip-mssql-testcontainers-spring-boot-starter
${infobip-mssql-testcontainers-spring-boot-starter.version}
test```
jTDS:
```yaml
spring:
datasource:
url: jdbc:jtds:sqlserver://:/FooBarDb
```Microsoft driver:
```yaml
spring:
datasource:
url: jdbc:sqlserver://:;database=FooBarDb
```Logical database is automatically created.
Container IP address is resolved based on running host, meaning on local machine `` will resolve to `localhost`
while inside Docker placeholder will resolve to `containerIp`.
When `` placeholder is used, container will be mapped on random port and automatically substituted.Add the following profile:
```xml
development
com.infobip
infobip-mssql-testcontainers-spring-boot-starter
${infobip-mssql-testcontainers-spring-boot-starter.version}
```
Before starting the application locally, activate development profile:
![profile.png](profile.png)
and update your local configuration (e.g. application-development.yaml):
jTDS:
```yaml
spring:
datasource:
url: jdbc:jtds:sqlserver://:/FooBarDb_test_${user.name}
```Microsoft driver:
```yaml
spring:
datasource:
url: jdbc:sqlserver://:;database=FooBarDb_test_${user.name}
```To change the docker image used simply add the following property (e.g. in yaml):
```yaml
testcontainers.mssql.docker.image: mcr.microsoft.com/mssql/server:2017-CU12
```To add an SQL script with which the container will be initialized with add the following property (e.g. in yaml):
```yaml
testcontainers.mssql.init-script: db/init-script.sql
```Include the dependency:
```xml
com.infobip
infobip-mysql-testcontainers-spring-boot-starter
${infobip-mysql-testcontainers-spring-boot-starter.version}
test```
Configuration:
```yaml
spring:
datasource:
url: jdbc:mysql://:/FooBarDb
username: test
password: test
```Logical database is automatically created.
Container IP address is resolved based on running host, meaning on local machine `` will resolve to `localhost`
while inside Docker placeholder will resolve to `containerIp`.
When `` placeholder is used, container will be mapped on random port and automatically substituted.Add the following profile:
```xml
development
com.infobip
infobip-mysql-testcontainers-spring-boot-starter
${infobip-mysql-testcontainers-spring-boot-starter.version}
test
```
Before starting the application locally, activate development profile:
![profile.png](profile.png)
and update your local configuration (e.g. application-development.yaml):
```yaml
spring:
datasource:
url: jdbc:mysql://:/FooBarDb_test_${user.name}
username: test
password: test
```To change the docker image used simply add the following property (e.g. in yaml):
```yaml
testcontainers.mysql.docker.image: mysql:5.7.34
```To add an SQL script with which the container will be initialized with add the following property (e.g. in yaml):
```yaml
testcontainers.mysql.init-script: db/init-script.sql
```Include the dependency:
```xml
com.infobip
infobip-postgresql-testcontainers-spring-boot-starter
${infobip-postgresql-testcontainers-spring-boot-starter.version}
test```
Configuration:
```yaml
spring:
datasource:
url: jdbc:postgresql://:/FooBarDb
username: test
password: test
```Logical database is automatically created.
Container IP address is resolved based on running host, meaning on local machine `` will resolve to `localhost`
while inside Docker placeholder will resolve to `containerIp`.
When `` placeholder is used, container will be mapped on random port and automatically substituted.Add the following profile:
```xml
development
com.infobip
infobip-postgresql-testcontainers-spring-boot-starter
${infobip-postgresql-testcontainers-spring-boot-starter.version}
test
```
Before starting the application locally, activate development profile:
![profile.png](profile.png)
and update your local configuration (e.g. application-development.yaml):
```yaml
spring:
datasource:
url: jdbc:postgresql://:/FooBarDb_test_${user.name}
username: test
password: test
```To change the docker image used simply add the following property (e.g. in yaml):
```yaml
testcontainers.postgresql.docker.image: postgres:15
```To add an SQL script with which the container will be initialized with add the following property (e.g. in yaml):
```yaml
testcontainers.postgresql.init-script: db/init-script.sql
```Include the dependency:
```xml
com.infobip
infobip-redis-testcontainers-spring-boot-starter
${infobip-redis-testcontainers-spring-boot-starter.version}
test```
Configuration:
```yaml
spring:
redis:
url: redis://:
```Container IP address is resolved based on running host, meaning on local machine `` will resolve to `localhost`
while inside Docker placeholder will resolve to `containerIp`.
When `` placeholder is used, container will be mapped on random port and automatically substituted.Add the following profile:
```xml
development
com.infobip
infobip-redis-testcontainers-spring-boot-starter
${infobip-redis-testcontainers-spring-boot-starter.version}
test
```
Before starting the application locally, activate development profile:
![profile.png](profile.png)
and update your local configuration (e.g. application-development.yaml):
```yaml
spring:
redis:
url: redis://:
```To change the docker image used simply add the following property (e.g. in yaml):
```yaml
testcontainers.redis.docker.image: redis:5.0.7-alpine
```Format: `::`
```yaml
testcontainers.kafka.topics: test-topic:1:1, test-topic-2:1:1
```Include the dependency:
```xml
com.infobip
infobip-kafka-testcontainers-spring-boot-starter
${infobip-kafka-testcontainers-spring-boot-starter.version}
test```
Configuration:
```yaml
spring:
kafka:
bootstrap-servers: :
```Logical database is automatically created.
Container IP address is resolved based on running host, meaning on local machine `` will resolve to `localhost`
while inside Docker placeholder will resolve to `containerIp`.
When `` placeholder is used, container will be mapped on random port and automatically substituted.Add the following profile:
```xml
development
com.infobip
infobip-kafka-testcontainers-spring-boot-starter
${infobip-kafka-testcontainers-spring-boot-starter.version}
test
```
Before starting the application locally, activate development profile:
![profile.png](profile.png)
and update your local configuration (e.g. application-development.yaml):
```yaml
spring:
kafka:
bootstrap-servers: :
```To change the docker image version used simply add the following property (e.g. in yaml):
```yaml
testcontainers.kafka.docker.image.version: 2.1.0
```Include the dependency:
```xml
com.infobip
infobip-rabbitmq-testcontainers-spring-boot-starter
${infobip-rabbitmq-testcontainers-spring-boot-starter.version}
test```
#### Test Configuration:
To configure RabbitMq in tests you need to create it's configuration for example:
```java
@Configuration
@Profile({"test", "development"})
public class RabbitConfigTestEnv {@Bean
public Queue testQueue() {
return QueueBuilder.durable("test.queue").build();
}@Bean
public TopicExchange testExchange() {
return new TopicExchange("test.exchange");
}@Bean
public Binding bindToTestExchange() {
return bind(testQueue()).to(testExchange()).with("test.key.#");
}
}
```This class should live inside test files and there you can create queues, exchanges and key routing bindings or receivers.
In this example method:
* `testQueue` creates queue with name `test.queue`
* `testExchange` creates exchange with name `test.exchange`
* `bindToTestExchange` tells Rabbit to send any message sent to test exchange, with key of value `test.key.#` to our test queueImportant: Queues are declared in Rabbit only after some message is sent to the queue.
If you log into `docker` and try to find queue, it won't be listed if no message was sent to it.Add the following profile:
```xml
development
com.infobip
infobip-rabbitmq-testcontainers-spring-boot-starter
${infobip-rabbitmq-testcontainers-spring-boot-starter.version}
test
```
Before starting the application locally, activate development profile:
![profile.png](profile.png)
To change the docker image used simply add the following property (e.g. in yaml):
```yaml
testcontainers.rabbit.docker.image: rabbitmq:3.6.14-alpine
```
### ClickHouseInclude the dependency:
```xml
com.infobip
infobip-clickhouse-testcontainers-spring-boot-starter
${infobip-clickhouse-testcontainers-spring-boot-starter.version}
test```
Add the following profile:
```xml
development
com.infobip
infobip-clickhouse-testcontainers-spring-boot-starter
${infobip-clickhouse-testcontainers-spring-boot-starter.version}
test
```
Before starting the application locally, activate development profile:
![profile.png](profile.png)
and update your local configuration (e.g. application-development.yaml):
```yaml
spring:
datasource:
jdbc-url: :
```
In case your datasource configuration is different from default one you can provide custom configuration property path
```yaml
testcontainers.clickhouse.custom-path: "spring.datasource.clickhouse"
```
in this case your configuration would look like this```yaml
spring:
datasource:
clickhouse:
jdbc-url: :
```To change the docker image used simply add the following property (e.g. in yaml):
```yaml
testcontainers.clickhouse.docker.image: clickhouse:latest
```To add an SQL script with which the container will be initialized with add the following property (e.g. in yaml):
```yaml
testcontainers.clickhouse.init-script: db/init-script.sql
```If you have an idea for a new feature or want to report a bug please use the issue tracker.
Pull requests are welcome!
This library is licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).