-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
263 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
### 3.2.0 | ||
|
||
#### ClickHouse: | ||
* Added support for ClickHouse | ||
* Custom path for ClickHouse jdbc properties can be provided under `testcontainers.clickhouse.custom-path` property. In case custom path is not provided, properties under `spring.datasource` will be used | ||
|
||
### 3.1.0 | ||
|
||
#### MSSQL: | ||
* username and password are now automatically injected and don't need to be explicitly set in configuration (note that they are not overriden if they do exist) | ||
* `spring.flyway` and `spring.r2dbc` are now supported |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
infobip-clickhouse-testcontainers-spring-boot-starter/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.infobip</groupId> | ||
<artifactId>infobip-testcontainers-spring-boot-starter</artifactId> | ||
<version>3.1.9-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>infobip-clickhouse-testcontainers-spring-boot-starter</artifactId> | ||
|
||
<properties> | ||
<clickhouse-jdbc.version>0.2.4</clickhouse-jdbc.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>infobip-testcontainers-common</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
|
||
<!-- LIBS --> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>clickhouse</artifactId> | ||
<version>${testcontainers.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ru.yandex.clickhouse</groupId> | ||
<artifactId>clickhouse-jdbc</artifactId> | ||
<version>${clickhouse-jdbc.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-jdbc</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
33 changes: 33 additions & 0 deletions
33
...ain/java/com/infobip/testcontainers/spring/clickhouse/ClickhouseContainerInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.infobip.testcontainers.spring.clickhouse; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import com.infobip.testcontainers.InitializerBase; | ||
import org.springframework.boot.test.util.TestPropertyValues; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.core.env.Environment; | ||
|
||
public class ClickhouseContainerInitializer extends InitializerBase<ClickhouseContainerWrapper> { | ||
|
||
@Override | ||
public void initialize(ConfigurableApplicationContext applicationContext) { | ||
Environment environment = applicationContext.getEnvironment(); | ||
Optional<String> customPropertyPath = Optional.ofNullable(environment.getProperty("testcontainers.clickhouse.custom-path")); | ||
String jdbcUrlPropertyPath = customPropertyPath.orElse( "spring.datasource") + ".jdbc-url"; | ||
String jdbcUrlValue = Objects.requireNonNull(environment.getProperty(jdbcUrlPropertyPath)); | ||
ClickhouseContainerWrapper container = Optional.ofNullable( | ||
environment.getProperty("testcontainers.clickhouse.docker.image.version")) | ||
.map(ClickhouseContainerWrapper::new) | ||
.orElseGet(ClickhouseContainerWrapper::new); | ||
|
||
start(container); | ||
String url = jdbcUrlValue.replace("<host>", container.getContainerIpAddress()) | ||
.replace("<port>", container.getMappedPort(ClickhouseContainerWrapper.HTTP_PORT) | ||
.toString()); | ||
TestPropertyValues values = TestPropertyValues.of( | ||
String.format("%s=%s", jdbcUrlPropertyPath, url)); | ||
values.applyTo(applicationContext); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...rc/main/java/com/infobip/testcontainers/spring/clickhouse/ClickhouseContainerWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.infobip.testcontainers.spring.clickhouse; | ||
|
||
import org.testcontainers.containers.ClickHouseContainer; | ||
|
||
public class ClickhouseContainerWrapper extends ClickHouseContainer { | ||
|
||
public ClickhouseContainerWrapper() { | ||
} | ||
|
||
public ClickhouseContainerWrapper(String confluentPlatformVersion) { | ||
super(confluentPlatformVersion); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...lickhouse-testcontainers-spring-boot-starter/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
org.springframework.context.ApplicationContextInitializer=com.infobip.testcontainers.spring.clickhouse.ClickhouseContainerInitializer | ||
org.springframework.context.ApplicationListener=com.infobip.testcontainers.spring.clickhouse.ClickhouseContainerInitializer |
33 changes: 33 additions & 0 deletions
33
...java/com/infobip/testcontainers/spring/clickhouse/ClickhouseContainerInitializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.infobip.testcontainers.spring.clickhouse; | ||
|
||
import static org.assertj.core.api.BDDAssertions.then; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.TestConstructor; | ||
|
||
@AllArgsConstructor | ||
@ActiveProfiles("test") | ||
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) | ||
@SpringBootTest(classes = Main.class) | ||
class ClickhouseContainerInitializerTest { | ||
|
||
DataSource dataSource; | ||
|
||
@Test | ||
void shouldCreateContainer() { | ||
//given | ||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); | ||
|
||
//when | ||
String result = jdbcTemplate.queryForObject("SELECT 1", String.class); | ||
|
||
//then | ||
then(result).isEqualTo("1"); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...-starter/src/test/java/com/infobip/testcontainers/spring/clickhouse/DataSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.infobip.testcontainers.spring.clickhouse; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.springframework.boot.jdbc.DataSourceBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.env.Environment; | ||
|
||
@Configuration | ||
@AllArgsConstructor | ||
public class DataSourceConfig { | ||
|
||
private final Environment environment; | ||
|
||
@Bean | ||
public DataSource getDataSource() { | ||
String url = environment.getProperty("spring.datasource.clickhouse.jdbc-url"); | ||
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create(); | ||
dataSourceBuilder.driverClassName("ru.yandex.clickhouse.ClickHouseDriver"); | ||
dataSourceBuilder.url(url); | ||
return dataSourceBuilder.build(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...-spring-boot-starter/src/test/java/com/infobip/testcontainers/spring/clickhouse/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.infobip.testcontainers.spring.clickhouse; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
|
||
@SpringBootApplication | ||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
new SpringApplicationBuilder(Main.class).run(args); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ip-clickhouse-testcontainers-spring-boot-starter/src/test/resources/application-test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
spring: | ||
datasource: | ||
clickhouse: | ||
jdbc-url: jdbc:clickhouse://<host>:<port> | ||
|
||
testcontainers: | ||
clickhouse: | ||
custom-path: "spring.datasource.clickhouse" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters