Skip to content

Commit

Permalink
SD/feat/#55 removed by mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
sarajaned authored and JaafarF committed Aug 12, 2023
1 parent 68158ce commit 9c9a30f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 13 deletions.
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");



}
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();
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.amigoscode.cohort2d.onlinebookstore.author;

import com.amigoscode.cohort2d.onlinebookstore.AbstractTestcontainers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.ActiveProfiles;

import static org.assertj.core.api.Assertions.assertThat;

@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ActiveProfiles("test")
class AuthorRepositoryTest {
class AuthorRepositoryTest extends AbstractTestcontainers {

@Autowired
private AuthorRepository underTest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.amigoscode.cohort2d.onlinebookstore.book;

import com.amigoscode.cohort2d.onlinebookstore.AbstractTestcontainers;
import com.amigoscode.cohort2d.onlinebookstore.author.Author;
import com.amigoscode.cohort2d.onlinebookstore.author.AuthorRepository;
import com.amigoscode.cohort2d.onlinebookstore.category.Category;
Expand All @@ -9,7 +10,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.ActiveProfiles;

import java.math.BigDecimal;
import java.time.LocalDate;
Expand All @@ -20,8 +20,7 @@

@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ActiveProfiles("test")
class BookRepositoryTest {
class BookRepositoryTest extends AbstractTestcontainers {

@Autowired
private BookRepository underTest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.amigoscode.cohort2d.onlinebookstore.category;

import com.amigoscode.cohort2d.onlinebookstore.AbstractTestcontainers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.ActiveProfiles;

import static org.assertj.core.api.Assertions.assertThat;

@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ActiveProfiles("test")
class CategoryRepositoryTest {
class CategoryRepositoryTest extends AbstractTestcontainers {

@Autowired
private CategoryRepository underTest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.amigoscode.cohort2d.onlinebookstore.user;

import com.amigoscode.cohort2d.onlinebookstore.AbstractTestcontainers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.ActiveProfiles;

import java.util.Collections;
import java.util.UUID;
Expand All @@ -14,8 +14,7 @@

@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ActiveProfiles("test")
class UserRepositoryTest {
class UserRepositoryTest extends AbstractTestcontainers {

@Autowired
private UserRepository underTest;
Expand Down

0 comments on commit 9c9a30f

Please sign in to comment.