Search in sources :

Example 16 with Transition

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

the class SCTResourceTest method testRemoveOrphanedLinkingDiagnostics.

@Test
public void testRemoveOrphanedLinkingDiagnostics() throws Exception {
    Statechart statechart = createStatechart("internal: event Event1");
    res.getContents().add(statechart);
    Transition transition = createTransition("Event2 [true] / 3 * 3");
    res.getContents().add(transition);
    res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
    assertEquals(1, res.getLinkingDiagnostics().size());
    transition.setSpecification("Event1 [true] / 3 * 3");
    res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
    assertEquals(0, res.getLinkingDiagnostics().size());
}
Also used : Transition(org.yakindu.sct.model.sgraph.Transition) Statechart(org.yakindu.sct.model.sgraph.Statechart) Test(org.junit.Test)

Example 17 with Transition

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

the class SCTResourceTest method testTransitionParsing.

@Test
public void testTransitionParsing() throws Exception {
    Transition transition = createTransition("after 10 s [true] / 3 * 3");
    assertNull(transition.getTrigger());
    assertNull(transition.getEffect());
    res.getContents().add(transition);
    assertNotNull(transition.getTrigger());
    assertNotNull(transition.getEffect());
}
Also used : Transition(org.yakindu.sct.model.sgraph.Transition) Test(org.junit.Test)

Example 18 with Transition

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

the class SCTResourceTest method testLinkingSuccess.

@Test
public void testLinkingSuccess() throws Exception {
    Statechart statechart = createStatechart("internal: event Event1");
    res.getContents().add(statechart);
    Transition transition = createTransition("Event1 [true] / 3 * 3");
    res.getContents().add(transition);
    res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
    assertEquals("" + res.getLinkingDiagnostics(), 0, res.getLinkingDiagnostics().size());
    ReactionTrigger trigger = (ReactionTrigger) transition.getTrigger();
    RegularEventSpec eventSpec = (RegularEventSpec) trigger.getTriggers().get(0);
    ElementReferenceExpression expression = (ElementReferenceExpression) eventSpec.getEvent();
    EventDefinition reference = (EventDefinition) expression.getReference();
    assertNotNull(reference);
    assertEquals("Event1", reference.getName());
}
Also used : ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) Transition(org.yakindu.sct.model.sgraph.Transition) Statechart(org.yakindu.sct.model.sgraph.Statechart) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) RegularEventSpec(org.yakindu.sct.model.stext.stext.RegularEventSpec) Test(org.junit.Test)

Example 19 with Transition

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

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

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