|
@@ -12,7 +12,6 @@
|
|
|
package org.yakindu.sct.model.stext.test;
|
|
|
|
|
|
import static org.eclipse.xtext.junit4.validation.AssertableDiagnostics.errorCode;
|
|
|
-import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
import static org.yakindu.sct.test.models.AbstractTestModelsUtil.VALIDATION_TESTMODEL_DIR;
|
|
@@ -21,18 +20,13 @@ import java.lang.reflect.Method;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
-import org.eclipse.emf.common.util.BasicDiagnostic;
|
|
|
import org.eclipse.emf.common.util.Diagnostic;
|
|
|
-import org.eclipse.emf.common.util.URI;
|
|
|
import org.eclipse.emf.ecore.EObject;
|
|
|
import org.eclipse.emf.ecore.util.Diagnostician;
|
|
|
import org.eclipse.xtext.junit4.InjectWith;
|
|
|
import org.eclipse.xtext.junit4.XtextRunner;
|
|
|
import org.eclipse.xtext.junit4.validation.AssertableDiagnostics;
|
|
|
-import org.eclipse.xtext.junit4.validation.ValidatorTester;
|
|
|
import org.eclipse.xtext.validation.Check;
|
|
|
-import org.junit.After;
|
|
|
-import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
import org.yakindu.base.expressions.expressions.Expression;
|
|
@@ -40,15 +34,12 @@ import org.yakindu.sct.model.sgraph.Choice;
|
|
|
import org.yakindu.sct.model.sgraph.Entry;
|
|
|
import org.yakindu.sct.model.sgraph.Exit;
|
|
|
import org.yakindu.sct.model.sgraph.Region;
|
|
|
-import org.yakindu.sct.model.sgraph.SGraphFactory;
|
|
|
import org.yakindu.sct.model.sgraph.Scope;
|
|
|
import org.yakindu.sct.model.sgraph.State;
|
|
|
import org.yakindu.sct.model.sgraph.Statechart;
|
|
|
import org.yakindu.sct.model.sgraph.Transition;
|
|
|
import org.yakindu.sct.model.sgraph.Trigger;
|
|
|
-import org.yakindu.sct.model.sgraph.Vertex;
|
|
|
import org.yakindu.sct.model.stext.inferrer.STextTypeInferrer;
|
|
|
-import org.yakindu.sct.model.stext.resource.StextResource;
|
|
|
import org.yakindu.sct.model.stext.stext.ImportScope;
|
|
|
import org.yakindu.sct.model.stext.stext.InterfaceScope;
|
|
|
import org.yakindu.sct.model.stext.stext.InternalScope;
|
|
@@ -59,6 +50,7 @@ import org.yakindu.sct.model.stext.stext.TransitionSpecification;
|
|
|
import org.yakindu.sct.model.stext.stext.impl.StextFactoryImpl;
|
|
|
import org.yakindu.sct.model.stext.test.util.AbstractSTextTest;
|
|
|
import org.yakindu.sct.model.stext.test.util.STextInjectorProvider;
|
|
|
+import org.yakindu.sct.model.stext.test.validation.AbstractSTextValidationTest;
|
|
|
import org.yakindu.sct.model.stext.validation.STextJavaValidator;
|
|
|
import org.yakindu.sct.model.stext.validation.STextValidationMessages;
|
|
|
import org.yakindu.sct.test.models.AbstractTestModelsUtil;
|
|
@@ -75,38 +67,8 @@ import com.google.inject.Injector;
|
|
|
*/
|
|
|
@RunWith(XtextRunner.class)
|
|
|
@InjectWith(STextInjectorProvider.class)
|
|
|
-public class STextJavaValidatorTest extends AbstractSTextTest implements STextValidationMessages {
|
|
|
-
|
|
|
- @Inject
|
|
|
- private STextJavaValidator validator;
|
|
|
- @Inject
|
|
|
- private Injector injector;
|
|
|
- private ValidatorTester<STextJavaValidator> tester;
|
|
|
- protected BasicDiagnostic diagnostics;
|
|
|
- protected SGraphFactory factory;
|
|
|
- protected Statechart statechart;
|
|
|
- protected StextResource resource;
|
|
|
-
|
|
|
- public STextJavaValidatorTest() {
|
|
|
- }
|
|
|
-
|
|
|
- @Before
|
|
|
- public void setup() {
|
|
|
- factory = SGraphFactory.eINSTANCE;
|
|
|
-
|
|
|
- resource = new StextResource(URI.createURI(""));
|
|
|
- injector.injectMembers(resource);
|
|
|
- statechart = factory.createStatechart();
|
|
|
- resource.getContents().add(statechart);
|
|
|
+public class STextJavaValidatorTest extends AbstractSTextValidationTest implements STextValidationMessages {
|
|
|
|
|
|
- diagnostics = new BasicDiagnostic();
|
|
|
- tester = new ValidatorTester<STextJavaValidator>(validator, injector);
|
|
|
- }
|
|
|
-
|
|
|
- @After
|
|
|
- public void teardown() {
|
|
|
- tester = null;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* @see STextJavaValidator#checkVariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition)
|
|
@@ -598,115 +560,6 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
|
|
|
assertWarning(diagnostics, INTERNAL_DECLARATION_UNUSED);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Show warning when transition has no guard
|
|
|
- */
|
|
|
- @Test
|
|
|
- public void transitionsWithNoTrigger() {
|
|
|
-
|
|
|
- Region region = factory.createRegion();
|
|
|
-
|
|
|
- // create vertices for main region
|
|
|
- Entry entry = factory.createEntry();
|
|
|
- State a = factory.createState();
|
|
|
- a.setName("A");
|
|
|
- State b = factory.createState();
|
|
|
- b.setName("B");
|
|
|
- State c = factory.createState();
|
|
|
- c.setName("C");
|
|
|
- State d = factory.createState();
|
|
|
- c.setName("D");
|
|
|
- Choice e = factory.createChoice();
|
|
|
- State f = factory.createState();
|
|
|
- f.setName("F");
|
|
|
- Transition entryToA = createTransition(entry, a);
|
|
|
- Transition aToB = createTransition(a, b);
|
|
|
- Transition bToC = createTransition(b, c);
|
|
|
- Transition cToD = createTransition(c, d);
|
|
|
- Transition eToF = createTransition(e, f);
|
|
|
-
|
|
|
- // create vertices for compositState
|
|
|
- State bb = factory.createState();
|
|
|
- bb.setName("BB");
|
|
|
- Entry entryB = factory.createEntry();
|
|
|
- Exit exitB = factory.createExit();
|
|
|
-
|
|
|
- Region b_region = factory.createRegion();
|
|
|
- b_region.getVertices().add(entryB);
|
|
|
- b_region.getVertices().add(bb);
|
|
|
- b_region.getVertices().add(exitB);
|
|
|
- b.getRegions().add(b_region);
|
|
|
- Transition entryBToBB = createTransition(entryB, bb);
|
|
|
- Transition bbToExitB = createTransition(bb, exitB);
|
|
|
-
|
|
|
- region.getVertices().add(entry);
|
|
|
- region.getVertices().add(a);
|
|
|
- region.getVertices().add(b);
|
|
|
- region.getVertices().add(c);
|
|
|
- region.getVertices().add(d);
|
|
|
- statechart.getRegions().add(region);
|
|
|
-
|
|
|
- // transitions from entry point to State A -> valid model with no
|
|
|
- // warnings
|
|
|
- assertTrue(validator.validate(eToF, diagnostics, new HashMap<Object, Object>()));
|
|
|
- assertIssueCount(diagnostics, 0);
|
|
|
-
|
|
|
- // transitions from entry point to State A -> valid model with no
|
|
|
- // warnings
|
|
|
- assertTrue(validator.validate(entryToA, diagnostics, new HashMap<Object, Object>()));
|
|
|
- assertIssueCount(diagnostics, 0);
|
|
|
-
|
|
|
- // transition from StateA to StateB -> valid model with warnings expect
|
|
|
- // 1 warning in total
|
|
|
- assertTrue(validator.validate(aToB, diagnostics, new HashMap<Object, Object>()));
|
|
|
- assertIssueCount(diagnostics, 1);
|
|
|
- resetDiagnostics();
|
|
|
-
|
|
|
- // transition from EntryB to StateBB -> valid model with no warnings
|
|
|
- // expect 1 warning in total
|
|
|
- assertTrue(validator.validate(entryBToBB, diagnostics, new HashMap<Object, Object>()));
|
|
|
- assertIssueCount(diagnostics, 0);
|
|
|
-
|
|
|
- // transition from BB to ExitB -> valid model with warnings expect 2
|
|
|
- // warning in total
|
|
|
- assertTrue(validator.validate(bbToExitB, diagnostics, new HashMap<Object, Object>()));
|
|
|
- assertIssueCount(diagnostics, 1);
|
|
|
- resetDiagnostics();
|
|
|
-
|
|
|
- // transition from B to C -> valid model with no warning warnings expect
|
|
|
- // 2 warning in total
|
|
|
- assertTrue(validator.validate(bToC, diagnostics, new HashMap<Object, Object>()));
|
|
|
- assertIssueCount(diagnostics, 0);
|
|
|
-
|
|
|
- // transition from C to D -> valid model with warning warning expect 3
|
|
|
- // warning in total
|
|
|
- assertTrue(validator.validate(cToD, diagnostics, new HashMap<Object, Object>()));
|
|
|
- assertIssueCount(diagnostics, 1);
|
|
|
- resetDiagnostics();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 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 validEmptyTransitionFromSync() {
|
|
|
- statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR
|
|
|
- + "ValidEmptyTransitionFromSync.sct");
|
|
|
- Iterator<EObject> iter = statechart.eAllContents();
|
|
|
- while (iter.hasNext()) {
|
|
|
- EObject element = iter.next();
|
|
|
- if (element instanceof Transition) {
|
|
|
- validator.validate(element, diagnostics, new HashMap<Object, Object>());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- assertIssueCount(diagnostics, 0);
|
|
|
- }
|
|
|
|
|
|
@Test
|
|
|
public void checkImportExists() {
|
|
@@ -716,42 +569,4 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
|
|
|
AssertableDiagnostics validationResult = tester.validate(importScope.getImports().get(0));
|
|
|
validationResult.assertError(STextJavaValidator.IMPORT_NOT_RESOLVED);
|
|
|
}
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
- protected void assertError(Diagnostic diag, String message) {
|
|
|
- Diagnostic d = issueByName(diag, message);
|
|
|
- assertNotNull("Issue '" + message + "' does not exist.", issueByName(diag, message));
|
|
|
- assertEquals("Issue '" + message + "' is no error.", Diagnostic.ERROR, d.getSeverity());
|
|
|
- }
|
|
|
-
|
|
|
- protected void assertWarning(Diagnostic diag, String message) {
|
|
|
- Diagnostic d = issueByName(diag, message);
|
|
|
- assertNotNull("Issue '" + message + "' does not exist.", issueByName(diag, message));
|
|
|
- assertEquals("Issue '" + message + "' is no warning.", Diagnostic.WARNING, d.getSeverity());
|
|
|
- }
|
|
|
-
|
|
|
- protected void assertIssueCount(Diagnostic diag, int count) {
|
|
|
- int c = diag.getChildren().size();
|
|
|
- assertEquals("expected " + count + " issue(s) but were " + c + " [" + diag.toString() + "]", count, c);
|
|
|
- }
|
|
|
-
|
|
|
- protected Diagnostic issueByName(Diagnostic diag, String message) {
|
|
|
- for (Diagnostic issue : diag.getChildren()) {
|
|
|
- if (message.equals(issue.getMessage()))
|
|
|
- return issue;
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- protected void resetDiagnostics() {
|
|
|
- diagnostics = new BasicDiagnostic();
|
|
|
- }
|
|
|
}
|