-
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.
- Loading branch information
Showing
6 changed files
with
60 additions
and
13 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...k-store/src/test/java/com/amigoscode/cohort2d/onlinebookstore/AbstractTestcontainers.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,37 @@ | ||
package com.amigoscode.cohort2d.onlinebookstore; | ||
|
||
import org.flywaydb.core.Flyway; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
|
||
@Testcontainers | ||
@ActiveProfiles("test") | ||
public abstract class AbstractTestcontainers { | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
Flyway flyway = Flyway | ||
.configure() | ||
.dataSource( | ||
postgreSQLContainer.getJdbcUrl(), | ||
postgreSQLContainer.getUsername(), | ||
postgreSQLContainer.getPassword() | ||
).load(); | ||
flyway.migrate(); | ||
} | ||
|
||
|
||
@Container | ||
protected static final PostgreSQLContainer<?> postgreSQLContainer = | ||
new PostgreSQLContainer<>("postgres:latest") | ||
.withDatabaseName("admin-unit-test") | ||
.withUsername("admin") | ||
.withPassword("1234"); | ||
|
||
|
||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...-book-store/src/test/java/com/amigoscode/cohort2d/onlinebookstore/TestcontainersTest.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,15 @@ | ||
package com.amigoscode.cohort2d.onlinebookstore; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class TestcontainersTest extends AbstractTestcontainers { | ||
|
||
@Test | ||
void canStartPostgresDB() { | ||
assertThat(postgreSQLContainer.isRunning()).isTrue(); | ||
assertThat(postgreSQLContainer.isCreated()).isTrue(); | ||
} | ||
|
||
} |
6 changes: 2 additions & 4 deletions
6
...re/src/test/java/com/amigoscode/cohort2d/onlinebookstore/author/AuthorRepositoryTest.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
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
5 changes: 2 additions & 3 deletions
5
...rc/test/java/com/amigoscode/cohort2d/onlinebookstore/category/CategoryRepositoryTest.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
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