BAEL-3299 - Testing a Spring Batch Job (#7982)
* BAEL-3299: First version. Broken tests * BAEL-3299: Fix tests * BAEL-3299: Include gitignore for output files * BAEL-3299: Example of writer unit test * BAEL-3299: Cleaned up and included more tests * BAEL-3299: Updated to use JobParameters * BAEL-3299: Fixed broken startup and included cleanup for tests * BAEL-3299: Fine tuned version. Fixed formatting. * BAEL-3299: Cleaned up redundant stuff * BAEL-3299: Fixed formatting * BAEL-3299: Moved source code in spring-batch module * BAEL-3299: Fixed broken tests
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package org.baeldung.batchtesting;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@SpringBootApplication
|
||||
@PropertySource("classpath:batchtesting/application.properties")
|
||||
public class SpringBatchApplication implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private JobLauncher jobLauncher;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("transformBooksRecords")
|
||||
private Job transformBooksRecordsJob;
|
||||
|
||||
@Value("${file.input}")
|
||||
private String input;
|
||||
|
||||
@Value("${file.output}")
|
||||
private String output;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBatchApplication.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
JobParametersBuilder paramsBuilder = new JobParametersBuilder();
|
||||
paramsBuilder.addString("file.input", input);
|
||||
paramsBuilder.addString("file.output", output);
|
||||
jobLauncher.run(transformBooksRecordsJob, paramsBuilder.toJobParameters());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user