Search in sources :

Example 21 with Transition

use of org.yakindu.sct.model.sgraph.Transition 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 22 with Transition

use of org.yakindu.sct.model.sgraph.Transition 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 23 with Transition

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

the class AbstractSTextValidationTest method createTransition.

protected Transition createTransition(Vertex source, Vertex target) {
    Transition trans = SGraphFactory.eINSTANCE.createTransition();
    trans.setSource(source);
    trans.setTarget(target);
    source.getOutgoingTransitions().add(trans);
    target.getIncomingTransitions().add(trans);
    return trans;
}
Also used : Transition(org.yakindu.sct.model.sgraph.Transition)

Example 24 with Transition

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

the class TransitionsWithNoTriggerTest method noTriggerOnSyncOutgoing.

/**
 * The outgoing transitions of a sync (fork / join) node must not have any
 * trigger part. Thus empty transitions must not have any warning. This test
 * case addresses a bug #75 (
 * https://code.google.com/a/eclipselabs.org/p/yakindu/issues/detail?id=75 )
 * .
 */
@Test
public void noTriggerOnSyncOutgoing() {
    statechart = loadStatechart("ValidEmptyTransitionFromSync.sct");
    Region validRegion = firstNamed(eAllOfType(statechart, Region.class), "valid");
    Synchronization sync = eAllOfType(validRegion, Synchronization.class).get(0);
    for (Transition t : sync.getOutgoingTransitions()) {
        assertTrue(validate(t));
        assertIssueCount(diagnostics, 0);
    }
}
Also used : Transition(org.yakindu.sct.model.sgraph.Transition) Region(org.yakindu.sct.model.sgraph.Region) Synchronization(org.yakindu.sct.model.sgraph.Synchronization) Test(org.junit.Test)

Example 25 with Transition

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

the class STextJavaValidatorTest method checkUnboundEntryPoints.

@Test
public void checkUnboundEntryPoints() {
    statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR + "UnboundDefaultEntryPoints.sct");
    Iterator<EObject> iter = statechart.eAllContents();
    // create and add triggers to all transitions to prevent to trigger
    // additional warnings
    // (see Check in SGrapJavaValidator transitionsWithNoGuard)
    Trigger trigger = StextFactoryImpl.init().createDefaultTrigger();
    while (iter.hasNext()) {
        EObject element = iter.next();
        if (element instanceof Transition) {
            ((Transition) element).setTrigger(trigger);
            validator.validate(element, diagnostics, new HashMap<>());
        }
        if (element instanceof State) {
            validator.validate(element, diagnostics, new HashMap<>());
        }
    }
    assertIssueCount(diagnostics, 4);
    assertError(diagnostics, TRANSITION_UNBOUND_DEFAULT_ENTRY_POINT);
    assertError(diagnostics, REGION_UNBOUND_DEFAULT_ENTRY_POINT);
    resetDiagnostics();
    statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR + "UnboundEntryPoints02.sct");
    iter = statechart.eAllContents();
    while (iter.hasNext()) {
        EObject element = iter.next();
        if (element instanceof Transition) {
            ((Transition) element).setTrigger(trigger);
            validator.validate(element, diagnostics, new HashMap<>());
        }
        if (element instanceof State) {
            validator.validate(element, diagnostics, new HashMap<>());
        }
    }
    assertIssueCount(diagnostics, 4);
}
Also used : Trigger(org.yakindu.sct.model.sgraph.Trigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) State(org.yakindu.sct.model.sgraph.State) EObject(org.eclipse.emf.ecore.EObject) Transition(org.yakindu.sct.model.sgraph.Transition) Test(org.junit.Test)

Aggregations

Transition (org.yakindu.sct.model.sgraph.Transition)63 Test (org.junit.Test)34 Region (org.yakindu.sct.model.sgraph.Region)26 State (org.yakindu.sct.model.sgraph.State)23 Statechart (org.yakindu.sct.model.sgraph.Statechart)19 FinalState (org.yakindu.sct.model.sgraph.FinalState)13 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)13 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)13 SGraphTestFactory._createTransition (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition)13 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)13 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)10 Entry (org.yakindu.sct.model.sgraph.Entry)10 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)10 StextTestFactory._createReactionTrigger (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger)9 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)8 LocalReaction (org.yakindu.sct.model.stext.stext.LocalReaction)8 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)8 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)7 If (org.yakindu.sct.model.sexec.If)7 Vertex (org.yakindu.sct.model.sgraph.Vertex)7