Search in sources :

Example 1 with StextTestFactory._createEventDefinition

use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition in project statecharts by Yakindu.

the class ModelSequencerStateReactionTest method testSingleRegularEventTriggerCondition.

/**
 * Single trigger events of a Reaction Trigger will be converted into a
 * single condition that consists of a ElementReferenceExpression to the
 * corresponding event definition.
 */
@Test
public void testSingleRegularEventTriggerCondition() {
    EventDefinition e1 = _createEventDefinition("e1", null);
    ReactionTrigger tr1 = _createReactionTrigger(null);
    _createRegularEventSpec(e1, tr1);
    Expression s = behaviorMapping.buildCondition(tr1);
    assertClass(ElementReferenceExpression.class, s);
}
Also used : StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) LogicalAndExpression(org.yakindu.base.expressions.expressions.LogicalAndExpression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) LogicalOrExpression(org.yakindu.base.expressions.expressions.LogicalOrExpression) NumericalMultiplyDivideExpression(org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) StextTestFactory.createGuardExpression(org.yakindu.sct.model.stext.test.util.StextTestFactory.createGuardExpression) Expression(org.yakindu.base.expressions.expressions.Expression) ParenthesizedExpression(org.yakindu.base.expressions.expressions.ParenthesizedExpression) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) StextTestFactory._createEventDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) Test(org.junit.Test)

Example 2 with StextTestFactory._createEventDefinition

use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition 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 3 with StextTestFactory._createEventDefinition

use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition 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 4 with StextTestFactory._createEventDefinition

use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition in project statecharts by Yakindu.

the class ModelSequencertDeclarationsTest method testMapScope.

@SuppressWarnings("unused")
@Test
public void testMapScope() {
    InterfaceScope scope = _createInterfaceScope(null, null);
    EventDefinition e1 = _createEventDefinition("e1", scope);
    EventDefinition e2 = _createEventDefinition("e2", scope);
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
    Scope _scope = structureMapping.mapScope(scope);
    assertTrue(_scope instanceof InterfaceScope);
    assertEquals(3, _scope.getDeclarations().size());
    for (int i = 0; i < _scope.getDeclarations().size(); i++) {
        Declaration s_decl = scope.getDeclarations().get(i);
        Declaration r_decl = _scope.getDeclarations().get(i);
        assertNotSame(s_decl, r_decl);
        assertEquals(s_decl.getName(), r_decl.getName());
        assertEquals(s_decl.getClass(), r_decl.getClass());
    }
}
Also used : VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) StextTestFactory._createInternalScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInternalScope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) Scope(org.yakindu.sct.model.sgraph.Scope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) Declaration(org.yakindu.base.types.Declaration) StextTestFactory._createEventDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) Test(org.junit.Test)

Example 5 with StextTestFactory._createEventDefinition

use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition in project statecharts by Yakindu.

the class ModelSequencerStateTest method testFinalStateEnterSequenceCall.

/**
 * The enter sequence must be called withnin incoming transitions.
 */
@SuppressWarnings("unused")
@Test
public void testFinalStateEnterSequenceCall() {
    Statechart sc = _createStatechart("sc");
    {
        InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
        VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, s_scope);
        EventDefinition e1 = _createEventDefinition("e1", s_scope);
        Region r = _createRegion("r", sc);
        {
            State s1 = _createState("s1", r);
            FinalState fs = _createFinalState(r);
            Transition t_s1_fs = _createTransition(s1, fs);
            _createReactionTrigger(t_s1_fs);
            _createRegularEventSpec(e1, (ReactionTrigger) t_s1_fs.getTrigger());
        }
    }
    ExecutionFlow flow = sequencer.transform(sc);
    ExecutionState _s1 = flow.getStates().get(0);
    assertEquals("sc.r.s1", _s1.getName());
    ExecutionState _fs = flow.getStates().get(1);
    assertEquals("sc.r._final_", _fs.getName());
    assertNull(_fs.getEntryAction());
    assertNull(_fs.getExitAction());
    // the transition s1 -> fs must includes the fs exit sequence call
    Sequence cycle = _s1.getReactSequence();
    If _if = (If) SCTTestUtil.flattenSequenceStepsAsList(cycle).get(0);
    assertCall(_if.getThenStep(), _s1.getReactions().get(0).getEffect());
    Sequence _seq = (Sequence) _s1.getReactions().get(0).getEffect();
    assertCall(_seq, 1, _fs.getEnterSequences().get(0));
}
Also used : 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) FinalState(org.yakindu.sct.model.sgraph.FinalState) SGraphTestFactory._createFinalState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createFinalState) ExitState(org.yakindu.sct.model.sexec.ExitState) SCTTestUtil.findState(org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) EnterState(org.yakindu.sct.model.sexec.EnterState) 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) 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) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) 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) StextTestFactory._createEventDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) FinalState(org.yakindu.sct.model.sgraph.FinalState) SGraphTestFactory._createFinalState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createFinalState) If(org.yakindu.sct.model.sexec.If) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)10 StextTestFactory._createEventDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition)10 Region (org.yakindu.sct.model.sgraph.Region)7 Statechart (org.yakindu.sct.model.sgraph.Statechart)7 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)7 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)7 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)7 StextTestFactory._createReactionTrigger (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger)7 Transition (org.yakindu.sct.model.sgraph.Transition)6 SGraphTestFactory._createTransition (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition)6 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)6 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)6 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)5 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)5 State (org.yakindu.sct.model.sgraph.State)5 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)5 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)5 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)5 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)4