/** * Test method for {@link org.springframework.batch.core.job.flow.FlowStep#afterPropertiesSet()}. */ @Test(expected=IllegalStateException.class) public void testAfterPropertiesSet() throws Exception{ FlowStep step = new FlowStep(); step.setJobRepository(jobRepository); step.afterPropertiesSet(); }
/** * Build a step that executes the flow provided, normally composed of other steps. The flow is not executed in a * transaction because the individual steps are supposed to manage their own transaction state. * * @return a flow step */ public Step build() { FlowStep step = new FlowStep(); step.setName(getName()); step.setFlow(flow); super.enhance(step); try { step.afterPropertiesSet(); } catch (Exception e) { throw new StepBuilderException(e); } return step; }
/** * Test method for {@link org.springframework.batch.core.job.flow.FlowStep#doExecute(org.springframework.batch.core.StepExecution)}. */ @Test public void testDoExecute() throws Exception { FlowStep step = new FlowStep(); step.setJobRepository(jobRepository); SimpleFlow flow = new SimpleFlow("job"); List<StateTransition> transitions = new ArrayList<>(); transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1")), "step2")); StepState step2 = new StepState(new StubStep("step2")); transitions.add(StateTransition.createStateTransition(step2, ExitStatus.FAILED.getExitCode(), "end0")); transitions.add(StateTransition.createStateTransition(step2, ExitStatus.COMPLETED.getExitCode(), "end1")); transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.FAILED, "end0"))); transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end1"))); flow.setStateTransitions(transitions); step.setFlow(flow); step.afterPropertiesSet(); StepExecution stepExecution = jobExecution.createStepExecution("step"); jobRepository.add(stepExecution); step.execute(stepExecution); stepExecution = getStepExecution(jobExecution, "step"); assertEquals(ExitStatus.COMPLETED, stepExecution.getExitStatus()); stepExecution = getStepExecution(jobExecution, "step2"); assertEquals(ExitStatus.COMPLETED, stepExecution.getExitStatus()); assertEquals(3, jobExecution.getStepExecutions().size()); }
@Test public void testDoExecuteAndFail() throws Exception { FlowStep step = new FlowStep(); step.setJobRepository(jobRepository); SimpleFlow flow = new SimpleFlow("job"); List<StateTransition> transitions = new ArrayList<>(); transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1")), "step2")); StepState step2 = new StepState(new StubStep("step2", true)); transitions.add(StateTransition.createStateTransition(step2, ExitStatus.FAILED.getExitCode(), "end0")); transitions.add(StateTransition.createStateTransition(step2, ExitStatus.COMPLETED.getExitCode(), "end1")); transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.FAILED, "end0"))); transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end1"))); flow.setStateTransitions(transitions); step.setFlow(flow); step.afterPropertiesSet(); StepExecution stepExecution = jobExecution.createStepExecution("step"); jobRepository.add(stepExecution); step.execute(stepExecution); stepExecution = getStepExecution(jobExecution, "step1"); assertEquals(ExitStatus.COMPLETED, stepExecution.getExitStatus()); stepExecution = getStepExecution(jobExecution, "step2"); assertEquals(ExitStatus.FAILED, stepExecution.getExitStatus()); stepExecution = getStepExecution(jobExecution, "step"); assertEquals(ExitStatus.FAILED, stepExecution.getExitStatus()); assertEquals(3, jobExecution.getStepExecutions().size()); }
/** * Test method for {@link org.springframework.batch.core.job.flow.FlowStep#doExecute(org.springframework.batch.core.StepExecution)}. */ @Test public void testExecuteWithParentContext() throws Exception { FlowStep step = new FlowStep(); step.setJobRepository(jobRepository); SimpleFlow flow = new SimpleFlow("job"); List<StateTransition> transitions = new ArrayList<>(); transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1")), "end0")); transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0"))); flow.setStateTransitions(transitions); step.setFlow(flow); step.afterPropertiesSet(); StepExecution stepExecution = jobExecution.createStepExecution("step"); stepExecution.getExecutionContext().put("foo", "bar"); jobRepository.add(stepExecution); step.execute(stepExecution); stepExecution = getStepExecution(jobExecution, "step"); assertEquals(ExitStatus.COMPLETED, stepExecution.getExitStatus()); stepExecution = getStepExecution(jobExecution, "step1"); assertEquals(ExitStatus.COMPLETED, stepExecution.getExitStatus()); assertEquals("bar", stepExecution.getExecutionContext().get("foo")); }
/** * Build a step that executes the flow provided, normally composed of other steps. The flow is not executed in a * transaction because the individual steps are supposed to manage their own transaction state. * * @return a flow step */ public Step build() { FlowStep step = new FlowStep(); step.setName(getName()); step.setFlow(flow); super.enhance(step); try { step.afterPropertiesSet(); } catch (Exception e) { throw new StepBuilderException(e); } return step; }
/** * Build a step that executes the flow provided, normally composed of other steps. The flow is not executed in a * transaction because the individual steps are supposed to manage their own transaction state. * * @return a flow step */ public Step build() { FlowStep step = new FlowStep(); step.setName(getName()); step.setFlow(flow); super.enhance(step); try { step.afterPropertiesSet(); } catch (Exception e) { throw new StepBuilderException(e); } return step; }
/** * Build a step that executes the flow provided, normally composed of other steps. The flow is not executed in a * transaction because the individual steps are supposed to manage their own transaction state. * * @return a flow step */ public Step build() { FlowStep step = new FlowStep(); step.setName(getName()); step.setFlow(flow); super.enhance(step); try { step.afterPropertiesSet(); } catch (Exception e) { throw new StepBuilderException(e); } return step; }
FlowStep ts = new FlowStep(); configureFlowStep(ts); return ts;