/
AAV
/
Book_Store
Обзор
Документация
Войти
/
AAV
/
Book_Store
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/test/java/ru/aav/IntegrationTest.java
59 строк
3 KB
AnciborAV
Initial commit
24 мар 2024, 21:52
24 мар 2024, 21:52
e07f059
Код
Авторство
О чём код?
package ru.aav; import com.github.springtestdbunit.DbUnitTestExecutionListener; import com.github.springtestdbunit.annotation.DbUnitConfiguration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Import; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; import org.springframework.test.context.support.DirtiesContextTestExecutionListener; import org.springframework.test.context.transaction.TransactionalTestExecutionListener; import org.springframework.test.web.servlet.MockMvc; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import ru.aav.config.DSConfig; import ru.aav.config.NullableColumnsDataSetLoader; import ru.aav.config.Profiles; @SpringBootTest @Testcontainers @ActiveProfiles(Profiles.TEST) @AutoConfigureMockMvc(addFilters = false) @ContextConfiguration(initializers = IntegrationTest.Initializer.class) @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class, DbUnitTestExecutionListener.class }) @Import({ DSConfig.class }) @DbUnitConfiguration(dataSetLoader = NullableColumnsDataSetLoader.class, databaseConnection = {"dbConnection"}) class IntegrationTest { private static final String DATABASE_NAME = "postgres"; @Container public static PostgreSQLContainer<?> postgreSQLContainer = new PostgreSQLContainer<>("postgres:15.3") .withReuse(true) .withDatabaseName(DATABASE_NAME); @Autowired protected MockMvc mockMvc; static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { public void initialize(ConfigurableApplicationContext configurableApplicationContext) { TestPropertyValues.of( "CONTAINER.USERNAME=" + postgreSQLContainer.getUsername(), "CONTAINER.PASSWORD=" + postgreSQLContainer.getPassword(), "CONTAINER.URL=" + postgreSQLContainer.getJdbcUrl() ).applyTo(configurableApplicationContext.getEnvironment()); } } }