-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Veselovnd88/feature/47-test-container
feature/47: testcontainers refactoring
- Loading branch information
Showing
8 changed files
with
65 additions
and
36 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/test/java/ru/veselov/companybot/config/EnableTestContainers.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,14 @@ | ||
package ru.veselov.companybot.config; | ||
|
||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ContextConfiguration(initializers = PostgresTestContainersInitializer.class) | ||
public @interface EnableTestContainers { | ||
} |
25 changes: 0 additions & 25 deletions
25
src/test/java/ru/veselov/companybot/config/PostgresTestContainersConfiguration.java
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
src/test/java/ru/veselov/companybot/config/PostgresTestContainersInitializer.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,35 @@ | ||
package ru.veselov.companybot.config; | ||
|
||
import org.springframework.boot.test.util.TestPropertyValues; | ||
import org.springframework.context.ApplicationContextInitializer; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
|
||
|
||
/** | ||
* Configuration class for managing test containers, it this situation we don't need use | ||
* {@link org.testcontainers.junit.jupiter.Testcontainers } annotation | ||
* on class, and {@link org.testcontainers.junit.jupiter.Container} annotation on the container itself. | ||
* In this class we will start containers that will be available for all our tests | ||
*/ | ||
public class PostgresTestContainersInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
|
||
static PostgreSQLContainer<?> postgresContainer = new PostgreSQLContainer<>("postgres:16") | ||
.withDatabaseName("cbotDB"); | ||
|
||
static { | ||
postgresContainer.start(); | ||
} | ||
|
||
|
||
//initialize environment before dynamic property source applied | ||
@Override | ||
public void initialize(ConfigurableApplicationContext ctx) { | ||
TestPropertyValues.of( | ||
"spring.liquibase.enabled=true", | ||
"spring.datasource.url=" + postgresContainer.getJdbcUrl(), | ||
"spring.datasource.username=" + postgresContainer.getUsername(), | ||
"spring.datasource.password=" + postgresContainer.getPassword()).applyTo(ctx.getEnvironment()); | ||
} | ||
|
||
} |
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
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
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