Add support for regions
- Add region id to RepositoryState and hook it via RepositoryStateMachineModelFactory. - Relates to #262
This commit is contained in:
@@ -48,6 +48,7 @@ public class JpaRepositoryState extends RepositoryState {
|
||||
|
||||
private String machineId;
|
||||
private String state;
|
||||
private String region;
|
||||
private boolean initial;
|
||||
private PseudoStateKind kind;
|
||||
|
||||
@@ -142,6 +143,15 @@ public class JpaRepositoryState extends RepositoryState {
|
||||
this.machineId = machineId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpaRepositoryState getParentState() {
|
||||
return parentState;
|
||||
|
||||
@@ -262,6 +262,25 @@ public class JpaRepositoryTests extends AbstractJpaRepositoryTests {
|
||||
plan.test();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testMachine5() throws Exception {
|
||||
context.register(Config5.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("S10", "S20").and()
|
||||
.step().sendEvent("E1").expectStates("S11", "S21").and()
|
||||
.step().sendEvent("E2").expectStates("S10", "S21").and()
|
||||
.step().sendEvent("E3").expectStates("S10", "S20").and()
|
||||
.build();
|
||||
plan.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulate1() {
|
||||
context.register(Config2.class);
|
||||
@@ -335,6 +354,17 @@ public class JpaRepositoryTests extends AbstractJpaRepositoryTests {
|
||||
}
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
static class Config5 {
|
||||
|
||||
@Bean
|
||||
public StateMachineJackson2RepositoryPopulatorFactoryBean jackson2RepositoryPopulatorFactoryBean() {
|
||||
StateMachineJackson2RepositoryPopulatorFactoryBean factoryBean = new StateMachineJackson2RepositoryPopulatorFactoryBean();
|
||||
factoryBean.setResources(new Resource[]{new ClassPathResource("data5.json")});
|
||||
return factoryBean;
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableStateMachineFactory
|
||||
public static class FactoryConfig extends StateMachineConfigurerAdapter<String, String> {
|
||||
|
||||
58
spring-statemachine-data/jpa/src/test/resources/data5.json
Normal file
58
spring-statemachine-data/jpa/src/test/resources/data5.json
Normal file
@@ -0,0 +1,58 @@
|
||||
[
|
||||
{
|
||||
"@id": "1",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"region": "r1",
|
||||
"initial": true,
|
||||
"state": "S10"
|
||||
},
|
||||
{
|
||||
"@id": "2",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"region": "r1",
|
||||
"initial": false,
|
||||
"state": "S11"
|
||||
},
|
||||
{
|
||||
"@id": "3",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"region": "r2",
|
||||
"initial": true,
|
||||
"state": "S20"
|
||||
},
|
||||
{
|
||||
"@id": "4",
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryState",
|
||||
"region": "r2",
|
||||
"initial": false,
|
||||
"state": "S21"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "1",
|
||||
"target": "2",
|
||||
"event": "E1",
|
||||
"kind": "EXTERNAL"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "3",
|
||||
"target": "4",
|
||||
"event": "E1",
|
||||
"kind": "EXTERNAL"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "2",
|
||||
"target": "1",
|
||||
"event": "E2",
|
||||
"kind": "EXTERNAL"
|
||||
},
|
||||
{
|
||||
"_class": "org.springframework.statemachine.data.jpa.JpaRepositoryTransition",
|
||||
"source": "4",
|
||||
"target": "3",
|
||||
"event": "E3",
|
||||
"kind": "EXTERNAL"
|
||||
}
|
||||
]
|
||||
@@ -48,6 +48,13 @@ public abstract class RepositoryState extends BaseRepositoryEntity {
|
||||
*/
|
||||
public abstract String getState();
|
||||
|
||||
/**
|
||||
* Gets the region.
|
||||
*
|
||||
* @return the region
|
||||
*/
|
||||
public abstract String getRegion();
|
||||
|
||||
/**
|
||||
* Checks if is initial.
|
||||
*
|
||||
|
||||
@@ -135,7 +135,8 @@ public class RepositoryStateMachineModelFactory extends AbstractStateMachineMode
|
||||
}
|
||||
|
||||
RepositoryState parentState = s.getParentState();
|
||||
StateData<String, String> stateData = new StateData<String, String>(parentState != null ? parentState.getState() : null, null,
|
||||
Object region = s.getRegion();
|
||||
StateData<String, String> stateData = new StateData<String, String>(parentState != null ? parentState.getState() : null, region,
|
||||
s.getState(), s.isInitial());
|
||||
stateData.setStateActions(stateActions);
|
||||
stateData.setEntryActions(entryActions);
|
||||
|
||||
Reference in New Issue
Block a user