Refactor config model classes

- Better naming for public model
  data classes.
- Relates to #172
This commit is contained in:
Janne Valkealahti
2016-03-19 10:06:38 +00:00
parent 79a91220f6
commit d3eb24ed1c
28 changed files with 345 additions and 151 deletions

View File

@@ -36,9 +36,9 @@ import org.springframework.statemachine.config.builders.StateMachineConfigBuilde
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
import org.springframework.statemachine.config.model.DefaultStateMachineModel;
import org.springframework.statemachine.config.model.StateMachineConfigurationConfig;
import org.springframework.statemachine.config.model.StateMachineStates;
import org.springframework.statemachine.config.model.StateMachineTransitions;
import org.springframework.statemachine.config.model.ConfigurationData;
import org.springframework.statemachine.config.model.StatesData;
import org.springframework.statemachine.config.model.TransitionsData;
import org.springframework.statemachine.listener.StateMachineListenerAdapter;
import org.springframework.statemachine.state.State;
@@ -51,9 +51,9 @@ public class ManualBuilderTests {
builder.apply(config);
StateMachineConfig<String, String> stateMachineConfig = builder.getOrBuild();
StateMachineTransitions<String, String> stateMachineTransitions = stateMachineConfig.getTransitions();
StateMachineStates<String, String> stateMachineStates = stateMachineConfig.getStates();
StateMachineConfigurationConfig<String, String> stateMachineConfigurationConfig = stateMachineConfig.getStateMachineConfigurationConfig();
TransitionsData<String, String> stateMachineTransitions = stateMachineConfig.getTransitions();
StatesData<String, String> stateMachineStates = stateMachineConfig.getStates();
ConfigurationData<String, String> stateMachineConfigurationConfig = stateMachineConfig.getStateMachineConfigurationConfig();
ObjectStateMachineFactory<String, String> stateMachineFactory = new ObjectStateMachineFactory<String, String>(
new DefaultStateMachineModel<String, String>(stateMachineConfigurationConfig, stateMachineStates, stateMachineTransitions));

View File

@@ -0,0 +1,90 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.statemachine.config.model;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.security.access.AccessDecisionManager;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.config.ObjectStateMachineFactory;
import org.springframework.statemachine.config.model.verifier.DefaultStateMachineModelVerifier;
import org.springframework.statemachine.config.model.verifier.StateMachineModelVerifier;
import org.springframework.statemachine.ensemble.StateMachineEnsemble;
import org.springframework.statemachine.listener.StateMachineListener;
import org.springframework.statemachine.security.SecurityRule;
import org.springframework.statemachine.transition.TransitionKind;
public class StateMachineModelTests {
@Test
public void testMachineManuallyViaModel() {
BeanFactory beanFactory = null;
TaskExecutor taskExecutor = new SyncTaskExecutor();
TaskScheduler taskScheduler = null;
boolean autoStart = false;
StateMachineEnsemble<String, String> ensemble = null;
List<StateMachineListener<String, String>> listeners = new ArrayList<>();
boolean securityEnabled = false;
AccessDecisionManager transitionSecurityAccessDecisionManager = null;
AccessDecisionManager eventSecurityAccessDecisionManager = null;
SecurityRule eventSecurityRule = null;
SecurityRule transitionSecurityRule = null;
boolean verifierEnabled = true;
StateMachineModelVerifier<String, String> verifier = new DefaultStateMachineModelVerifier<>();
ConfigurationData<String, String> configurationData = new ConfigurationData<>(beanFactory, taskExecutor, taskScheduler, autoStart,
ensemble, listeners, securityEnabled, transitionSecurityAccessDecisionManager, eventSecurityAccessDecisionManager,
eventSecurityRule, transitionSecurityRule, verifierEnabled, verifier);
Collection<StateData<String, String>> stateData = new ArrayList<>();
StateData<String, String> stateData1 = new StateData<String, String>(null, null, "S1", null, null, null);
stateData1.setInitial(true);
stateData.add(stateData1);
StateData<String, String> stateData2 = new StateData<String, String>(null, null, "S2", null, null, null);
stateData.add(stateData2);
StatesData<String, String> statesData = new StatesData<>(stateData);
Collection<TransitionData<String, String>> transitions = new ArrayList<>();
TransitionData<String, String> transitionData1 = new TransitionData<String, String>("S1", "S2", null, "E1", null, null, null, null, TransitionKind.EXTERNAL, null);
transitions.add(transitionData1);
Map<String, List<ChoiceData<String, String>>> choices = new HashMap<>();
Map<String, List<String>> forks = new HashMap<>();
Map<String, List<String>> joins = new HashMap<>();
TransitionsData<String, String> transitionsData = new TransitionsData<>(transitions, choices, forks, joins);
StateMachineModel<String, String> stateMachineModel = new DefaultStateMachineModel<>(configurationData, statesData, transitionsData);
ObjectStateMachineFactory<String, String> factory = new ObjectStateMachineFactory<>(stateMachineModel);
StateMachine<String,String> stateMachine = factory.getStateMachine();
stateMachine.start();
assertThat(stateMachine.getState().getIds(), contains("S1"));
stateMachine.sendEvent("E1");
assertThat(stateMachine.getState().getIds(), contains("S2"));
}
}