Remove job autowiring in JobLauncherTestUtils
Before this commit, registering the JobLauncherTestUtils as a bean in the test context (either manually or via `@SpringBatchTest`) was failing when multiple jobs are defined in the test context. This commit removes the autowiring of the job under test in JobLauncherTestUtils. Resolves #1237
This commit is contained in:
@@ -18,6 +18,8 @@ package org.springframework.batch.sample;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -48,12 +50,15 @@ class AMQPJobFunctionalTests {
|
||||
private JobExplorer jobExplorer;
|
||||
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
|
||||
jobLauncherTestUtils.launchJob();
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
// given
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
this.jobLauncherTestUtils.launchJob();
|
||||
|
||||
// when
|
||||
int count = jobExplorer.getJobInstances("amqp-example-job", 0, 1).size();
|
||||
|
||||
// then
|
||||
assertTrue(count > 0);
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
@@ -29,10 +31,15 @@ class BeanWrapperMapperSampleJobFunctionalTests {
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
@Test
|
||||
void testJobLaunch() throws Exception {
|
||||
void testJobLaunch(@Autowired Job job) throws Exception {
|
||||
// given
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
|
||||
jobLauncherTestUtils.launchJob();
|
||||
// when
|
||||
this.jobLauncherTestUtils.launchJob();
|
||||
|
||||
// then
|
||||
// FIXME no assertions?
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import javax.sql.DataSource;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.sample.domain.trade.Trade;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -60,7 +61,8 @@ class CompositeItemWriterSampleFunctionalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJobLaunch() throws Exception {
|
||||
void testJobLaunch(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "TRADE");
|
||||
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE");
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ import javax.sql.DataSource;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -80,7 +82,8 @@ class CustomerFilterJobFunctionalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFilterJob() throws Exception {
|
||||
void testFilterJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
|
||||
|
||||
customers = Arrays.asList(new Customer("customer1", (credits.get("customer1"))),
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.launch.JobOperator;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
@@ -53,8 +54,8 @@ class DatabaseShutdownFunctionalTests {
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
@@ -19,6 +19,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.sample.domain.person.PersonService;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -35,8 +37,8 @@ class DelegatingJobFunctionalTests {
|
||||
private PersonService personService;
|
||||
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
jobLauncherTestUtils.launchJob();
|
||||
|
||||
assertTrue(personService.getReturnedCount() > 0);
|
||||
|
||||
@@ -20,6 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -41,7 +43,8 @@ class FootballJobFunctionalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "PLAYERS", "GAMES", "PLAYER_SUMMARY");
|
||||
|
||||
jobLauncherTestUtils.launchJob();
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
@@ -54,8 +55,8 @@ class GracefulShutdownFunctionalTests {
|
||||
private JobOperator jobOperator;
|
||||
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
final JobParameters jobParameters = new JobParametersBuilder().addLong("timestamp", System.currentTimeMillis())
|
||||
.toJobParameters();
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ import java.io.IOException;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
@@ -41,7 +43,8 @@ class GroovyJobFunctionalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
assertFalse(new File("target/groovyJob/output/files.zip").exists());
|
||||
jobLauncherTestUtils.launchJob();
|
||||
assertTrue(new File("target/groovyJob/output/files.zip").exists());
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -43,8 +45,9 @@ class HeaderFooterSampleFunctionalTests {
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
@Test
|
||||
void testJob() throws Exception {
|
||||
jobLauncherTestUtils.launchJob();
|
||||
void testJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
this.jobLauncherTestUtils.launchJob();
|
||||
|
||||
BufferedReader inputReader = new BufferedReader(new FileReader(input.getFile()));
|
||||
BufferedReader outputReader = new BufferedReader(new FileReader(output.getFile()));
|
||||
|
||||
@@ -28,6 +28,7 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.sample.domain.trade.internal.CustomerCreditIncreaseProcessor;
|
||||
@@ -89,7 +90,8 @@ class HibernateFailureJobFunctionalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
validatePreConditions();
|
||||
|
||||
JobParameters params = new JobParametersBuilder().addString("key", "failureJob").toJobParameters();
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.batch.sample;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.sample.domain.trade.internal.ItemTrackingTradeItemWriter;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -40,8 +42,9 @@ class LoopFlowSampleFunctionalTests {
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
@Test
|
||||
void testJobLaunch() throws Exception {
|
||||
jobLauncherTestUtils.launchJob();
|
||||
void testJobLaunch(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
this.jobLauncherTestUtils.launchJob();
|
||||
// items processed = items read + 2 exceptions
|
||||
assertEquals(10, itemWriter.getItems().size());
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.sample.domain.mail.internal.TestMailErrorHandler;
|
||||
import org.springframework.batch.sample.domain.mail.internal.TestMailSender;
|
||||
@@ -93,7 +94,8 @@ class MailJobFunctionalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSkip() throws Exception {
|
||||
void testSkip(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
this.createUsers(new Object[][] { USER1, USER2_SKIP, USER3, USER4_SKIP, USER5, USER6, USER7, USER8 });
|
||||
|
||||
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.batch.sample;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
@@ -43,8 +44,9 @@ class MultilineJobFunctionalTests {
|
||||
private final Resource output = new FileSystemResource("target/test-outputs/20070122.testStream.multilineStep.txt");
|
||||
|
||||
@Test
|
||||
void testJobLaunch() throws Exception {
|
||||
jobLauncherTestUtils.launchJob();
|
||||
void testJobLaunch(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
this.jobLauncherTestUtils.launchJob();
|
||||
assertEquals(EXPECTED_RESULT, StringUtils.replace(IOUtils.toString(output.getInputStream(), "UTF-8"),
|
||||
System.getProperty("line.separator"), ""));
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.springframework.batch.sample;
|
||||
import static org.springframework.batch.test.AssertFile.assertFileEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -37,8 +39,9 @@ class MultilineOrderJobFunctionalTests {
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
@Test
|
||||
void testJobLaunch() throws Exception {
|
||||
jobLauncherTestUtils.launchJob();
|
||||
void testJobLaunch(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
this.jobLauncherTestUtils.launchJob();
|
||||
assertFileEquals(new ClassPathResource(EXPECTED), new FileSystemResource(ACTUAL));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
@@ -44,7 +45,8 @@ class ParallelJobFunctionalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING");
|
||||
JobExecution execution = jobLauncherTestUtils.launchJob();
|
||||
int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STAGING");
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
@@ -62,7 +63,8 @@ class PartitionFileJobFunctionalTests implements ApplicationContextAware {
|
||||
* Check the resulting credits correspond to inputs increased by fixed amount.
|
||||
*/
|
||||
@Test
|
||||
void testUpdateCredit() throws Exception {
|
||||
void testUpdateCredit(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
assertTrue(applicationContext.containsBeanDefinition("outputTestReader"),
|
||||
"Define a prototype bean called 'outputTestReader' to check the output");
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
@@ -62,7 +63,8 @@ class PartitionJdbcJobFunctionalTests implements ApplicationContextAware {
|
||||
* Check the resulting credits correspond to inputs increased by fixed amount.
|
||||
*/
|
||||
@Test
|
||||
void testUpdateCredit() throws Exception {
|
||||
void testUpdateCredit(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
assertTrue(applicationContext.containsBeanDefinition("outputTestReader"),
|
||||
"Define a prototype bean called 'outputTestReader' to check the output");
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.sample.config.JobRunnerConfiguration;
|
||||
import org.springframework.batch.sample.remotechunking.ManagerConfiguration;
|
||||
@@ -69,7 +70,10 @@ class RemoteChunkingJobFunctionalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoteChunkingJob() throws Exception {
|
||||
void testRemoteChunkingJob(@Autowired Job job) throws Exception {
|
||||
// given
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
|
||||
// when
|
||||
JobExecution jobExecution = this.jobLauncherTestUtils.launchJob();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -75,7 +76,10 @@ public abstract class RemotePartitioningJobFunctionalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemotePartitioningJob() throws Exception {
|
||||
void testRemotePartitioningJob(@Autowired Job job) throws Exception {
|
||||
// given
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
|
||||
// when
|
||||
JobExecution jobExecution = this.jobLauncherTestUtils.launchJob();
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
@@ -49,7 +50,8 @@ class RestartFileSampleFunctionalTests {
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
@Test
|
||||
void runTest() throws Exception {
|
||||
void runTest(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
JobParameters jobParameters = jobLauncherTestUtils.getUniqueJobParameters();
|
||||
|
||||
JobExecution je1 = jobLauncherTestUtils.launchJob(jobParameters);
|
||||
|
||||
@@ -23,6 +23,7 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
@@ -67,7 +68,8 @@ class RestartFunctionalTests {
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE");
|
||||
|
||||
JobExecution jobExecution = runJobForRestartTest();
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.batch.sample;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.sample.config.DataSourceConfiguration;
|
||||
import org.springframework.batch.sample.config.JobRunnerConfiguration;
|
||||
import org.springframework.batch.sample.config.RetrySampleConfiguration;
|
||||
@@ -32,6 +34,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
@SpringJUnitConfig(
|
||||
classes = { DataSourceConfiguration.class, RetrySampleConfiguration.class, JobRunnerConfiguration.class })
|
||||
@@ -47,8 +50,9 @@ class RetrySampleConfigurationTests {
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
jobLauncherTestUtils.launchJob();
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
this.jobLauncherTestUtils.launchJob();
|
||||
// items processed = items read + 2 exceptions
|
||||
assertEquals(itemGenerator.getLimit() + 2, itemProcessor.getCounter());
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.batch.sample;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.sample.domain.trade.internal.GeneratingTradeItemReader;
|
||||
import org.springframework.batch.sample.support.RetrySampleItemWriter;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
@@ -28,6 +30,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
* Checks that expected number of items have been processed.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
@SpringJUnitConfig(
|
||||
locations = { "/simple-job-launcher-context.xml", "/jobs/retrySample.xml", "/job-runner-context.xml" })
|
||||
@@ -43,8 +46,9 @@ class RetrySampleFunctionalTests {
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
jobLauncherTestUtils.launchJob();
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
this.jobLauncherTestUtils.launchJob();
|
||||
// items processed = items read + 2 exceptions
|
||||
assertEquals(itemGenerator.getLimit() + 2, itemProcessor.getCounter());
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
@@ -35,7 +36,8 @@ class TaskletJobFunctionalTests {
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
JobExecution jobExecution = jobLauncherTestUtils
|
||||
.launchJob(new JobParametersBuilder().addString("value", "foo").toJobParameters());
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
|
||||
@@ -32,6 +32,8 @@ import javax.sql.DataSource;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.sample.domain.trade.Trade;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -81,8 +83,9 @@ class TradeJobFunctionalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLaunchJob() throws Exception {
|
||||
jobLauncherTestUtils.launchJob();
|
||||
void testLaunchJob(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
this.jobLauncherTestUtils.launchJob();
|
||||
|
||||
customers = Arrays.asList(new Customer("customer1", (credits.get("customer1") - 98.34)),
|
||||
new Customer("customer2", (credits.get("customer2") - 18.12 - 12.78)),
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
@@ -46,6 +47,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
||||
* to parse the outputs.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
@SpringJUnitConfig(
|
||||
locations = { "/simple-job-launcher-context.xml", "/job-runner-context.xml", "/jobs/ioSampleJob.xml" })
|
||||
@@ -62,7 +64,8 @@ abstract class AbstractIoSampleTests {
|
||||
* Check the resulting credits correspond to inputs increased by fixed amount.
|
||||
*/
|
||||
@Test
|
||||
void testUpdateCredit() throws Exception {
|
||||
void testUpdateCredit(@Autowired Job job) throws Exception {
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
|
||||
open(reader);
|
||||
List<CustomerCredit> inputs = getCredits(reader);
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.springframework.batch.sample.iosample;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.test.AssertFile;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -25,6 +27,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
/**
|
||||
* @author Dan Garrette
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 2.0
|
||||
*/
|
||||
@SpringJUnitConfig(
|
||||
@@ -42,8 +45,14 @@ class MultiLineFunctionalTests {
|
||||
* Output should be the same as input
|
||||
*/
|
||||
@Test
|
||||
void testJob() throws Exception {
|
||||
jobLauncherTestUtils.launchJob();
|
||||
void testJob(@Autowired Job job) throws Exception {
|
||||
// given
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
|
||||
// when
|
||||
this.jobLauncherTestUtils.launchJob();
|
||||
|
||||
// then
|
||||
AssertFile.assertFileEquals(new FileSystemResource(INPUT_FILE), new FileSystemResource(OUTPUT_FILE));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.springframework.batch.sample.iosample;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.test.AssertFile;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -25,6 +27,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
/**
|
||||
* @author Dan Garrette
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 2.0
|
||||
*/
|
||||
@SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/jobs/iosample/multiRecordType.xml",
|
||||
@@ -42,8 +45,14 @@ class MultiRecordTypeFunctionalTests {
|
||||
* Output should be the same as input
|
||||
*/
|
||||
@Test
|
||||
void testJob() throws Exception {
|
||||
void testJob(@Autowired Job job) throws Exception {
|
||||
// given
|
||||
this.jobLauncherTestUtils.setJob(job);
|
||||
|
||||
// when
|
||||
jobLauncherTestUtils.launchJob();
|
||||
|
||||
// then
|
||||
AssertFile.assertFileEquals(new FileSystemResource(INPUT_FILE), new FileSystemResource(OUTPUT_FILE));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user