/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
spring-batch-2/src/test/java/com/baeldung/batch/SpringBootBatchIntegrationTest.java
57 строк
2 KB
Sam
implementation #bael-7150 (#16996)
13 июл 2024, 17:05
Не верифицирован
13 июл 2024, 17:05
4e92d8a
Код
Авторство
О чём код?
package com.baeldung.batch; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.batch.test.JobRepositoryTestUtils; import org.springframework.batch.test.context.SpringBatchTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.context.annotation.PropertySource; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; @SpringBatchTest @DirtiesContext @SpringJUnitConfig(BatchConfiguration.class) @PropertySource("classpath:application.properties") @EnableAutoConfiguration @ExtendWith({ OutputCaptureExtension.class }) public class SpringBootBatchIntegrationTest { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @Autowired private JobRepositoryTestUtils jobRepositoryTestUtils; @MockBean private JobCompletionNotificationListener jobCompletionNotificationListener; @AfterEach public void cleanUp() { jobRepositoryTestUtils.removeJobExecutions(); } @Test public void givenCoffeeList_whenJobExecuted_thenSuccess(CapturedOutput output) throws Exception { JobExecution jobExecution = jobLauncherTestUtils.launchJob(); JobInstance jobInstance = jobExecution.getJobInstance(); ExitStatus jobExitStatus = jobExecution.getExitStatus(); assertEquals("importUserJob", jobInstance.getJobName()); assertEquals("COMPLETED", jobExitStatus.getExitCode()); String regex = "\\[virtual-thread-executor\\d+\\] INFO c.baeldung.batch.CoffeeItemProcessor"; assertThat(output.getAll()).containsPattern(regex); } }