Add support for entry/exit states
- Adding entry/exit state construction - Relates to #262
This commit is contained in:
@@ -425,6 +425,24 @@ public class JpaRepositoryTests extends AbstractJpaRepositoryTests {
|
||||
plan.test();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testMachine9() throws Exception {
|
||||
context.register(Config9.class, FactoryConfig.class);
|
||||
context.refresh();
|
||||
StateMachineFactory<String, String> stateMachineFactory = context.getBean(StateMachineFactory.class);
|
||||
StateMachine<String, String> stateMachine = stateMachineFactory.getStateMachine();
|
||||
|
||||
StateMachineTestPlan<String, String> plan =
|
||||
StateMachineTestPlanBuilder.<String, String>builder()
|
||||
.stateMachine(stateMachine)
|
||||
.step().expectStates("S1").and()
|
||||
.step().sendEvent("ENTRY1").expectStates("S2", "S22").and()
|
||||
.step().sendEvent("EXIT1").expectStates("S4").and()
|
||||
.build();
|
||||
plan.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulate1() {
|
||||
context.register(Config2.class);
|
||||
@@ -595,6 +613,17 @@ public class JpaRepositoryTests extends AbstractJpaRepositoryTests {
|
||||
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
static class Config9 {
|
||||
|
||||
@Bean
|
||||
public StateMachineJackson2RepositoryPopulatorFactoryBean jackson2RepositoryPopulatorFactoryBean() {
|
||||
StateMachineJackson2RepositoryPopulatorFactoryBean factoryBean = new StateMachineJackson2RepositoryPopulatorFactoryBean();
|
||||
factoryBean.setResources(new Resource[]{new ClassPathResource("data9.json")});
|
||||
return factoryBean;
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableStateMachineFactory
|
||||
public static class FactoryConfig extends StateMachineConfigurerAdapter<String, String> {
|
||||
|
||||
131
spring-statemachine-data/jpa/src/test/resources/data9.json
Normal file
131
spring-statemachine-data/jpa/src/test/resources/data9.json
Normal file
@@ -0,0 +1,131 @@
|
||||
[
|
||||
{
|
||||
"@id": "1",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"initial": true,
|
||||
"state": "S1"
|
||||
},
|
||||
{
|
||||
"@id": "2",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"state": "S2"
|
||||
},
|
||||
{
|
||||
"@id": "3",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"state": "S3"
|
||||
},
|
||||
{
|
||||
"@id": "4",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"state": "S4"
|
||||
},
|
||||
{
|
||||
"@id": "5",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"state": "S5"
|
||||
},
|
||||
{
|
||||
"@id": "6",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"initial": true,
|
||||
"state": "S21",
|
||||
"parentState": "2"
|
||||
},
|
||||
{
|
||||
"@id": "7",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"state": "S22",
|
||||
"parentState": "2"
|
||||
},
|
||||
{
|
||||
"@id": "8",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"state": "S23",
|
||||
"parentState": "2"
|
||||
},
|
||||
{
|
||||
"@id": "9",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"state": "S2ENTRY1",
|
||||
"parentState": "2",
|
||||
"kind": "ENTRY"
|
||||
},
|
||||
{
|
||||
"@id": "10",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"state": "S2ENTRY2",
|
||||
"parentState": "2",
|
||||
"kind": "ENTRY"
|
||||
},
|
||||
{
|
||||
"@id": "11",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"state": "S2EXIT1",
|
||||
"parentState": "2",
|
||||
"kind": "EXIT"
|
||||
},
|
||||
{
|
||||
"@id": "12",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"state": "S2EXIT2",
|
||||
"parentState": "2",
|
||||
"kind": "EXIT"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "1",
|
||||
"target": "2",
|
||||
"event": "E1"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "2",
|
||||
"target": "3",
|
||||
"event": "E2"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "1",
|
||||
"target": "9",
|
||||
"event": "ENTRY1"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "1",
|
||||
"target": "10",
|
||||
"event": "ENTRY2"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "7",
|
||||
"target": "11",
|
||||
"event": "EXIT1"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "7",
|
||||
"target": "12",
|
||||
"event": "EXIT2"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "9",
|
||||
"target": "7"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "10",
|
||||
"target": "9"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "11",
|
||||
"target": "4"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "12",
|
||||
"target": "5"
|
||||
}
|
||||
]
|
||||
@@ -32,6 +32,8 @@ import org.springframework.statemachine.config.model.AbstractStateMachineModelFa
|
||||
import org.springframework.statemachine.config.model.ChoiceData;
|
||||
import org.springframework.statemachine.config.model.ConfigurationData;
|
||||
import org.springframework.statemachine.config.model.DefaultStateMachineModel;
|
||||
import org.springframework.statemachine.config.model.EntryData;
|
||||
import org.springframework.statemachine.config.model.ExitData;
|
||||
import org.springframework.statemachine.config.model.HistoryData;
|
||||
import org.springframework.statemachine.config.model.JunctionData;
|
||||
import org.springframework.statemachine.config.model.StateData;
|
||||
@@ -154,6 +156,8 @@ public class RepositoryStateMachineModelFactory extends AbstractStateMachineMode
|
||||
}
|
||||
StatesData<String, String> statesData = new StatesData<>(stateDatas);
|
||||
Collection<TransitionData<String, String>> transitionData = new ArrayList<>();
|
||||
Collection<EntryData<String, String>> entrys = new ArrayList<EntryData<String, String>>();
|
||||
Collection<ExitData<String, String>> exits = new ArrayList<ExitData<String, String>>();
|
||||
Collection<HistoryData<String, String>> historys = new ArrayList<HistoryData<String, String>>();
|
||||
Map<String, LinkedList<ChoiceData<String, String>>> choices = new HashMap<String, LinkedList<ChoiceData<String,String>>>();
|
||||
Map<String, LinkedList<JunctionData<String, String>>> junctions = new HashMap<String, LinkedList<JunctionData<String,String>>>();
|
||||
@@ -183,7 +187,11 @@ public class RepositoryStateMachineModelFactory extends AbstractStateMachineMode
|
||||
Guard<String, String> guard = resolveGuard(t);
|
||||
transitionData.add(new TransitionData<>(t.getSource().getState(), t.getTarget().getState(), t.getEvent(), actions, guard, kind != null ? kind : TransitionKind.EXTERNAL));
|
||||
|
||||
if (t.getSource().getKind() == PseudoStateKind.CHOICE) {
|
||||
if (t.getSource().getKind() == PseudoStateKind.ENTRY) {
|
||||
entrys.add(new EntryData<String, String>(t.getSource().getState(), t.getTarget().getState()));
|
||||
} else if (t.getSource().getKind() == PseudoStateKind.EXIT) {
|
||||
exits.add(new ExitData<String, String>(t.getSource().getState(), t.getTarget().getState()));
|
||||
} else if (t.getSource().getKind() == PseudoStateKind.CHOICE) {
|
||||
LinkedList<ChoiceData<String, String>> list = choices.get(t.getSource().getState());
|
||||
if (list == null) {
|
||||
list = new LinkedList<ChoiceData<String, String>>();
|
||||
@@ -221,7 +229,8 @@ public class RepositoryStateMachineModelFactory extends AbstractStateMachineMode
|
||||
HashMap<String, List<JunctionData<String, String>>> junctionsCopy = new HashMap<String, List<JunctionData<String, String>>>();
|
||||
junctionsCopy.putAll(junctions);
|
||||
|
||||
TransitionsData<String, String> transitionsData = new TransitionsData<>(transitionData, choicesCopy, junctionsCopy, null, null, null, null, historys);
|
||||
TransitionsData<String, String> transitionsData = new TransitionsData<>(transitionData, choicesCopy, junctionsCopy, null, null,
|
||||
entrys, exits, historys);
|
||||
|
||||
StateMachineModel<String, String> stateMachineModel = new DefaultStateMachineModel<>(configurationData, statesData, transitionsData);
|
||||
return stateMachineModel;
|
||||
|
||||
Reference in New Issue
Block a user