/** * Create a {@link StepExecution} with default parameters. * * @return a {@link StepExecution} with stepName="step" and * id=DEFAULT_STEP_EXECUTION_ID */ public static StepExecution createStepExecution() { return createStepExecution(DEFAULT_STEP_NAME, DEFAULT_STEP_EXECUTION_ID); }
/** * Create a {@link StepExecution} with the parameters provided. * * @param stepName the stepName for the {@link StepExecution} * @param executionId the id for the {@link StepExecution} * @return a {@link StepExecution} with a {@link JobExecution} having * default properties */ public static StepExecution createStepExecution(String stepName, Long executionId) { return createStepExecution(createJobExecution(), stepName, executionId); }
/** * Create a {@link StepExecution} and all its parent entities with default * values, but using the {@link ExecutionContext} provided. * * @param executionContext some {@link ExecutionContext} * @return a {@link StepExecution} with the execution context provided */ public static StepExecution createStepExecution(ExecutionContext executionContext) { StepExecution stepExecution = createStepExecution(); stepExecution.setExecutionContext(executionContext); return stepExecution; }
/** * Create a {@link StepExecution} and all its parent entities with default * values, but using the {@link ExecutionContext} and {@link JobParameters} * provided. * * @param jobParameters come {@link JobParameters} * @param executionContext some {@link ExecutionContext} * * @return a {@link StepExecution} with the execution context provided */ public static StepExecution createStepExecution(JobParameters jobParameters, ExecutionContext executionContext) { StepExecution stepExecution = createStepExecution(jobParameters); stepExecution.setExecutionContext(executionContext); return stepExecution; }
/** * Create a {@link JobExecution} with the parameters provided with attached * step executions. * * @param executionId the {@link JobExecution} id * @param stepNames the names of the step executions * @return a {@link JobExecution} with step executions as specified, each * with a unique id */ public static JobExecution createJobExecutionWithStepExecutions(Long executionId, Collection<String> stepNames) { JobExecution jobExecution = createJobExecution(DEFAULT_JOB_NAME, DEFAULT_JOB_INSTANCE_ID, executionId); Long stepExecutionId = DEFAULT_STEP_EXECUTION_ID; for (String stepName : stepNames) { createStepExecution(jobExecution, stepName, stepExecutionId); stepExecutionId++; } return jobExecution; }
/** * Create a {@link StepExecution} that can be used to satisfy step scoped * dependencies in the test itself (not in the job it launches). * * @return a {@link StepExecution} */ protected StepExecution getStepExecution() { return MetaDataInstanceFactory.createStepExecution(getUniqueJobParameters()); }
/** * Test method for * {@link MetaDataInstanceFactory#createStepExecution(JobExecution, String, Long)} * . */ @Test public void testCreateStepExecutionJobExecutionStringLong() { assertNotNull(MetaDataInstanceFactory.createStepExecution(stepName, stepExecutionId)); }
/** * Test method for {@link MetaDataInstanceFactory#createStepExecution()} . */ @Test public void testCreateStepExecution() { assertNotNull(MetaDataInstanceFactory.createStepExecution()); }
public StepExecution getStepExecution() { StepExecution execution = MetaDataInstanceFactory.createStepExecution(); execution.getExecutionContext().putString("input.data", "foo,bar"); return execution; }
/** * Test method for * {@link MetaDataInstanceFactory#createStepExecution(String, Long)} . */ @Test public void testCreateStepExecutionStringLong() { assertNotNull(MetaDataInstanceFactory.createStepExecution(stepName, stepExecutionId)); }
public StepExecution getStepExecution() { // Assert that dependencies are already injected... assertNotNull(reader); // Then create the execution for the step scope... StepExecution execution = MetaDataInstanceFactory.createStepExecution(); execution.getExecutionContext().putString("input.file", "classpath:/org/springframework/batch/test/simple.txt"); return execution; }
@Test public void testExecutionInStepScope() throws Exception { delegate = new ItemProcessor<String, String>() { public String process(String item) throws Exception { StepContext context = StepSynchronizationManager.getContext(); assertTrue(context != null && context.getStepExecution() != null); return item + item; }; }; processor.setDelegate(delegate); Future<String> result = StepScopeTestUtils.doInStepScope(MetaDataInstanceFactory.createStepExecution(), new Callable<Future<String>>() { public Future<String> call() throws Exception { return processor.process("foo"); } }); assertEquals("foofoo", result.get()); }
@Test public void testFromStep() throws Exception { Date date = new Date(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(); stepExecution.getExecutionContext().put("foo", date); Date result = ExecutionContextTestUtils.getValueFromStep(stepExecution, "foo"); assertEquals(date, result); }
@Override protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) { JobParameters jobParameters = new JobParametersBuilder(super.getUniqueJobParameters()).addDouble("credit", 0.) .toJobParameters(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters); StepSynchronizationManager.close(); StepSynchronizationManager.register(stepExecution); }
@Override protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) { JobParameters jobParameters = new JobParametersBuilder(super.getUniqueJobParameters()).addString("inputFile", "file:./build/test-outputs/delimitedOutput.csv").toJobParameters(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters); StepSynchronizationManager.close(); StepSynchronizationManager.register(stepExecution); }
@Override protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) { JobParameters jobParameters = new JobParametersBuilder(super.getUniqueJobParameters()).addString( "input.file.path", "file:build/test-outputs/multiResourceOutput.csv.*").toJobParameters(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters); StepSynchronizationManager.close(); StepSynchronizationManager.register(stepExecution); }
@Override protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) { JobParameters jobParameters = new JobParametersBuilder(super.getUniqueJobParameters()).addDouble("credit", 0.) .toJobParameters(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters); StepSynchronizationManager.close(); StepSynchronizationManager.register(stepExecution); }
@Override protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) { JobParameters jobParameters = new JobParametersBuilder(super.getUniqueJobParameters()).addString("inputFile", "file:./build/test-outputs/fixedLengthOutput.txt").toJobParameters(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters); StepSynchronizationManager.close(); StepSynchronizationManager.register(stepExecution); }
private void verifyOutput(int expected) throws Exception { JobParameters jobParameters = new JobParametersBuilder().addString("inputFile", "file:./build/test-outputs/delimitedOutput.csv").toJobParameters(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters); int count = StepScopeTestUtils.doInStepScope(stepExecution, new Callable<Integer>() { @Override public Integer call() throws Exception { int count = 0; readerStream.open(new ExecutionContext()); try { while (reader.read() != null) { count++; } } finally { readerStream.close(); } return count; } }); assertEquals(expected, count); }
@Test public void testVanillaHandleChunk() throws Exception { handler.setChunkProcessor(new ChunkProcessor<Object>() { public void process(StepContribution contribution, Chunk<Object> chunk) throws Exception { count += chunk.size(); } }); StepContribution stepContribution = MetaDataInstanceFactory.createStepExecution().createStepContribution(); ChunkResponse response = handler.handleChunk(new ChunkRequest<>(0, StringUtils .commaDelimitedListToSet("foo,bar"), 12L, stepContribution)); assertEquals(stepContribution, response.getStepContribution()); assertEquals(12, response.getJobId().longValue()); assertTrue(response.isSuccessful()); assertEquals(2, count); }