Ich habe einen einfachen Job mit 2 Tasklets implementiert. Ich möchte das zweite Tasklet testen, indem ich Parameter übergebe.Test einzelner Spring Batch Tasklet Schritt mit Parametern
Ich habe den Frühling Batch-Dokumentation und unter meinem Test lesen:
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles({"test"})
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
StepScopeTestExecutionListener.class })
public class EtudeBatchApplicationTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
public StepExecution getStepExecution() {
StepExecution execution = MetaDataInstanceFactory.createStepExecution();
execution.getJobExecution().getExecutionContext().putString("myValue", "foo,bar,spam");
return execution;
}
@Test
public void contextLoads() {
JobExecution jobExecution = jobLauncherTestUtils.launchStep("insertIncludedSiretsStep");
}
}
Mein Problem in meinem Tasklet wird, ist die myValue immer null.
Unten der Code des Tasklet:
@Component
@StepScope
@Slf4j
public class InsertIncludedSiretsTask implements Tasklet {
@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
Object myValue = chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().get("myValue");
log.info("INSERTINCLUDEDSIRETSTASK runnning");
Thread.sleep(3000);
return RepeatStatus.FINISHED;
}
}