Search in sources :

Example 26 with LocalReaction

use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.

the class ModelSequencerStateReactionTest method testSingleLocalTimeTrigger.

/**
 */
@SuppressWarnings("unused")
@Test
public void testSingleLocalTimeTrigger() {
    Statechart sc = _createStatechart("test");
    Scope scope = _createInterfaceScope("interface", sc);
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
    Region r = _createRegion("main", sc);
    State s = _createState("s", r);
    LocalReaction timeTriggeredReaction = _createTimeTriggeredReaction(s, TimeEventType.AFTER, _createValue(2), TimeUnit.MILLISECOND);
    AssignmentExpression assign = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) timeTriggeredReaction.getEffect());
    ExecutionFlow flow = sequencer.transform(sc);
    Scope timerScope = flow.getScopes().get(1);
    assertTrue(timerScope.getDeclarations().get(0) instanceof TimeEvent);
    TimeEvent te = (TimeEvent) timerScope.getDeclarations().get(0);
    // assert that the reaction check checks the time event
    ExecutionState _s = flow.getStates().get(0);
    // assert the scheduling of the time event during state entry
    assertNotNull(_s.getEntryAction());
    Sequence entryAction = (Sequence) _s.getEntryAction();
    ScheduleTimeEvent ste = (ScheduleTimeEvent) entryAction.getSteps().get(0);
    assertSame(te, ste.getTimeEvent());
    PrimitiveValueExpression value = (PrimitiveValueExpression) ste.getTimeValue();
    assertIntLiteral(2, value.getValue());
    assertNotNull(_s.getExitAction());
    Sequence exitAction = (Sequence) _s.getExitAction();
    UnscheduleTimeEvent ute = (UnscheduleTimeEvent) exitAction.getSteps().get(0);
    assertSame(te, ute.getTimeEvent());
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Sequence(org.yakindu.sct.model.sexec.Sequence) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) ScheduleTimeEvent(org.yakindu.sct.model.sexec.ScheduleTimeEvent) Scope(org.yakindu.sct.model.sgraph.Scope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) State(org.yakindu.sct.model.sgraph.State) UnscheduleTimeEvent(org.yakindu.sct.model.sexec.UnscheduleTimeEvent) 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) TimeEvent(org.yakindu.sct.model.sexec.TimeEvent) UnscheduleTimeEvent(org.yakindu.sct.model.sexec.UnscheduleTimeEvent) ScheduleTimeEvent(org.yakindu.sct.model.sexec.ScheduleTimeEvent) Test(org.junit.Test)

Example 27 with LocalReaction

use of org.yakindu.sct.model.stext.stext.LocalReaction 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())));
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) Entry(org.yakindu.sct.model.sgraph.Entry) SGraphTestFactory._createEntry(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) State(org.yakindu.sct.model.sgraph.State) ExecutionRegion(org.yakindu.sct.model.sexec.ExecutionRegion) Transition(org.yakindu.sct.model.sgraph.Transition) SGraphTestFactory._createTransition(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) 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) ExecutionRegion(org.yakindu.sct.model.sexec.ExecutionRegion) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) StextTestFactory._createReactionEffect(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect) Test(org.junit.Test)

Example 28 with LocalReaction

use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.

the class StextTestFactory method _createLocalReaction.

public static LocalReaction _createLocalReaction(State parent, EventSpec triggerEvent) {
    LocalReaction reaction = _createLocalReaction(triggerEvent);
    Scope scope = getOrCreateSimpleScope(parent);
    scope.getReactions().add(reaction);
    return reaction;
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) SimpleScope(org.yakindu.sct.model.stext.stext.SimpleScope) Scope(org.yakindu.sct.model.sgraph.Scope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope)

Example 29 with LocalReaction

use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.

the class StextTestFactory method _createLocalReaction.

public static LocalReaction _createLocalReaction(EventSpec triggerEvent) {
    LocalReaction reaction = StextFactory.eINSTANCE.createLocalReaction();
    ReactionTrigger trigger = StextFactory.eINSTANCE.createReactionTrigger();
    _createReactionEffect(reaction);
    if (triggerEvent != null)
        trigger.getTriggers().add(triggerEvent);
    reaction.setTrigger(trigger);
    return reaction;
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger)

Example 30 with LocalReaction

use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.

the class StextTestFactory method _createEntryAssignment.

public static void _createEntryAssignment(VariableDefinition v1, State s1, int value) {
    LocalReaction entryAction = _createEntryAction(s1);
    _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(value), (ReactionEffect) entryAction.getEffect());
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction)

Aggregations

LocalReaction (org.yakindu.sct.model.stext.stext.LocalReaction)31 Test (org.junit.Test)23 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)22 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)22 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)22 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)21 StextTestFactory._createLocalReaction (org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction)21 Scope (org.yakindu.sct.model.sgraph.Scope)16 State (org.yakindu.sct.model.sgraph.State)16 Region (org.yakindu.sct.model.sgraph.Region)15 Statechart (org.yakindu.sct.model.sgraph.Statechart)15 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)15 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)15 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)15 Sequence (org.yakindu.sct.model.sexec.Sequence)13 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)13 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)12 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)11 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)11 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)10