'Spring State Machine use StateMachineTestPlan to test a withChoice transition
If I have a StateMachine set up as below:
transitionConfigurer
.withExternal()
.source(FIRST)
.event(EVENT_1)
.target(SECOND)
.and()
.withChoice()
.source(SECOND)
.first(THIRD, new Guard(someService))
.last(FIRST)
.and()
.withExternal()
.source(THIRD)
.event(EVENT_2)
.target(FIRST);
How can I test the withChoice using a StateMachineTestPlan.
I have a StateMachineTestPlan set up as below, this creates a State Machine with an initial state of SECOND, I want to then be able to test the choice. However, when I perform the .step() in the test plan nothing happens:
createStateMachineAndSetInitialState(SECOND, workflowCreator);
StateMachineTestPlan<State, Event> plan = StateMachineTestPlanBuilder.<State, Event> builder()
.defaultAwaitTime(1)
.stateMachine(machine)
.step()
.expectState(THIRD)
.and()
.build();
plan.test();
Solution 1:[1]
First of all, can you please share your custom override for the method below?
You need to make sure you have configured choice states like this:
@Override
public void configure(final StateMachineStateConfigurer<States, Events> states)
throws Exception {
states
.withStates()
.initial(States.FIRST)
.choice(States.SECOND)
.end(States.LAST)
.states(States.enumSet);
}
It seems like you reached state (SECOND) but did not enter in the CHOICE pseudo-state. In which state have your test stopped at?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel Vilas-Boas |
