Fix uml spel state action

- UmlModelParser wrongly set spel based state action as
  exit action. Change this to behave same as bean based
  action is used.
- Fixes #474
This commit is contained in:
Janne Valkealahti
2018-01-19 08:01:48 +00:00
parent 394ded8daa
commit f524ea4f62
4 changed files with 27 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2018 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.
@@ -500,7 +500,7 @@ public class UmlModelParser {
new SpelParserConfiguration(SpelCompilerMode.MIXED, null));
ArrayList<Action<String, String>> stateActions = new ArrayList<Action<String, String>>();
stateActions.add(new SpelExpressionAction<String, String>(parser.parseExpression(expression)));
stateData.setExitActions(stateActions);
stateData.setStateActions(stateActions);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2018 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.
@@ -459,6 +459,8 @@ public class UmlStateMachineModelFactoryTests extends AbstractUmlTests {
context.register(Config11.class);
context.refresh();
StateMachine<String, String> stateMachine = context.getBean(StateMachine.class);
TestExtendedStateListener listener = new TestExtendedStateListener();
stateMachine.addStateListener(listener);
LatchAction e1Action = context.getBean("e1Action", LatchAction.class);
LatchAction s1Exit = context.getBean("s1Exit", LatchAction.class);
LatchAction s2Entry = context.getBean("s2Entry", LatchAction.class);
@@ -469,6 +471,8 @@ public class UmlStateMachineModelFactoryTests extends AbstractUmlTests {
assertThat(e1Action.latch.await(1, TimeUnit.SECONDS), is(true));
assertThat(s1Exit.latch.await(1, TimeUnit.SECONDS), is(true));
assertThat(s2Entry.latch.await(1, TimeUnit.SECONDS), is(true));
assertThat(listener.latch.await(1, TimeUnit.SECONDS), is(true));
assertThat(stateMachine.getExtendedState().getVariables().get("hellos2do"), is("hellos2dovalue"));
}
@Test
@@ -1744,4 +1748,16 @@ public class UmlStateMachineModelFactoryTests extends AbstractUmlTests {
exited.clear();
}
}
private static class TestExtendedStateListener extends StateMachineListenerAdapter<String, String> {
CountDownLatch latch = new CountDownLatch(1);
@Override
public void extendedStateChanged(Object key, Object value) {
if (ObjectUtils.nullSafeEquals(key, "hellos2do")) {
latch.countDown();
}
}
}
}

View File

@@ -49,6 +49,10 @@
<element xmi:type="uml:FunctionBehavior" href="simple-actions.uml#_Pk2SMASYEeaXyaQL1WyV3A"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_Pk_cIQSYEeaXyaQL1WyV3A"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_tUbu8PzjEeeuv4NiH5yIZg" type="691">
<element xmi:type="uml:FunctionBehavior" href="simple-actions.uml#_tSJ3APzjEeeuv4NiH5yIZg"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_tUbu8fzjEeeuv4NiH5yIZg"/>
</children>
<element xmi:type="uml:State" href="simple-actions.uml#_s9CwsASXEeaXyaQL1WyV3A"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_s9FM8QSXEeaXyaQL1WyV3A" x="230" y="207" width="261" height="61"/>
</children>

View File

@@ -17,6 +17,10 @@
</exit>
</subvertex>
<subvertex xmi:type="uml:State" xmi:id="_s9CwsASXEeaXyaQL1WyV3A" name="S2">
<doActivity xmi:type="uml:FunctionBehavior" xmi:id="_tSJ3APzjEeeuv4NiH5yIZg">
<language>spel</language>
<body>extendedState.variables.put('hellos2do','hellos2dovalue')</body>
</doActivity>
<entry xmi:type="uml:FunctionBehavior" xmi:id="_Pk2SMASYEeaXyaQL1WyV3A" name="s2Entry">
<language>bean</language>
<body>s2Entry</body>