Search in sources :

Example 1 with FinalState

use of org.yakindu.sct.model.sgraph.FinalState in project statecharts by Yakindu.

the class ModelSequencerStateTest method testFinalStateEnterSequence.

/**
 * A leaf state must have a enter sequence. This enter sequence consists of
 * an entry action call and a state enter step.
 */
@SuppressWarnings("unused")
@Test
public void testFinalStateEnterSequence() {
    Statechart sc = _createStatechart("cs");
    Scope scope = _createInterfaceScope("interface", sc);
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
    Region r = _createRegion("r", sc);
    FinalState fs = _createFinalState(r);
    ExecutionFlow flow = sequencer.transform(sc);
    ExecutionState _fs = flow.getStates().get(0);
    assertEquals("_final_0", _fs.getSimpleName());
    assertSame(fs, _fs.getSourceElement());
    assertNull(_fs.getEntryAction());
    assertNotNull(_fs.getEnterSequences().get(0));
    assertEquals(1, _fs.getEnterSequences().get(0).getSteps().size());
    assertClass(EnterState.class, _fs.getEnterSequences().get(0).getSteps().get(0));
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) 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) 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) FinalState(org.yakindu.sct.model.sgraph.FinalState) SGraphTestFactory._createFinalState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createFinalState) Test(org.junit.Test)

Example 2 with FinalState

use of org.yakindu.sct.model.sgraph.FinalState in project statecharts by Yakindu.

the class ModelSequencerStateTest method testFinalStateExitSequence.

/**
 * A final state must have a exit sequence. This exit sequence consists of a
 * state exit step.
 */
@SuppressWarnings("unused")
@Test
public void testFinalStateExitSequence() {
    Statechart sc = _createStatechart("cs");
    Scope scope = _createInterfaceScope("interface", sc);
    Region r = _createRegion("r", sc);
    FinalState fs = _createFinalState(r);
    ExecutionFlow flow = sequencer.transform(sc);
    ExecutionState _fs = flow.getStates().get(0);
    assertEquals("_final_0", _fs.getSimpleName());
    assertNull(_fs.getExitAction());
    assertNotNull(_fs.getExitSequence());
    assertEquals(1, _fs.getExitSequence().getSteps().size());
    assertClass(ExitState.class, _fs.getExitSequence().getSteps().get(0));
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) 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) 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) FinalState(org.yakindu.sct.model.sgraph.FinalState) SGraphTestFactory._createFinalState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createFinalState) Test(org.junit.Test)

Example 3 with FinalState

use of org.yakindu.sct.model.sgraph.FinalState 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)

Example 4 with FinalState

use of org.yakindu.sct.model.sgraph.FinalState in project statecharts by Yakindu.

the class SGraphJavaValidationTest method finalStateIsolated.

/**
 * A final state should have at least one incoming transition.
 */
@Test
public void finalStateIsolated() {
    statechart = factory.createStatechart();
    Region region = factory.createRegion();
    statechart.getRegions().add(region);
    FinalState finalState = factory.createFinalState();
    region.getVertices().add(finalState);
    assertFalse(validate(finalState));
    assertIssueCount(diagnostics, 1);
    assertError(diagnostics, ISSUE_NODE_NOT_REACHABLE);
}
Also used : Region(org.yakindu.sct.model.sgraph.Region) FinalState(org.yakindu.sct.model.sgraph.FinalState) Test(org.junit.Test)

Example 5 with FinalState

use of org.yakindu.sct.model.sgraph.FinalState in project statecharts by Yakindu.

the class SGraphJavaValidationTest method finalStateValid.

/**
 * A positive case for a valid final state.
 */
@Test
public void finalStateValid() {
    statechart = factory.createStatechart();
    Region region = factory.createRegion();
    statechart.getRegions().add(region);
    FinalState finalState = factory.createFinalState();
    region.getVertices().add(finalState);
    State state = factory.createState();
    region.getVertices().add(state);
    createTransition(state, finalState);
    assertTrue(validate(finalState));
    assertIssueCount(diagnostics, 0);
}
Also used : FinalState(org.yakindu.sct.model.sgraph.FinalState) State(org.yakindu.sct.model.sgraph.State) Region(org.yakindu.sct.model.sgraph.Region) FinalState(org.yakindu.sct.model.sgraph.FinalState) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 FinalState (org.yakindu.sct.model.sgraph.FinalState)8 Region (org.yakindu.sct.model.sgraph.Region)8 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)5 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)5 State (org.yakindu.sct.model.sgraph.State)5 Statechart (org.yakindu.sct.model.sgraph.Statechart)5 SGraphTestFactory._createFinalState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createFinalState)5 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)5 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)5 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)5 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)5 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)4 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)4 EnterState (org.yakindu.sct.model.sexec.EnterState)3 ExecutionScope (org.yakindu.sct.model.sexec.ExecutionScope)3 ExitState (org.yakindu.sct.model.sexec.ExitState)3 SCTTestUtil.findState (org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState)3 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)3 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)3