Refactor concepts around uml model factory

- Fixes #226
This commit is contained in:
Janne Valkealahti
2016-05-17 09:11:14 +01:00
parent c8cc2b1ba4
commit ec21afc131
5 changed files with 230 additions and 73 deletions

View File

@@ -22,17 +22,15 @@ import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.uml2.uml.Model;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.statemachine.config.model.AbstractStateMachineModelFactory;
import org.springframework.statemachine.config.model.ConfigurationData;
import org.springframework.statemachine.config.model.DefaultStateMachineModel;
import org.springframework.statemachine.config.model.StateMachineModel;
import org.springframework.statemachine.config.model.StateMachineModelFactory;
import org.springframework.statemachine.uml.support.UmlModelParser;
import org.springframework.statemachine.uml.support.UmlUtils;
import org.springframework.statemachine.uml.support.UmlModelParser.DataHolder;
import org.springframework.statemachine.uml.support.UmlUtils;
import org.springframework.util.Assert;
import org.springframework.util.FileCopyUtils;
@@ -64,6 +62,7 @@ public class UmlStateMachineModelFactory extends AbstractStateMachineModelFactor
* @param location the resource location
*/
public UmlStateMachineModelFactory(String location) {
Assert.notNull(location, "Location must be set");
this.location = location;
}
@@ -85,11 +84,7 @@ public class UmlStateMachineModelFactory extends AbstractStateMachineModelFactor
if (resource != null) {
return resource;
} else {
ResourceLoader loader = getResourceLoader();
if (loader == null) {
loader = new DefaultResourceLoader();
}
return loader.getResource(location);
return getResourceLoader().getResource(location);
}
}

View File

@@ -39,6 +39,7 @@ import org.springframework.statemachine.action.Action;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineModelConfigurer;
import org.springframework.statemachine.config.model.DefaultStateMachineComponentResolver;
import org.springframework.statemachine.config.model.StateData;
import org.springframework.statemachine.config.model.StateMachineModel;
import org.springframework.statemachine.config.model.StateMachineModelFactory;
@@ -56,7 +57,7 @@ public class UmlStateMachineModelFactoryTests extends AbstractUmlTests {
}
@Test
public void testSimpleFlat() {
public void testSimpleFlat1() {
context.refresh();
Resource model1 = new ClassPathResource("org/springframework/statemachine/uml/simple-flat.uml");
UmlStateMachineModelFactory builder = new UmlStateMachineModelFactory(model1);
@@ -78,6 +79,30 @@ public class UmlStateMachineModelFactoryTests extends AbstractUmlTests {
}
}
@Test
public void testSimpleFlat2() {
context.refresh();
Resource model1 = new ClassPathResource("org/springframework/statemachine/uml/simple-flat.uml");
DefaultStateMachineComponentResolver<String, String> resolver = new DefaultStateMachineComponentResolver<>();
resolver.registerAction("action1", new LatchAction());
UmlStateMachineModelFactory builder = new UmlStateMachineModelFactory(model1);
builder.setStateMachineComponentResolver(resolver);
assertThat(model1.exists(), is(true));
StateMachineModel<String, String> stateMachineModel = builder.build();
assertThat(stateMachineModel, notNullValue());
Collection<StateData<String, String>> stateDatas = stateMachineModel.getStatesData().getStateData();
assertThat(stateDatas.size(), is(2));
for (StateData<String, String> stateData : stateDatas) {
if (stateData.getState().equals("S1")) {
assertThat(stateData.isInitial(), is(true));
} else if (stateData.getState().equals("S2")) {
assertThat(stateData.isInitial(), is(false));
} else {
throw new IllegalArgumentException();
}
}
}
@Test
public void testSimpleSubmachine() {
context.refresh();