/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
testing-modules/spring-testing-2/src/test/java/com/baeldung/dynamicproperties/PostgreSQLExtension.java
31 строка
1 KB
Haroon Khan
[JAVA-8703] Fix Live test to allow isolated execution
02 дек 2021, 01:41
02 дек 2021, 01:41
1ff29cf
Код
Авторство
О чём код?
package com.baeldung.dynamicproperties; import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.ExtensionContext; import org.testcontainers.containers.PostgreSQLContainer; public class PostgreSQLExtension implements BeforeAllCallback, AfterAllCallback { private PostgreSQLContainer<?> postgres; @Override public void beforeAll(ExtensionContext context) { postgres = new PostgreSQLContainer<>("postgres:11") .withDatabaseName("prop") .withUsername("postgres") .withPassword("pass") .withExposedPorts(5432); postgres.start(); 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) { // do nothing, Testcontainers handles container shutdown } }