use of org.yakindu.sct.model.sexec.Execution 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.sexec.Execution 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.sexec.Execution in project statecharts by Yakindu.
the class Assert method assertAssignment.
public static void assertAssignment(Step step, String variableName, AssignmentOperator operator, String value) {
assertClass(Execution.class, step);
Execution exec = (Execution) step;
assertTrue(exec.getStatement() instanceof AssignmentExpression);
AssignmentExpression assignment = (AssignmentExpression) exec.getStatement();
assertEquals(operator, assignment.getOperator());
Expression varRef = assignment.getVarRef();
if (varRef instanceof ElementReferenceExpression) {
ElementReferenceExpression elementRef = (ElementReferenceExpression) varRef;
assertEquals(variableName, ((NamedElement) elementRef.getReference()).getName());
} else if (varRef instanceof FeatureCall) {
FeatureCall call = (FeatureCall) varRef;
assertEquals(variableName, ((NamedElement) call.getFeature()).getName());
}
assertExpressionEquals(value, assignment.getExpression());
}
Aggregations