RegionState not created with nested states

- EnumStateMachineFactory didn't add created machine
  which wrapped region states into a internal
  machine map which is used to resolve built machines.
- Adding test which simply tests nested regions.
- Fixes #54
This commit is contained in:
Janne Valkealahti
2015-05-01 11:26:47 +01:00
parent f24dd481bc
commit ffa2bcbfa8
2 changed files with 52 additions and 3 deletions

View File

@@ -162,10 +162,8 @@ public class EnumStateMachineFactory<S extends Enum<S>, E extends Enum<E>> exten
m.setBeanFactory(getBeanFactory());
}
m.afterPropertiesSet();
machine = m;
machineMap.put(peek.getParent(), machine);
} else {
machine = buildMachine(machineMap, stateMap, stateDatas, transitionsData, getBeanFactory(),
contextEvents, defaultExtendedState, stateMachineTransitions);

View File

@@ -250,6 +250,19 @@ public class RegionMachineTests extends AbstractStateMachineTests {
assertThat(machine.getState().getIds(), containsInAnyOrder(TestStates.S10, TestStates.S20));
}
@Test
public void testRegionsInNestedState() throws Exception {
context.register(BaseConfig.class, StateMachineEventPublisherConfiguration.class, Config2.class);
context.refresh();
@SuppressWarnings("unchecked")
EnumStateMachine<TestStates,TestEvents> machine =
context.getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, EnumStateMachine.class);
assertThat(machine, notNullValue());
machine.start();
machine.sendEvent(TestEvents.E1);
assertThat(machine.getState().getIds(), containsInAnyOrder(TestStates.S2, TestStates.S20, TestStates.S30));
}
@Configuration
@EnableStateMachine
static class Config1 extends EnumStateMachineConfigurerAdapter<TestStates, TestEvents> {
@@ -299,6 +312,44 @@ public class RegionMachineTests extends AbstractStateMachineTests {
}
@Configuration
@EnableStateMachine
static class Config2 extends EnumStateMachineConfigurerAdapter<TestStates, TestEvents> {
@Override
public void configure(StateMachineStateConfigurer<TestStates, TestEvents> states) throws Exception {
states
.withStates()
.initial(TestStates.SI)
.state(TestStates.SI)
.state(TestStates.S2)
.end(TestStates.SF)
.and()
.withStates()
.parent(TestStates.S2)
.initial(TestStates.S20)
.state(TestStates.S20)
.state(TestStates.S21)
.and()
.withStates()
.parent(TestStates.S2)
.initial(TestStates.S30)
.state(TestStates.S30)
.state(TestStates.S31);
}
@Override
public void configure(StateMachineTransitionConfigurer<TestStates, TestEvents> transitions) throws Exception {
transitions
.withExternal()
.source(TestStates.SI)
.target(TestStates.S2)
.event(TestEvents.E1);
}
}
private static class TestStateMachineListener extends StateMachineListenerAdapter<TestStates, TestEvents> {
volatile CountDownLatch stateChangedLatch = new CountDownLatch(0);