Search in sources :

Example 1 with MinimalTSC

use of org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.MinimalTSC in project statecharts by Yakindu.

the class ModelSequencerSCTest method testSCExitSequence.

@Test
public void testSCExitSequence() {
    MinimalTSC sc = new MinimalTSC();
    ExecutionFlow flow = sequencer.transform(sc.sc);
    assertNotNull(flow.getExitSequence());
    assertCall(flow.getExitSequence(), 0, flow.getSubScopes().get(0).getExitSequence());
}
Also used : MinimalTSC(org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.MinimalTSC) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Test(org.junit.Test)

Example 2 with MinimalTSC

use of org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.MinimalTSC in project statecharts by Yakindu.

the class ModelSequencerStateTest method testStateCycle_EntryActionExclusion.

/**
 * Entry action behaviors are not directly part of the states cycle steps
 */
@SuppressWarnings("unused")
@Test
public void testStateCycle_EntryActionExclusion() {
    MinimalTSC tsc = new MinimalTSC();
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
    // add a simple entry action: "entry / x=42;"
    LocalReaction lr = _createEntryAction(tsc.s1);
    ReactionEffect lr_eff = _createReactionEffect(lr);
    AssignmentExpression assign1 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr_eff);
    // TRANSFORM
    ExecutionFlow flow = sequencer.transform(tsc.sc);
    // test state with one outgoing transition
    ExecutionState s1 = flow.getStates().get(0);
    assertEquals(0, s1.getReactions().size());
    assertNotNull(s1.getReactSequence());
    assertEquals(1, s1.getReactSequence().getSteps().size());
}
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) MinimalTSC(org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.MinimalTSC) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) StextTestFactory._createReactionEffect(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect) Test(org.junit.Test)

Example 3 with MinimalTSC

use of org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.MinimalTSC in project statecharts by Yakindu.

the class ModelSequencerStateTest method testStateCycle_WithLocalReactionsOnly.

/**
 * The cycle sequence of a state that only consists of local reactions
 * includes sequential processing of the local reactions.
 */
@SuppressWarnings("unused")
@Test
public void testStateCycle_WithLocalReactionsOnly() {
    MinimalTSC tsc = new MinimalTSC();
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
    // the first local reaction conforms to "e1 / x=42;"
    LocalReaction lr1 = _createLocalReaction(tsc.s1, null);
    _createRegularEventSpec(tsc.e1, (ReactionTrigger) lr1.getTrigger());
    ReactionEffect lr1_eff = _createReactionEffect(lr1);
    AssignmentExpression assign1 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr1_eff);
    // the secont local reaction conforms to "e1 [x==42] / x=0;"
    LocalReaction lr2 = _createLocalReaction(tsc.s1, null);
    _createRegularEventSpec(tsc.e1, (ReactionTrigger) lr2.getTrigger());
    LogicalRelationExpression lr2_equals = ExpressionsFactory.eINSTANCE.createLogicalRelationExpression();
    lr2_equals.setOperator(RelationalOperator.EQUALS);
    ElementReferenceExpression lr2_varRef = ExpressionsFactory.eINSTANCE.createElementReferenceExpression();
    lr2_varRef.setReference(v1);
    PrimitiveValueExpression lr2_value = _createValue(42);
    lr2_equals.setLeftOperand(lr2_varRef);
    lr2_equals.setRightOperand(lr2_value);
    ((ReactionTrigger) lr2.getTrigger()).setGuard(createGuardExpression(lr2_equals));
    ReactionEffect lr2_eff = _createReactionEffect(lr2);
    AssignmentExpression assign2 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(0), lr2_eff);
    // the third local reaction conforms to: "[x==0] / x=1;"
    LocalReaction lr3 = _createLocalReaction(tsc.s1, null);
    LogicalRelationExpression lr3_equals = ExpressionsFactory.eINSTANCE.createLogicalRelationExpression();
    lr3_equals.setOperator(RelationalOperator.EQUALS);
    ElementReferenceExpression lr3_varRef = ExpressionsFactory.eINSTANCE.createElementReferenceExpression();
    lr3_varRef.setReference(v1);
    PrimitiveValueExpression lr3_value = _createValue(0);
    lr3_equals.setLeftOperand(lr3_varRef);
    lr3_equals.setRightOperand(lr3_value);
    ((ReactionTrigger) lr3.getTrigger()).setGuard(createGuardExpression(lr3_equals));
    ReactionEffect lr3_eff = _createReactionEffect(lr3);
    AssignmentExpression assign3 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(1), lr3_eff);
    ExecutionFlow flow = sequencer.transform(tsc.sc);
    // test state with one outgoing transition
    ExecutionState s1 = flow.getStates().get(0);
    assertEquals(tsc.s1.getName(), s1.getSimpleName());
    assertEquals(3, s1.getReactions().size());
    assertNotNull(s1.getReactSequence());
    Step step = s1.getReactSequence().getSteps().get(0);
    Sequence _seq = assertedSequence(assertedSequence(assertedSequence(assertedSequence(assertedSequence(step).getSteps().get(0)).getSteps().get(0)).getSteps().get(0)).getSteps().get(0));
    assertEquals(3, _seq.getSteps().size());
    // check first local reaction
    If _lr1 = (If) _seq.getSteps().get(0);
    assertClass(ElementReferenceExpression.class, _lr1.getCheck().getCondition());
    assertSame(s1.getReactions().get(0).getCheck().getCondition(), _lr1.getCheck().getCondition());
    Call _lr1_eff_call = (Call) _lr1.getThenStep();
    assertSame(s1.getReactions().get(0).getEffect(), _lr1_eff_call.getStep());
    // check second local reaction
    If _lr2 = (If) _seq.getSteps().get(1);
    assertClass(LogicalAndExpression.class, _lr2.getCheck().getCondition());
    assertSame(s1.getReactions().get(1).getCheck().getCondition(), _lr2.getCheck().getCondition());
    Call _lr2_eff_call = (Call) _lr2.getThenStep();
    assertSame(s1.getReactions().get(1).getEffect(), _lr2_eff_call.getStep());
    // check the third local reaction
    If _lr3 = (If) _seq.getSteps().get(2);
    assertClass(LogicalRelationExpression.class, _lr3.getCheck().getCondition());
    assertSame(s1.getReactions().get(2).getCheck().getCondition(), _lr3.getCheck().getCondition());
    Call _lr3_eff_call = (Call) _lr3.getThenStep();
    assertSame(s1.getReactions().get(2).getEffect(), _lr3_eff_call.getStep());
}
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) Call(org.yakindu.sct.model.sexec.Call) MinimalTSC(org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.MinimalTSC) 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) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) StextTestFactory._createReactionEffect(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect) Step(org.yakindu.sct.model.sexec.Step) Sequence(org.yakindu.sct.model.sexec.Sequence) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) LogicalRelationExpression(org.yakindu.base.expressions.expressions.LogicalRelationExpression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) If(org.yakindu.sct.model.sexec.If) Test(org.junit.Test)

