/** * Delegate execution to the target object and translate the return value to * an {@link ExitStatus} by invoking a method in the delegate POJO. Ignores * the {@link StepContribution} and the attributes. * * @see Tasklet#execute(StepContribution, ChunkContext) */ @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { if (getArguments() == null) { setArguments(new Object[]{contribution, chunkContext}); } contribution.setExitStatus(mapResult(invokeDelegateMethod())); return RepeatStatus.FINISHED; }
@Before public void setUp() throws Exception { stepContribution = new StepContribution(mock(StepExecution.class)); chunkContext = mock(ChunkContext.class); tasklet = new TestTasklet(); adapter = new MethodInvokingTaskletAdapter(); adapter.setTargetObject(tasklet); }
@Test(expected = IllegalArgumentException.class) public void testIncorrectSignatureWithExtraParameter() throws Exception { adapter.setTargetMethod("execute10"); adapter.execute(stepContribution, chunkContext); }
/** * Delegate execution to the target object and translate the return value to * an {@link ExitStatus} by invoking a method in the delegate POJO. Ignores * the {@link StepContribution} and the attributes. * * @see Tasklet#execute(StepContribution, ChunkContext) */ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { contribution.setExitStatus(mapResult(invokeDelegateMethod())); return RepeatStatus.FINISHED; }
/** * Delegate execution to the target object and translate the return value to * an {@link ExitStatus} by invoking a method in the delegate POJO. Ignores * the {@link StepContribution} and the attributes. * * @see Tasklet#execute(StepContribution, ChunkContext) */ @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { contribution.setExitStatus(mapResult(invokeDelegateMethod())); return RepeatStatus.FINISHED; }
/** * Delegate execution to the target object and translate the return value to * an {@link ExitStatus} by invoking a method in the delegate POJO. Ignores * the {@link StepContribution} and the attributes. * * @see Tasklet#execute(StepContribution, ChunkContext) */ @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { if (getArguments() == null) { setArguments(new Object[]{contribution, chunkContext}); } contribution.setExitStatus(mapResult(invokeDelegateMethod())); return RepeatStatus.FINISHED; }
@Test public void testArgumentSubsetWithoutArguments() throws Exception { adapter.setTargetMethod("execute5"); RepeatStatus repeatStatus = adapter.execute(stepContribution, chunkContext); assertEquals(RepeatStatus.FINISHED, repeatStatus); }
/** * Delegate execution to the target object and translate the return value to * an {@link ExitStatus} by invoking a method in the delegate POJO. Ignores * the {@link StepContribution} and the attributes. * * @see Tasklet#execute(StepContribution, ChunkContext) */ @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { if (getArguments() == null) { setArguments(new Object[]{contribution, chunkContext}); } contribution.setExitStatus(mapResult(invokeDelegateMethod())); return RepeatStatus.FINISHED; }
@Test public void testCompatibleReturnTypeWhenVoid() throws Exception { adapter.setTargetMethod("execute7"); RepeatStatus repeatStatus = adapter.execute(stepContribution, chunkContext); assertEquals(RepeatStatus.FINISHED, repeatStatus); }
@Test public void testCompatibleReturnTypeWhenBoolean() throws Exception { adapter.setTargetMethod("execute6"); RepeatStatus repeatStatus = adapter.execute(stepContribution, chunkContext); assertEquals(RepeatStatus.FINISHED, repeatStatus); }
@Test public void testArgumentSubsetWithOnlyChunkContextAndCompatibleReturnTypeVoid() throws Exception { adapter.setTargetMethod("execute9"); RepeatStatus repeatStatus = adapter.execute(stepContribution, chunkContext); assertEquals(RepeatStatus.FINISHED, repeatStatus); assertEquals(tasklet.getChunkContext(), chunkContext); }
@Test public void testArgumentSubsetWithOnlyStepContributionAndCompatibleReturnTypeBoolean() throws Exception { adapter.setTargetMethod("execute8"); RepeatStatus repeatStatus = adapter.execute(stepContribution, chunkContext); assertEquals(RepeatStatus.FINISHED, repeatStatus); assertEquals(tasklet.getStepContribution(), stepContribution); }
@Test public void testMapResultWithNull() throws Exception { tasklet.setTargetMethod("process"); StepContribution contribution = stepExecution.createStepContribution(); tasklet.execute(contribution,null); assertEquals(ExitStatus.COMPLETED, contribution.getExitStatus()); }
@Test public void testArgumentSubsetWithOnlyChunkContext() throws Exception { adapter.setTargetMethod("execute3"); RepeatStatus repeatStatus = adapter.execute(stepContribution, chunkContext); assertEquals(RepeatStatus.FINISHED, repeatStatus); assertEquals(tasklet.getChunkContext(), chunkContext); }
@Test public void testExitStatusReturnType() throws Exception { adapter.setTargetMethod("execute11"); adapter.execute(stepContribution, chunkContext); assertEquals(new ExitStatus("DONE"), stepContribution.getExitStatus()); }
@Test public void testExecuteWithExitStatus() throws Exception { tasklet.setTargetMethod("execute"); StepContribution contribution = stepExecution.createStepContribution(); tasklet.execute(contribution,null); assertEquals(ExitStatus.NOOP, contribution.getExitStatus()); }
@Test public void testMapResultWithNonNull() throws Exception { tasklet.setTargetMethod("process"); this.result = "foo"; StepContribution contribution = stepExecution.createStepContribution(); tasklet.execute(contribution,null); assertEquals(ExitStatus.COMPLETED, contribution.getExitStatus()); }
@Test public void testArgumentSubsetWithOnlyStepContribution() throws Exception { adapter.setTargetMethod("execute4"); RepeatStatus repeatStatus = adapter.execute(stepContribution, chunkContext); assertEquals(RepeatStatus.FINISHED, repeatStatus); assertEquals(tasklet.getStepContribution(), stepContribution); }
@Test public void testNonExitStatusReturnType() throws Exception { adapter.setTargetMethod("execute12"); RepeatStatus repeatStatus = adapter.execute(stepContribution, chunkContext); assertEquals(RepeatStatus.FINISHED, repeatStatus); assertEquals(ExitStatus.COMPLETED, stepContribution.getExitStatus()); }
@Test public void testDifferentParametersOrder() throws Exception { adapter.setTargetMethod("execute2"); RepeatStatus repeatStatus = adapter.execute(stepContribution, chunkContext); assertEquals(RepeatStatus.FINISHED, repeatStatus); assertEquals(tasklet.getStepContribution(), stepContribution); assertEquals(tasklet.getChunkContext(), chunkContext); }