BATCH-1053: Modified so that AbstractJob.getStep() returns null if the step is not found and Flow.getState() returns null if the state is not found. Javadocs and unit tests were updated to reflect this change.
This commit is contained in:
@@ -446,6 +446,25 @@ public class SimpleJobTests {
|
||||
|
||||
assertNull("Second step was not supposed to be executed", step2.passedInStepContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepExists() {
|
||||
step1 = new StubStep("step1", jobRepository);
|
||||
step2 = new StubStep("step2", jobRepository);
|
||||
job.setSteps(Arrays.asList(new Step[] { step1, step2 }));
|
||||
Step step = job.getStep("step2");
|
||||
assertNotNull(step);
|
||||
assertEquals("step2", step.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepNotExists() {
|
||||
step1 = new StubStep("step1", jobRepository);
|
||||
step2 = new StubStep("step2", jobRepository);
|
||||
job.setSteps(Arrays.asList(new Step[] { step1, step2 }));
|
||||
Step step = job.getStep("foo");
|
||||
assertNull(step);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check JobRepository to ensure status is being saved.
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.batch.core.job.flow;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -292,6 +293,56 @@ public class FlowJobTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepExists() throws Exception {
|
||||
SimpleFlow flow = new SimpleFlow("job");
|
||||
List<StateTransition> transitions = new ArrayList<StateTransition>();
|
||||
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1")), "step2"));
|
||||
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step2")), "end0"));
|
||||
transitions.add(StateTransition.createEndStateTransition(new EndState(BatchStatus.COMPLETED, "end0")));
|
||||
flow.setStateTransitions(transitions);
|
||||
flow.afterPropertiesSet();
|
||||
job.setFlow(flow);
|
||||
job.afterPropertiesSet();
|
||||
|
||||
|
||||
Step step = job.getStep("step2");
|
||||
assertNotNull(step);
|
||||
assertEquals("step2", step.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepNotExists() throws Exception {
|
||||
SimpleFlow flow = new SimpleFlow("job");
|
||||
List<StateTransition> transitions = new ArrayList<StateTransition>();
|
||||
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1")), "step2"));
|
||||
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step2")), "end0"));
|
||||
transitions.add(StateTransition.createEndStateTransition(new EndState(BatchStatus.COMPLETED, "end0")));
|
||||
flow.setStateTransitions(transitions);
|
||||
flow.afterPropertiesSet();
|
||||
job.setFlow(flow);
|
||||
job.afterPropertiesSet();
|
||||
|
||||
Step step = job.getStep("foo");
|
||||
assertNull(step);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepNotStepState() throws Exception {
|
||||
SimpleFlow flow = new SimpleFlow("job");
|
||||
List<StateTransition> transitions = new ArrayList<StateTransition>();
|
||||
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1")), "step2"));
|
||||
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step2")), "end0"));
|
||||
transitions.add(StateTransition.createEndStateTransition(new EndState(BatchStatus.COMPLETED, "end0")));
|
||||
flow.setStateTransitions(transitions);
|
||||
flow.afterPropertiesSet();
|
||||
job.setFlow(flow);
|
||||
job.afterPropertiesSet();
|
||||
|
||||
Step step = job.getStep("end0");
|
||||
assertNull(step);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.batch.core.job.flow.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -215,12 +216,13 @@ public class SimpleFlowTests {
|
||||
assertEquals("step1", state.getName());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testGetStateDoesNotExist() throws Exception {
|
||||
flow.setStateTransitions(Collections.singletonList(StateTransition.createEndStateTransition(new StubState(
|
||||
"step1"))));
|
||||
flow.afterPropertiesSet();
|
||||
flow.getState("bar");
|
||||
State state = flow.getState("bar");
|
||||
assertNull(state);
|
||||
}
|
||||
|
||||
private List<StateTransition> collect(StateTransition s1, StateTransition s2) {
|
||||
|
||||
Reference in New Issue
Block a user