Example 4 with MinimalTSC

use of org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.MinimalTSC in project statecharts by Yakindu.

the class ModelSequencerStateTest method testStateCycle_ExitActionExclusion.

/**
 * Exit action behaviors are not directly part of the states cycle steps
 */
@SuppressWarnings("unused")
@Test
public void testStateCycle_ExitActionExclusion() {
    MinimalTSC tsc = new MinimalTSC();
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
    // add a simple entry action: "entry / x=42;"
    LocalReaction lr = _createExitAction(tsc.s1);
    ReactionEffect lr_eff = _createReactionEffect(lr);
    AssignmentExpression assign1 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr_eff);
    // TRANSFORM
    ExecutionFlow flow = sequencer.transform(tsc.sc);
    // test state with one outgoing transition
    ExecutionState s1 = flow.getStates().get(0);
    assertEquals(0, s1.getReactions().size());
    assertNotNull(s1.getReactSequence());
    assertEquals(1, s1.getReactSequence().getSteps().size());
}
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) MinimalTSC(org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.MinimalTSC) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) StextTestFactory._createReactionEffect(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect) Test(org.junit.Test)

Example 5 with MinimalTSC

use of org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.MinimalTSC in project statecharts by Yakindu.

the class ModelSequencerStateTest method testStateCycle_LocalReactionWithMixedRegularAndEntryTrigger.

/**
 * Local reactions that define regular and entry triggers side by side must
 * also be part of the cycle steps.
 */
@SuppressWarnings("unused")
@Test
public void testStateCycle_LocalReactionWithMixedRegularAndEntryTrigger() {
    MinimalTSC tsc = new MinimalTSC();
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
    // add a simple entry action: "entry / x=42;"
    LocalReaction lr = _createEntryAction(tsc.s1);
    _createRegularEventSpec(tsc.e1, (ReactionTrigger) lr.getTrigger());
    ReactionEffect lr_eff = _createReactionEffect(lr);
    AssignmentExpression assign1 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr_eff);
    // TRANSFORM
    ExecutionFlow flow = sequencer.transform(tsc.sc);
    // test state with one outgoing transition
    ExecutionState s1 = flow.getStates().get(0);
    assertEquals(1, s1.getReactions().size());
    assertNotNull(s1.getReactSequence());
    assertEquals(1, s1.getReactSequence().getSteps().size());
    Sequence _seq = (Sequence) s1.getReactSequence().getSteps().get(0);
    If _lr1 = (If) assertedSequence(assertedSequence(assertedSequence(assertedSequence(_seq.getSteps().get(0)).getSteps().get(0)).getSteps().get(0)).getSteps().get(0)).getSteps().get(0);
    assertClass(ElementReferenceExpression.class, _lr1.getCheck().getCondition());
    assertSame(s1.getReactions().get(0).getCheck().getCondition(), _lr1.getCheck().getCondition());
    Call _lr1_eff_call = (Call) _lr1.getThenStep();
    assertSame(s1.getReactions().get(0).getEffect(), _lr1_eff_call.getStep());
}
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) Call(org.yakindu.sct.model.sexec.Call) MinimalTSC(org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.MinimalTSC) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) StextTestFactory._createReactionEffect(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect) Sequence(org.yakindu.sct.model.sexec.Sequence) If(org.yakindu.sct.model.sexec.If) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)5 MinimalTSC (org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.MinimalTSC)5 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)4 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)4 LocalReaction (org.yakindu.sct.model.stext.stext.LocalReaction)4 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)4 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)4 StextTestFactory._createLocalReaction (org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction)4 StextTestFactory._createReactionEffect (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect)4 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)4 Call (org.yakindu.sct.model.sexec.Call)2 If (org.yakindu.sct.model.sexec.If)2 Sequence (org.yakindu.sct.model.sexec.Sequence)2 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)1 LogicalRelationExpression (org.yakindu.base.expressions.expressions.LogicalRelationExpression)1 PrimitiveValueExpression (org.yakindu.base.expressions.expressions.PrimitiveValueExpression)1 Step (org.yakindu.sct.model.sexec.Step)1 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)1 StextTestFactory._createReactionTrigger (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger)1