Search in sources :

Example 1 with Execution

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));
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) SimpleFlatTSC(org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.SimpleFlatTSC) Execution(org.yakindu.sct.model.sexec.Execution) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) StextTestFactory._createReactionEffect(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect) Sequence(org.yakindu.sct.model.sexec.Sequence) LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) Reaction(org.yakindu.sct.model.sexec.Reaction) Test(org.junit.Test)

Example 2 with Execution

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());
}
Also used : ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) StextTestFactory._createReactionEffect(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect) Step(org.yakindu.sct.model.sexec.Step) Execution(org.yakindu.sct.model.sexec.Execution) StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) State(org.yakindu.sct.model.sgraph.State) Transition(org.yakindu.sct.model.sgraph.Transition) SGraphTestFactory._createTransition(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition) Statechart(org.yakindu.sct.model.sgraph.Statechart) SGraphTestFactory._createStatechart(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart) Region(org.yakindu.sct.model.sgraph.Region) SGraphTestFactory._createRegion(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion) OperationDefinition(org.yakindu.sct.model.stext.stext.OperationDefinition) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) If(org.yakindu.sct.model.sexec.If) Test(org.junit.Test)

Example 3 with Execution

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());
}
Also used : Execution(org.yakindu.sct.model.sexec.Execution) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) Expression(org.yakindu.base.expressions.expressions.Expression) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) NamedElement(org.yakindu.base.base.NamedElement)

Aggregations

Execution (org.yakindu.sct.model.sexec.Execution)3 Test (org.junit.Test)2 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)2 FeatureCall (org.yakindu.base.expressions.expressions.FeatureCall)2 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)2 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)2 StextTestFactory._createReactionEffect (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect)2 NamedElement (org.yakindu.base.base.NamedElement)1 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)1 Expression (org.yakindu.base.expressions.expressions.Expression)1 PrimitiveValueExpression (org.yakindu.base.expressions.expressions.PrimitiveValueExpression)1 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)1 If (org.yakindu.sct.model.sexec.If)1 Reaction (org.yakindu.sct.model.sexec.Reaction)1 Sequence (org.yakindu.sct.model.sexec.Sequence)1 Step (org.yakindu.sct.model.sexec.Step)1 SimpleFlatTSC (org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.SimpleFlatTSC)1 Region (org.yakindu.sct.model.sgraph.Region)1 State (org.yakindu.sct.model.sgraph.State)1 Statechart (org.yakindu.sct.model.sgraph.Statechart)1