Search in sources :

Example 6 with ReactionTrigger

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

the class ModelSequencerStateReactionTest method testTransitionCheckSequenceWithGuard.

@Test
public void testTransitionCheckSequenceWithGuard() {
    EventDefinition e1 = _createEventDefinition("e1", null);
    EventDefinition e2 = _createEventDefinition("e2", null);
    ReactionTrigger tr1 = _createReactionTrigger(null);
    _createRegularEventSpec(e1, tr1);
    _createRegularEventSpec(e2, tr1);
    PrimitiveValueExpression exp = _createValue(false);
    tr1.setGuard(createGuardExpression(exp));
    Transition t = SGraphFactory.eINSTANCE.createTransition();
    t.setTrigger(tr1);
    Statechart sc = _createStatechart("test");
    Region region = _createRegion("r1", sc);
    t.setSource(_createState("A", region));
    t.setTarget(_createState("B", region));
    Reaction reaction = behaviorMapping.mapTransition(t);
    // now check the expression structure ...
    // the root is an and condition with the trigger check as the first
    // (left) part and the guard as the right (second) part.
    LogicalAndExpression and = (LogicalAndExpression) reaction.getCheck().getCondition();
    ParenthesizedExpression parenthesis = (ParenthesizedExpression) and.getLeftOperand();
    LogicalOrExpression triggerCheck = (LogicalOrExpression) parenthesis.getExpression();
    PrimitiveValueExpression guardCheck = (PrimitiveValueExpression) ((ParenthesizedExpression) and.getRightOperand()).getExpression();
    assertClass(ElementReferenceExpression.class, triggerCheck.getLeftOperand());
    assertClass(ElementReferenceExpression.class, triggerCheck.getRightOperand());
    assertEquals(e1.getName(), ((NamedElement) ((ElementReferenceExpression) triggerCheck.getLeftOperand()).getReference()).getName());
    assertEquals(e2.getName(), ((NamedElement) ((ElementReferenceExpression) triggerCheck.getRightOperand()).getReference()).getName());
    assertBoolLiteral(false, guardCheck.getValue());
}
Also used : ParenthesizedExpression(org.yakindu.base.expressions.expressions.ParenthesizedExpression) LogicalAndExpression(org.yakindu.base.expressions.expressions.LogicalAndExpression) StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) LogicalOrExpression(org.yakindu.base.expressions.expressions.LogicalOrExpression) 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) StextTestFactory._createEventDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createTimeTriggeredReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createTimeTriggeredReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) Reaction(org.yakindu.sct.model.sexec.Reaction) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) Test(org.junit.Test)

Example 7 with ReactionTrigger

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

the class ModelSequencerStateReactionTest method testEntryActionWithGuard.

/**
 * If a entry trigger is combined with a guard condition then the entry
 * action is executed conditionally with this trigger.
 */
@Test
public void testEntryActionWithGuard() {
    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());
    ((ReactionTrigger) entryAction.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 _entrySeq = (Sequence) _s2.getEntryAction();
    assertClass(If.class, _entrySeq.getSteps().get(0));
    assertClass(PrimitiveValueExpression.class, ((If) _entrySeq.getSteps().get(0)).getCheck().getCondition());
    assertAssignment(((Sequence) ((If) _entrySeq.getSteps().get(0)).getThenStep()).getSteps().get(0), "v1", AssignmentOperator.ASSIGN, "42");
}
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) Entry(org.yakindu.sct.model.sgraph.Entry) SGraphTestFactory._createEntry(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry) Scope(org.yakindu.sct.model.sgraph.Scope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) 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) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) State(org.yakindu.sct.model.sgraph.State) 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) Sequence(org.yakindu.sct.model.sexec.Sequence) If(org.yakindu.sct.model.sexec.If) Test(org.junit.Test)

Example 8 with ReactionTrigger

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

the class ModelSequencerStateReactionTest method testTransitionCheckSequenceWithoutGuard.

