use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testExitActionWithGuard.
/**
* If a entry trigger is combined with a guard condition then the entry
* action is executed conditionally with this trigger.
*/
@Test
public void testExitActionWithGuard() {
Statechart sc = _createStatechart("test");
Scope scope = _createInterfaceScope("interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
Region r = _createRegion("main", sc);
Entry e = _createEntry(EntryKind.INITIAL, null, r);
State s1 = _createState("s1", r);
State s2 = _createState("s2", r);
_createTransition(e, s1);
_createTransition(s1, s2);
LocalReaction exitAction = _createExitAction(s2);
_createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) exitAction.getEffect());
((ReactionTrigger) exitAction.getTrigger()).setGuard(createGuardExpression(_createValue(true)));
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s1 = flow.getStates().get(0);
ExecutionState _s2 = flow.getStates().get(1);
assertEquals(s1.getName(), _s1.getSimpleName());
assertEquals(s2.getName(), _s2.getSimpleName());
Sequence _exitSeq = (Sequence) _s2.getExitAction();
assertClass(If.class, _exitSeq.getSteps().get(0));
assertClass(PrimitiveValueExpression.class, ((If) _exitSeq.getSteps().get(0)).getCheck().getCondition());
assertAssignment(((Sequence) ((If) _exitSeq.getSteps().get(0)).getThenStep()).getSteps().get(0), "v1", AssignmentOperator.ASSIGN, "42");
}
use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateEntryAction.
/**
* if a state defines a entry action then the execution state must have a
* entryAction.
*/
@Test
public void testStateEntryAction() {
Statechart sc = _createStatechart("test");
Scope scope = _createInterfaceScope("interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
Region r = _createRegion("main", sc);
Entry e = _createEntry(EntryKind.INITIAL, null, r);
State s1 = _createState("s1", r);
State s2 = _createState("s2", r);
_createTransition(e, s1);
_createTransition(s1, s2);
LocalReaction entryAction = _createEntryAction(s2);
_createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) entryAction.getEffect());
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s1 = flow.getStates().get(0);
ExecutionState _s2 = flow.getStates().get(1);
assertEquals(s1.getName(), _s1.getSimpleName());
assertEquals(s2.getName(), _s2.getSimpleName());
assertNotNull(_s2.getEntryAction());
assertNull(_s1.getEntryAction());
}
use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateReaction_WithExitAction.
/**
* The exit action must be part of the reaction effect sequence
*/
@SuppressWarnings("unused")
@Test
public void testStateReaction_WithExitAction() {
SimpleFlatTSC tsc = new SimpleFlatTSC();
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
LocalReaction exitAction = _createExitAction(tsc.s1);
AssignmentExpression assign = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(21), (ReactionEffect) exitAction.getEffect());
ExecutionFlow flow = sequencer.transform(tsc.sc);
// test state with one outgoing transition
ExecutionState _s1 = flow.getStates().get(0);
ExecutionState _s2 = flow.getStates().get(1);
assertEquals(tsc.s1.getName(), _s1.getSimpleName());
assertEquals(tsc.s2.getName(), _s2.getSimpleName());
assertEquals(1, _s1.getReactions().size());
Reaction reaction = _s1.getReactions().get(0);
assertNotNull(reaction.getCheck());
assertNotNull(reaction.getEffect());
Sequence seq = (Sequence) reaction.getEffect();
assertCall(seq, 0, _s1.getExitSequence());
assertCall(_s1.getExitSequence(), 1, _s1.getExitAction());
}
use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateCycle_EntryActionExclusion.
/**
* Entry action behaviors are not directly part of the states cycle steps
*/
@SuppressWarnings("unused")
@Test
public void testStateCycle_EntryActionExclusion() {
MinimalTSC tsc = new MinimalTSC();
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
// add a simple entry action: "entry / x=42;"
LocalReaction lr = _createEntryAction(tsc.s1);
ReactionEffect lr_eff = _createReactionEffect(lr);
AssignmentExpression assign1 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr_eff);
// TRANSFORM
ExecutionFlow flow = sequencer.transform(tsc.sc);
// test state with one outgoing transition
ExecutionState s1 = flow.getStates().get(0);
assertEquals(0, s1.getReactions().size());
assertNotNull(s1.getReactSequence());
assertEquals(1, s1.getReactSequence().getSteps().size());
}
use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateExitAction.
/**
* if a state defines a exit action then the execution state must have a
* exitAction.
*/
@Test
public void testStateExitAction() {
Statechart sc = _createStatechart("test");
Scope scope = _createInterfaceScope("interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
Region r = _createRegion("main", sc);
Entry e = _createEntry(EntryKind.INITIAL, null, r);
State s1 = _createState("s1", r);
State s2 = _createState("s2", r);
_createTransition(e, s1);
_createTransition(s1, s2);
LocalReaction exitAction = _createExitAction(s1);
_createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(21), (ReactionEffect) exitAction.getEffect());
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s1 = flow.getStates().get(0);
ExecutionState _s2 = flow.getStates().get(1);
assertEquals(s1.getName(), _s1.getSimpleName());
assertEquals(s2.getName(), _s2.getSimpleName());
assertNotNull(_s1.getExitAction());
assertNull(_s2.getExitAction());
}
Aggregations