Search in sources :

Example 36 with Transition

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

the class SCTResourceTest method testLinkingError2.

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

Example 37 with Transition

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

the class SCTResourceTest method testTransitionSerializing.

@Test
public void testTransitionSerializing() throws Exception {
    res.setSerializerEnabled(true);
    Transition transition = createTransition("after 10\n s [true] / 3 * 3");
    res.getContents().add(transition);
    ReactionTrigger trigger = (ReactionTrigger) transition.getTrigger();
    TimeEventSpec timeTrigger = stextFac.createTimeEventSpec();
    timeTrigger.setType(TimeEventType.EVERY);
    timeTrigger.setUnit(TimeUnit.SECOND);
    PrimitiveValueExpression exp = expFac.createPrimitiveValueExpression();
    IntLiteral literal = expFac.createIntLiteral();
    literal.setValue(42);
    exp.setValue(literal);
    timeTrigger.setValue(exp);
    trigger.getTriggers().add(timeTrigger);
    assertEquals("after 10\n s , every 42 s [true] / 3 * 3", transition.getSpecification());
    assertEquals("" + res.getErrors(), 0, res.getErrors().size());
}
Also used : ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) Transition(org.yakindu.sct.model.sgraph.Transition) IntLiteral(org.yakindu.base.expressions.expressions.IntLiteral) TimeEventSpec(org.yakindu.sct.model.stext.stext.TimeEventSpec) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) Test(org.junit.Test)

Example 38 with Transition

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

the class SCTResourceTest method testLinkingError1.

@Test
public void testLinkingError1() 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);
    System.out.println(res.getLinkingDiagnostics());
    assertEquals(1, res.getLinkingDiagnostics().size());
}
Also used : Transition(org.yakindu.sct.model.sgraph.Transition) Statechart(org.yakindu.sct.model.sgraph.Statechart) Test(org.junit.Test)

Example 39 with Transition

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

the class SCTResourceTest method testParsingOnLoad.

@Test
public void testParsingOnLoad() throws Exception {
    File tmpFile = File.createTempFile("SCTResource", "test.test");
    tmpFile.deleteOnExit();
    URI uri = URI.createFileURI(tmpFile.getPath().toString());
    Resource resource = new XMIResourceImpl(uri);
    Statechart statechart = createStatechart("internal: event Event1");
    resource.getContents().add(statechart);
    Transition transition = createTransition("Event1 [true] / 3 * 3");
    resource.getContents().add(transition);
    resource.save(Collections.EMPTY_MAP);
    res.setURI(uri);
    res.load(Collections.EMPTY_MAP);
    statechart = (Statechart) res.getContents().get(0);
    transition = (Transition) res.getContents().get(1);
    assertEquals("" + res.getErrors(), 0, res.getErrors().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) StextResource(org.yakindu.sct.model.stext.resource.StextResource) Resource(org.eclipse.emf.ecore.resource.Resource) Transition(org.yakindu.sct.model.sgraph.Transition) Statechart(org.yakindu.sct.model.sgraph.Statechart) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) File(java.io.File) URI(org.eclipse.emf.common.util.URI) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) RegularEventSpec(org.yakindu.sct.model.stext.stext.RegularEventSpec) Test(org.junit.Test)

Example 40 with Transition

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

the class SCTResourceTest method createTransition.

protected Transition createTransition(String exp) {
    Transition transition = SGraphFactory.eINSTANCE.createTransition();
    transition.setSpecification(exp);
    return transition;
}
Also used : Transition(org.yakindu.sct.model.sgraph.Transition)

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