@Test
public void testTransitionCheckSequenceWithoutGuard() {
    EventDefinition e1 = _createEventDefinition("e1", null);
    EventDefinition e2 = _createEventDefinition("e2", null);
    ReactionTrigger tr1 = _createReactionTrigger(null);
    _createRegularEventSpec(e1, tr1);
    _createRegularEventSpec(e2, tr1);
    Transition t = SGraphFactory.eINSTANCE.createTransition();
    t.setTrigger(tr1);
    Statechart sc = _createStatechart("test");
    Region region = _createRegion("r1", sc);
    t.setSource(_createState("A", region));
    t.setTarget(_createState("B", region));
    Reaction reaction = behaviorMapping.mapTransition(t);
    assertTrue(reaction.getCheck().getCondition() instanceof LogicalOrExpression);
    assertClass(ElementReferenceExpression.class, ((LogicalOrExpression) reaction.getCheck().getCondition()).getLeftOperand());
    assertClass(ElementReferenceExpression.class, ((LogicalOrExpression) reaction.getCheck().getCondition()).getRightOperand());
    assertEquals(e1.getName(), ((NamedElement) ((ElementReferenceExpression) ((LogicalOrExpression) reaction.getCheck().getCondition()).getLeftOperand()).getReference()).getName());
    assertEquals(e2.getName(), ((NamedElement) ((ElementReferenceExpression) ((LogicalOrExpression) reaction.getCheck().getCondition()).getRightOperand()).getReference()).getName());
}
Also used : StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) LogicalOrExpression(org.yakindu.base.expressions.expressions.LogicalOrExpression) 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) StextTestFactory._createEventDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createTimeTriggeredReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createTimeTriggeredReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) Reaction(org.yakindu.sct.model.sexec.Reaction) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) Test(org.junit.Test)

Example 9 with ReactionTrigger

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

the class ModelSequencerStateReactionTest method testTransitionCheckSequenceWithoutTrigger.

@Test
public void testTransitionCheckSequenceWithoutTrigger() {
    ReactionTrigger tr1 = _createReactionTrigger(null);
    PrimitiveValueExpression exp = _createValue(false);
    tr1.setGuard(createGuardExpression(exp));
    Transition t = SGraphFactory.eINSTANCE.createTransition();
    t.setTrigger(tr1);
    Statechart sc = _createStatechart("test");
    Region region = _createRegion("r1", sc);
    t.setSource(_createState("A", region));
    t.setTarget(_createState("B", region));
    Reaction reaction = behaviorMapping.mapTransition(t);
    // now check the expression structure ...
    // the root is an and condition with the trigger check as the first
    // (left) part and the guard as the right (second) part.
    PrimitiveValueExpression guard = (PrimitiveValueExpression) reaction.getCheck().getCondition();
    assertBoolLiteral(false, guard.getValue());
}
Also used : StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) 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) LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createTimeTriggeredReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createTimeTriggeredReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) Reaction(org.yakindu.sct.model.sexec.Reaction) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) Test(org.junit.Test)

Example 10 with ReactionTrigger

use of org.yakindu.sct.model.stext.stext.ReactionTrigger 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");
}
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) Entry(org.yakindu.sct.model.sgraph.Entry) SGraphTestFactory._createEntry(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry) Scope(org.yakindu.sct.model.sgraph.Scope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) 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) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) State(org.yakindu.sct.model.sgraph.State) 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) Sequence(org.yakindu.sct.model.sexec.Sequence) If(org.yakindu.sct.model.sexec.If) Test(org.junit.Test)

Aggregations

ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)26 Test (org.junit.Test)20 StextTestFactory._createReactionTrigger (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger)16 LocalReaction (org.yakindu.sct.model.stext.stext.LocalReaction)14 Statechart (org.yakindu.sct.model.sgraph.Statechart)13 Region (org.yakindu.sct.model.sgraph.Region)12 Transition (org.yakindu.sct.model.sgraph.Transition)12 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)11 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)11 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)11 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)10 If (org.yakindu.sct.model.sexec.If)10 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)10 StextTestFactory._createLocalReaction (org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction)10 State (org.yakindu.sct.model.sgraph.State)9 SGraphTestFactory._createTransition (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition)9 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)9 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)8 PrimitiveValueExpression (org.yakindu.base.expressions.expressions.PrimitiveValueExpression)8 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)8