Merge pull request #11539 from hkhan/JAVA-8703-fix-extension-live-test
[JAVA-8703] Fix Live test to allow isolated execution
This commit is contained in:
commit
cd7486dd27
|
@ -63,7 +63,7 @@
|
|||
</build>
|
||||
|
||||
<properties>
|
||||
<testcontainers.version>1.12.2</testcontainers.version>
|
||||
<testcontainers.version>1.16.2</testcontainers.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -4,13 +4,17 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("pg")
|
||||
@ExtendWith(PostgreSQLExtension.class)
|
||||
@DirtiesContext
|
||||
public class ArticleTestFixtureLiveTest {
|
||||
|
||||
@Autowired
|
||||
|
@ -23,8 +27,11 @@ public class ArticleTestFixtureLiveTest {
|
|||
article.setContent("Today's applications...");
|
||||
|
||||
articleRepository.save(article);
|
||||
Article persisted = articleRepository.findAll().get(0);
|
||||
assertThat(persisted.getId()).isNotNull();
|
||||
|
||||
List<Article> allArticles = articleRepository.findAll();
|
||||
assertThat(allArticles).hasSize(1);
|
||||
|
||||
Article persisted = allArticles.get(0);
|
||||
assertThat(persisted.getTitle()).isEqualTo("A Guide to @DynamicPropertySource in Spring");
|
||||
assertThat(persisted.getContent()).isEqualTo("Today's applications...");
|
||||
}
|
||||
|
|
|
@ -18,14 +18,14 @@ public class PostgreSQLExtension implements BeforeAllCallback, AfterAllCallback
|
|||
.withExposedPorts(5432);
|
||||
|
||||
postgres.start();
|
||||
String jdbcUrl = String.format("jdbc:postgresql://localhost:%d/prop", postgres.getFirstMappedPort());
|
||||
System.setProperty("spring.datasource.url", jdbcUrl);
|
||||
System.setProperty("spring.datasource.username", "postgres");
|
||||
System.setProperty("spring.datasource.password", "pass");
|
||||
|
||||
System.setProperty("spring.datasource.url", postgres.getJdbcUrl());
|
||||
System.setProperty("spring.datasource.username", postgres.getUsername());
|
||||
System.setProperty("spring.datasource.password", postgres.getPassword());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterAll(ExtensionContext context) {
|
||||
postgres.stop();
|
||||
// do nothing, Testcontainers handles container shutdown
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue