Search in sources :

Example 16 with StextTestFactory._createInterfaceScope

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

the class ModelSequencerStateTest method testStateEntryAction.

/**
 * if a state defines a entry action then the execution state must have a
 * entryAction.
 */
@Test
public void testStateEntryAction() {
    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());
    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());
    assertNotNull(_s2.getEntryAction());
    assertNull(_s1.getEntryAction());
}
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) ExecutionScope(org.yakindu.sct.model.sexec.ExecutionScope) Scope(org.yakindu.sct.model.sgraph.Scope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) 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) 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) 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) Test(org.junit.Test)

Example 17 with StextTestFactory._createInterfaceScope

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

the class ModelSequencerStateTest method testCompositeStateExitSequence.

/**
 * A composite state must have a exit sequence. This exit sequence consists
 * of an exit action call and a state switch for all leaf states.
 */
@SuppressWarnings("unused")
@Test
public void testCompositeStateExitSequence() {
    Statechart sc = _createStatechart("cs");
    {
        Scope scope = _createInterfaceScope("interface", sc);
        VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
        Region r = _createRegion("r", sc);
        {
            State s1 = _createState("s1", r);
            {
                _createExitAssignment(v1, s1, 1);
                Region r1_s1 = _createRegion("r1", s1);
                {
                    Entry e = _createEntry(EntryKind.INITIAL, null, r1_s1);
                    State s2 = _createState("s2", r1_s1);
                    State s3 = _createState("s3", r1_s1);
                    _createTransition(e, s2);
                    _createTransition(s2, s3);
                }
                Region r2_s1 = _createRegion("r2", s1);
                {
                    Entry e = _createEntry(EntryKind.INITIAL, null, r2_s1);
                    State s4 = _createState("s4", r2_s1);
                    State s5 = _createState("s5", r2_s1);
                    State s6 = _createState("s6", r2_s1);
                    _createTransition(e, s4);
                }
            }
        }
    }
    ExecutionFlow flow = sequencer.transform(sc);
    ExecutionState _s1 = flow.getStates().get(0);
    assertEquals("s1", _s1.getSimpleName());
    ExecutionState _s2 = flow.getStates().get(1);
    assertEquals("s2", _s2.getSimpleName());
    ExecutionState _s3 = flow.getStates().get(2);
    assertEquals("s3", _s3.getSimpleName());
    ExecutionState _s4 = flow.getStates().get(3);
    assertEquals("s4", _s4.getSimpleName());
    ExecutionState _s5 = flow.getStates().get(4);
    assertEquals("s5", _s5.getSimpleName());
    ExecutionState _s6 = flow.getStates().get(5);
    assertEquals("s6", _s6.getSimpleName());
    assertNotNull(_s1.getExitAction());
    assertNotNull(_s1.getExitSequence());
    assertEquals(3, _s1.getExitSequence().getSteps().size());
    Sequence _r1_s1 = _s2.getSuperScope().getExitSequence();
    assertCall(_s1.getExitSequence(), 0, _r1_s1);
    Sequence _r2_s1 = _s4.getSuperScope().getExitSequence();
    assertCall(_s1.getExitSequence(), 1, _r2_s1);
    Step _switch = _r1_s1.getSteps().get(0);
    assertStateSwitch(_switch, _s2, _s3);
    assertCall(assertedSequence(assertedStateCase(_switch, _s2).getStep()), 0, _s2.getExitSequence());
    assertCall(assertedSequence(assertedStateCase(_switch, _s3).getStep()), 0, _s3.getExitSequence());
    _switch = _r2_s1.getSteps().get(0);
    assertStateSwitch(_switch, _s4, _s5, _s6);
    assertCall(assertedSequence(assertedStateCase(_switch, _s4).getStep()), 0, _s4.getExitSequence());
    assertCall(assertedSequence(assertedStateCase(_switch, _s5).getStep()), 0, _s5.getExitSequence());
    assertCall(assertedSequence(assertedStateCase(_switch, _s6).getStep()), 0, _s6.getExitSequence());
    assertCall(_s1.getExitSequence(), 2, _s1.getExitAction());
}
Also used : 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) ExecutionScope(org.yakindu.sct.model.sexec.ExecutionScope) Scope(org.yakindu.sct.model.sgraph.Scope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) 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) 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) 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) Step(org.yakindu.sct.model.sexec.Step) Test(org.junit.Test)

Example 18 with StextTestFactory._createInterfaceScope

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

the class ModelSequencerStateTest method testStateExitAction.

/**
 * if a state defines a exit action then the execution state must have a
 * exitAction.
 */
@Test
public void testStateExitAction() {
    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(s1);
    _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(21), (ReactionEffect) exitAction.getEffect());
    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());
    assertNotNull(_s1.getExitAction());
    assertNull(_s2.getExitAction());
}
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) ExecutionScope(org.yakindu.sct.model.sexec.ExecutionScope) Scope(org.yakindu.sct.model.sgraph.Scope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) 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) 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) 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) Test(org.junit.Test)

Example 19 with StextTestFactory._createInterfaceScope

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

the class HistoryTest method testEnterStatechart.

