Library containing Spring Boot starters which manage lifecycle (start/stop) of testcontainers.
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)
Disclaimer: by using this testcontainer you accept the EULA for mssql docker image as required here.
Include the dependency:
<dependency>
<groupId>com.infobip</groupId>
<artifactId>infobip-mssql-testcontainers-spring-boot-starter</artifactId>
<version>${infobip-mssql-testcontainers-spring-boot-starter.version}</version>
<scope>test</scope>
</dependency>
jTDS:
spring:
datasource:
url: jdbc:jtds:sqlserver://<host>:<port>/FooBarDb
username: SA
password: A_Str0ng_Required_Password
Microsoft driver:
spring:
datasource:
url: jdbc:sqlserver://<host>:<port>;database=FooBarDb
username: SA
password: A_Str0ng_Required_Password
Logical database is automatically created.
Container IP address is resolved based on running host, meaning on local machine <host>
will resolve to localhost
while inside Docker placeholder will resolve to containerIp
.
Docker container is mapped on random port so <port>
placeholder is used and will be automatically substituted.
Add the following profile:
<profiles>
<profile>
<id>development</id>
<dependencies>
<dependency>
<groupId>com.infobip</groupId>
<artifactId>infobip-mssql-testcontainers-spring-boot-starter</artifactId>
<version>${infobip-mssql-testcontainers-spring-boot-starter.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
Before starting the application locally, activate development profile:
and update your local configuration (e.g. application-development.yaml):
jTDS:
spring:
datasource:
url: jdbc:jtds:sqlserver://<host>:<port>/FooBarDb_test_${user.name}
username: SA
password: A_Str0ng_Required_Password
Microsoft driver:
spring:
datasource:
url: jdbc:sqlserver://<host>:<port>;database=FooBarDb_test_${user.name}
username: SA
password: A_Str0ng_Required_Password
To change the docker image used simply add the following property (e.g. in yaml):
testcontainers.mssql.docker.image: mcr.microsoft.com/mssql/server:2017-CU12
Include the dependency:
<dependency>
<groupId>com.infobip</groupId>
<artifactId>infobip-postgresql-testcontainers-spring-boot-starter</artifactId>
<version>${infobip-postgresql-testcontainers-spring-boot-starter.version}</version>
<scope>test</scope>
</dependency>
Configuration:
spring:
datasource:
url: jdbc:postgresql://<host>:<port>/FooBarDb
username: test
password: test
Logical database is automatically created.
Container IP address is resolved based on running host, meaning on local machine <host>
will resolve to localhost
while inside Docker placeholder will resolve to containerIp
.
Docker container is mapped on random port so <port>
placeholder is used and will be automatically substituted.
Add the following profile:
<profiles>
<profile>
<id>development</id>
<dependencies>
<dependency>
<groupId>com.infobip</groupId>
<artifactId>infobip-postgresql-testcontainers-spring-boot-starter</artifactId>
<version>${infobip-postgresql-testcontainers-spring-boot-starter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
Before starting the application locally, activate development profile:
and update your local configuration (e.g. application-development.yaml):
spring:
datasource:
url: jdbc:postgresql://<host>:<port>/FooBarDb_test_${user.name}
username: test
password: test
To change the docker image used simply add the following property (e.g. in yaml):
testcontainers.postgresql.docker.image: postgres:10
Include the dependency:
<dependency>
<groupId>com.infobip</groupId>
<artifactId>infobip-redis-testcontainers-spring-boot-starter</artifactId>
<version>${infobip-redis-testcontainers-spring-boot-starter.version}</version>
<scope>test</scope>
</dependency>
Configuration:
spring:
redis:
url: redis://<host>:<port>
Container IP address is resolved based on running host, meaning on local machine <host>
will resolve to localhost
while inside Docker placeholder will resolve to containerIp
.
Docker container is mapped on random port so <port>
placeholder is used and will be automatically substituted.
Add the following profile:
<profiles>
<profile>
<id>development</id>
<dependencies>
<dependency>
<groupId>com.infobip</groupId>
<artifactId>infobip-redis-testcontainers-spring-boot-starter</artifactId>
<version>${infobip-redis-testcontainers-spring-boot-starter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
Before starting the application locally, activate development profile:
and update your local configuration (e.g. application-development.yaml):
spring:
redis:
url: redis://<host>:<port>
To change the docker image used simply add the following property (e.g. in yaml):
testcontainers.redis.docker.image: redis:5.0.7-alpine
Format: <topicName>:<numPartitions>:<replicationFactor>
testcontainers.kafka.topics: test-topic:1:1, test-topic-2:1:1
Include the dependency:
<dependency>
<groupId>com.infobip</groupId>
<artifactId>infobip-kafka-testcontainers-spring-boot-starter</artifactId>
<version>${infobip-kafka-testcontainers-spring-boot-starter.version}</version>
<scope>test</scope>
</dependency>
Configuration:
spring:
kafka:
bootstrap-servers: <host>:<port>
Logical database is automatically created.
Container IP address is resolved based on running host, meaning on local machine <host>
will resolve to localhost
while inside Docker placeholder will resolve to containerIp
.
Docker container is mapped on random port so <port>
placeholder is used and will be automatically substituted.
Add the following profile:
<profiles>
<profile>
<id>development</id>
<dependencies>
<dependency>
<groupId>com.infobip</groupId>
<artifactId>infobip-kafka-testcontainers-spring-boot-starter</artifactId>
<version>${infobip-kafka-testcontainers-spring-boot-starter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
Before starting the application locally, activate development profile:
and update your local configuration (e.g. application-development.yaml):
spring:
kafka:
bootstrap-servers: <host>:<port>
To change the docker image version used simply add the following property (e.g. in yaml):
testcontainers.kafka.docker.image.version: 2.1.0
Include the dependency:
<dependency>
<groupId>com.infobip</groupId>
<artifactId>infobip-rabbitmq-testcontainers-spring-boot-starter</artifactId>
<version>${infobip-rabbitmq-testcontainers-spring-boot-starter.version}</version>
<scope>test</scope>
</dependency>
To configure RabbitMq in tests you need to create it's configuration for example:
@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 nametest.queue
testExchange
creates exchange with nametest.exchange
bindToTestExchange
tells Rabbit to send any message sent to test exchange, with key of valuetest.key.#
to our test queue
Important: 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:
<profiles>
<profile>
<id>development</id>
<dependencies>
<dependency>
<groupId>com.infobip</groupId>
<artifactId>infobip-rabbitmq-testcontainers-spring-boot-starter</artifactId>
<version>${infobip-rabbitmq-testcontainers-spring-boot-starter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
Before starting the application locally, activate development profile:
To change the docker image used simply add the following property (e.g. in yaml):
testcontainers.rabbit.docker.image: rabbitmq:3.6.14-alpine
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.