use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateReaction_WithTransitionAction.
/**
* The transition action must be part of the reaction effect sequence
*/
@Test
public void testStateReaction_WithTransitionAction() {
SimpleFlatTSC tsc = new SimpleFlatTSC();
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
ReactionEffect effect = _createReactionEffect(tsc.t1);
AssignmentExpression assign = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), effect);
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());
assertClass(Sequence.class, seq.getSteps().get(1));
Execution _exec = (Execution) ((Sequence) seq.getSteps().get(1)).getSteps().get(0);
AssignmentExpression _assign = (AssignmentExpression) _exec.getStatement();
assertNotSame(_assign, assign);
assertNotSame(_assign.getVarRef(), assign.getVarRef());
assertNotSame(_assign.getVarRef(), v1);
assertCall(seq, 2, s2.getEnterSequences().get(0));
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateCycle_ExitActionExclusion.
/**
* Exit action behaviors are not directly part of the states cycle steps
*/
@SuppressWarnings("unused")
@Test
public void testStateCycle_ExitActionExclusion() {
MinimalTSC tsc = new MinimalTSC();
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
// add a simple entry action: "entry / x=42;"
LocalReaction lr = _createExitAction(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.test.util.StextTestFactory._createReactionEffect in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateCycle_LocalReactionWithMixedRegularAndEntryTrigger.
/**
* Local reactions that define regular and entry triggers side by side must
* also be part of the cycle steps.
*/
@SuppressWarnings("unused")
@Test
public void testStateCycle_LocalReactionWithMixedRegularAndEntryTrigger() {
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);
_createRegularEventSpec(tsc.e1, (ReactionTrigger) lr.getTrigger());
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(1, s1.getReactions().size());
assertNotNull(s1.getReactSequence());
assertEquals(1, s1.getReactSequence().getSteps().size());
Sequence _seq = (Sequence) s1.getReactSequence().getSteps().get(0);
If _lr1 = (If) assertedSequence(assertedSequence(assertedSequence(assertedSequence(_seq.getSteps().get(0)).getSteps().get(0)).getSteps().get(0)).getSteps().get(0)).getSteps().get(0);
assertClass(ElementReferenceExpression.class, _lr1.getCheck().getCondition());
assertSame(s1.getReactions().get(0).getCheck().getCondition(), _lr1.getCheck().getCondition());
Call _lr1_eff_call = (Call) _lr1.getThenStep();
assertSame(s1.getReactions().get(0).getEffect(), _lr1_eff_call.getStep());
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect in project statecharts by Yakindu.
the class ModelSequencertDeclarationsTest method testOperationMapping.
/**
* The OperationCalls must map to Operations in Scopes inside the Flow..
*/
@Test
public void testOperationMapping() {
Statechart sc = _createStatechart("test");
InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
OperationDefinition _operation = _createOperation("value", s_scope);
Region r = _createRegion("main", sc);
State s1 = _createState("S1", r);
State s2 = _createState("S2", r);
Transition t = _createTransition(s1, s2);
ReactionTrigger tr = _createReactionTrigger(t);
tr.setGuard(createGuardExpression(_createValue(true)));
ReactionEffect tr1 = _createReactionEffect(t);
FeatureCall _operationCall = _createOperationCall(_operation);
tr1.getActions().add(_operationCall);
ExecutionFlow flow = sequencer.transform(sc);
OperationDefinition _o1 = (OperationDefinition) flow.getScopes().get(0).getDeclarations().get(0);
assertNotSame(_operation, _o1);
assertEquals(_operation.getName(), _o1.getName());
Step step = flow.getStates().get(0).getReactSequence().getSteps().get(0);
If _if = (If) assertedSequence(assertedSequence(assertedSequence(step).getSteps().get(0)).getSteps().get(0)).getSteps().get(0);
Step thenSequence = assertedSequence(((Call) _if.getThenStep()).getStep()).getSteps().get(1);
Execution call = (Execution) assertedSequence(thenSequence).getSteps().get(0);
assertNotSame(_operationCall, call.getStatement());
assertSame(_o1, ((FeatureCall) call.getStatement()).getFeature());
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect in project statecharts by Yakindu.
the class StatechartEnterExistActionTest method testSCLocalReaction.
/**
* The transition sequence must contain all exit actions for parent states
* that will be left by a transition.
*/
@SuppressWarnings("unused")
@Test
public void testSCLocalReaction() {
Statechart sc = _createStatechart("sc");
{
VariableDefinition v = _createVariableDefinition("v", TYPE_INTEGER, getOrCreateInternalScope(sc));
LocalReaction entryAction = _createEntryAction(sc);
ReactionEffect effect = _createReactionEffect(entryAction);
_createVariableAssignment(v, AssignmentOperator.ADD_ASSIGN, _createValue(1), effect);
LocalReaction exitAction = _createExitAction(sc);
effect = _createReactionEffect(exitAction);
_createVariableAssignment(v, AssignmentOperator.ADD_ASSIGN, _createValue(1), effect);
Region r = _createRegion("r", sc);
{
Entry e = _createEntry(EntryKind.INITIAL, null, r);
State s1 = _createState("s1", r);
Transition t = _createTransition(e, s1);
}
}
ExecutionFlow flow = sequencer.transform(sc);
ExecutionRegion region = flow.getRegions().get(0);
assertEquals(0, flow.getReactions().size());
assertedOrder(flow.getEnterSequences().get(0), null, Lists.newArrayList(new StepLeaf(flow.getEntryAction()), new StepLeaf(region.getEnterSequences().get(0))));
assertedOrder(flow.getExitSequence(), null, Lists.newArrayList(new StepLeaf(region.getExitSequence()), new StepLeaf(flow.getExitAction())));
}
Aggregations