@Test
public void testEnterStatechart() {
    Statechart sc = _createStatechart("sc");
    {
        InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
        VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, s_scope);
        Region r = _createRegion("r", sc);
        {
            Entry r_entry = _createEntry(EntryKind.INITIAL, null, r);
            State s1 = _createState("s1", r);
            State s2 = _createState("s2", r);
            {
                _createEntryAssignment(v1, s2, 3);
                Region r2 = _createRegion("r2", s2);
                {
                    Entry e = _createEntry(EntryKind.DEEP_HISTORY, null, r2);
                    State s3 = _createState("s3", r2);
                    {
                        _createEntryAssignment(v1, s3, 4);
                    }
                    State s4 = _createState("s4", r2);
                    {
                        _createEntryAssignment(v1, s4, 6);
                    }
                    _createTransition(e, s3);
                    _createTransition(s3, s4);
                    _createTransition(s4, s3);
                }
            }
            _createTransition(r_entry, s2);
            _createTransition(s1, s2);
            _createTransition(s2, s1);
        }
    }
    ExecutionFlow flow = sequencer.transform(sc);
    ExecutionState _s1 = flow.getStates().get(0);
    assertEquals("sc.r.s1", _s1.getName());
    Sequence enterSequence = flow.getEnterSequences().get(0);
    ExecutionRegion _r = (ExecutionRegion) _s1.getSuperScope();
    assertCall(enterSequence, 0, flow.getEntryAction());
    assertCall(enterSequence, 1, _r.getEnterSequences().get(0));
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) Entry(org.yakindu.sct.model.sgraph.Entry) ExecutionEntry(org.yakindu.sct.model.sexec.ExecutionEntry) HistoryEntry(org.yakindu.sct.model.sexec.HistoryEntry) 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) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) State(org.yakindu.sct.model.sgraph.State) ExecutionRegion(org.yakindu.sct.model.sexec.ExecutionRegion) 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) ExecutionRegion(org.yakindu.sct.model.sexec.ExecutionRegion) Sequence(org.yakindu.sct.model.sexec.Sequence) Test(org.junit.Test)

Example 20 with StextTestFactory._createInterfaceScope

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

the class HistoryTest method testHistoryAsEntry.

@Test
public void testHistoryAsEntry() {
    Statechart sc = _createStatechart("sc");
    {
        InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
        VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, s_scope);
        Region r = _createRegion("r", sc);
        {
            Entry r_entry = _createEntry(EntryKind.INITIAL, null, r);
            State s1 = _createState("s1", r);
            State s2 = _createState("s2", r);
            {
                _createEntryAssignment(v1, s2, 3);
                Region r2 = _createRegion("r2", s2);
                {
                    Entry e = _createEntry(EntryKind.DEEP_HISTORY, null, r2);
                    State s3 = _createState("s3", r2);
                    {
                        _createEntryAssignment(v1, s3, 4);
                    }
                    State s4 = _createState("s4", r2);
                    {
                        _createEntryAssignment(v1, s4, 6);
                    }
                    _createTransition(e, s3);
                    _createTransition(s3, s4);
                    _createTransition(s4, s3);
                }
            }
            _createTransition(r_entry, s2);
            _createTransition(s1, s2);
            _createTransition(s2, s1);
        }
    }
    ExecutionFlow flow = sequencer.transform(sc);
    ExecutionState _s2 = flow.getStates().get(1);
    assertEquals("sc.r.s2", _s2.getName());
    ExecutionState _s3 = flow.getStates().get(2);
    assertEquals("sc.r.s2.r2.s3", _s3.getName());
    ExecutionNode e = flow.getNodes().get(1);
    assertTrue(e.eClass().getName(), e instanceof ExecutionEntry);
    Sequence reactSequence = e.getReactSequence();
    assertEquals("Default react sequence for deep history entry ", reactSequence.getComment());
    Step historyEntryStep = reactSequence.getSteps().get(0);
    assertTrue(historyEntryStep.eClass().getName(), historyEntryStep instanceof HistoryEntry);
    HistoryEntry historyEntry = (HistoryEntry) historyEntryStep;
    Sequence initialStep = (Sequence) historyEntry.getInitialStep();
    assertCall(((Sequence) initialStep.getSteps().get(0)).getSteps().get(0), _s3.getEnterSequences().get(0));
    ExecutionRegion _r2 = (ExecutionRegion) _s3.getSuperScope();
    assertCall(historyEntry.getHistoryStep(), _r2.getDeepEnterSequence());
    Step _s3EnterStep = assertedStateCase(_r2.getDeepEnterSequence().getSteps().get(0), _s3).getStep();
    Step _s3EnterCall = assertedSequence(_s3EnterStep).getSteps().get(0);
    assertCall(_s3EnterCall, _s3.getEnterSequences().get(0));
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) ExecutionNode(org.yakindu.sct.model.sexec.ExecutionNode) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) ExecutionEntry(org.yakindu.sct.model.sexec.ExecutionEntry) Sequence(org.yakindu.sct.model.sexec.Sequence) Step(org.yakindu.sct.model.sexec.Step) Entry(org.yakindu.sct.model.sgraph.Entry) ExecutionEntry(org.yakindu.sct.model.sexec.ExecutionEntry) HistoryEntry(org.yakindu.sct.model.sexec.HistoryEntry) SGraphTestFactory._createEntry(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry) 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) ExecutionRegion(org.yakindu.sct.model.sexec.ExecutionRegion) 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) HistoryEntry(org.yakindu.sct.model.sexec.HistoryEntry) Test(org.junit.Test)

Aggregations

StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)50 Test (org.junit.Test)49 Region (org.yakindu.sct.model.sgraph.Region)48 Statechart (org.yakindu.sct.model.sgraph.Statechart)48 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)48 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)48 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)47 State (org.yakindu.sct.model.sgraph.State)46 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)46 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)46 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)46 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)44 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)43 Sequence (org.yakindu.sct.model.sexec.Sequence)34 SCTTestUtil.findState (org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState)27 Entry (org.yakindu.sct.model.sgraph.Entry)26 SGraphTestFactory._createEntry (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry)26 EnterState (org.yakindu.sct.model.sexec.EnterState)20 Reaction (org.yakindu.sct.model.sexec.Reaction)18 Scope (org.yakindu.sct.model.sgraph.Scope)17