Browse Source

separated exit and entry validator and tests

Axel Terfloth 7 years ago
parent
commit
b90fde4dca

+ 28 - 45
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/validation/EntryExitValidator.java

@@ -27,30 +27,11 @@ import org.yakindu.sct.model.sgraph.Vertex;
 
 /**
  * 
- * All validation contraints for the meta model elements {@link Entry} and
- * {@link Exit}
+ * All validation contraints for the meta model elements {@link Entry}
  *
  */
-public class EntryExitValidator extends AbstractSGraphValidator {
+public class EntryValidator extends AbstractSGraphValidator {
 
-	private static final String INITIAL_ENTRY_NO_IN_TRANSITION_MSG = "Initial entry should have no incoming transition.";
-	public static final String INITIAL_ENTRY_NO_IN_TRANSITION_CODE = "entry.in.transition";
-
-	public static final String ENTRY_WITH_MULTIPLE_OUT_TRANS_MSG = "Entries must not have more than one outgoing transition.";
-	private static final String INITIAL_ENTRY_ONE_OUT_TRANSITION_MSG = "Initial entry should have exactly one outgoing transition.";
-	public static final String INITIAL_ENTRY_ONE_OUT_TRANSITION_CODE = "entry.out.transition";
-
-	private static final String EXIT_AT_LEAST_ONE_IN_TRANSITION_MSG = "Exit node should have at least one incoming transition.";
-	public static final String EXIT_AT_LEAST_ONE_IN_TRANSITION_CODE = "exit.in.transition";
-
-	private static final String EXIT_NO_OUTGOING_TRANSITION_MSG = "Exit node should have no outgoing transition.";
-	public static final String EXIT_NO_OUTGOING_TRANSITION_CODE = "exit.out.transition";
-
-	private static final String EXIT_NO_TOPLEVEL_REGION_MSG = "Exit node in top level region not supported - use final states instead.";
-	public static final String EXIT_NO_TOPLEVEL_REGION_CODE = "exit.not.toplevel";
-
-	private static final String ENTRY_NO_TRIGGER_MSG = "Outgoing transitions from entry points can not have a trigger or guard.";
-	public static final String ENTRY_NO_TRIGGER_CODE = "entry.no.trigger";
 
 	private static final String REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY_MSG = "The region can't be entered using the shallow history. Add a default entry node.";
 	public static final String REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY_CODE = "entry.region.default";
@@ -61,48 +42,50 @@ public class EntryExitValidator extends AbstractSGraphValidator {
 	private final static String REGION_MULTIPLE_DEFAULT_ENTRIES_MSG = "There are multiple default entry nodes (one without a name and one named 'default') in this region.";
 	public final static String REGION_MULTIPLE_DEFAULT_ENTRIES_CODE = "region.duplicate.entry";
 
+
+	
+	
+	private static final String ENTRY_TRANSITIONS_NO_IN_IF_INITIAL_MSG  = "Initial entry should have no incoming transition.";
+	public static final String  ENTRY_TRANSITIONS_NO_IN_IF_INITIAL_CODE = "entry.transitions.NoInIfInitial";
+
 	@Check(CheckType.FAST)
-	public void initialEntryWithoutIncomingTransitions(Entry entry) {
+	public void checkEntryTransitionsNoInIfInitial(Entry entry) {
 		if (entry.getIncomingTransitions().size() > 0 && entry.getKind().equals(EntryKind.INITIAL)) {
-			warning(INITIAL_ENTRY_NO_IN_TRANSITION_MSG, entry, null, -1, INITIAL_ENTRY_NO_IN_TRANSITION_CODE);
+			warning(ENTRY_TRANSITIONS_NO_IN_IF_INITIAL_MSG, entry, null, -1, ENTRY_TRANSITIONS_NO_IN_IF_INITIAL_CODE);
 		}
 	}
 
-	@Check(CheckType.FAST)
-	public void initialEntryWithoutOutgoingTransition(Entry entry) {
-		if (entry.getOutgoingTransitions().size() > 1) {
-			error(ENTRY_WITH_MULTIPLE_OUT_TRANS_MSG, entry, null, -1, INITIAL_ENTRY_ONE_OUT_TRANSITION_CODE);
-		} else if (entry.getOutgoingTransitions().size() != 1 && ((Entry) entry).getKind().equals(EntryKind.INITIAL)) {
-			warning(INITIAL_ENTRY_ONE_OUT_TRANSITION_MSG, entry, null, -1, INITIAL_ENTRY_ONE_OUT_TRANSITION_CODE);
-		}
-	}
 
-	@Check(CheckType.FAST)
-	public void exitWithoutIncomingTransition(Exit exit) {
-		if (exit.getIncomingTransitions().size() == 0) {
-			warning(EXIT_AT_LEAST_ONE_IN_TRANSITION_MSG, exit, null, -1, EXIT_AT_LEAST_ONE_IN_TRANSITION_CODE);
-		}
-	}
+	private static final String ENTRY_TRANSITIONS_REQUIRE_OUT_IF_INITIAL_MSG  = "Initial entry must have an outgoing transition.";
+	public static final String  ENTRY_TRANSITIONS_REQUIRE_OUT_IF_INITIAL_CODE = "entry.transitions.RequireOutIfInitial";
 
 	@Check(CheckType.FAST)
-	public void exitWithOutgoingTransition(Exit exit) {
-		if (exit.getOutgoingTransitions().size() > 0) {
-			error(EXIT_NO_OUTGOING_TRANSITION_MSG, exit, null, -1, EXIT_NO_OUTGOING_TRANSITION_CODE);
+	public void checkEntryTransitionsRequireOneOutIfInitial(Entry entry) {
+		if (entry.getKind().equals(EntryKind.INITIAL) && entry.getOutgoingTransitions().size() == 0 ) {
+			error(ENTRY_TRANSITIONS_REQUIRE_OUT_IF_INITIAL_MSG, entry, null, -1, ENTRY_TRANSITIONS_REQUIRE_OUT_IF_INITIAL_CODE);
 		}
 	}
 
+		
+	private static final String ENTRY_TRANSITIONS_NO_MULTIPLE_OUT_MSG  = "Entries must not have more than one outgoing transition.";
+	public static final String  ENTRY_TRANSITIONS_NO_MULTIPLE_OUT_CODE = "entry.transitions.NoMultipleOut";
+
 	@Check(CheckType.FAST)
-	public void exitOnStatechart(Exit exit) {
-		if (exit.getParentRegion().getComposite() instanceof Statechart) {
-			error(EXIT_NO_TOPLEVEL_REGION_MSG, exit, null, -1, EXIT_NO_TOPLEVEL_REGION_CODE);
+	public void checkEntryTransitionsNoMultipleOut(Entry entry) {
+		if (entry.getOutgoingTransitions().size() > 1) {
+			error(ENTRY_TRANSITIONS_NO_MULTIPLE_OUT_MSG, entry, null, -1, ENTRY_TRANSITIONS_NO_MULTIPLE_OUT_CODE);
 		}
 	}
 
+	
+	private static final String ENTRY_TRANSITIONS_NO_TRIGGER_ON_OUT_MSG = "Outgoing transitions from entry points must not have a trigger or guard.";
+	public static final String ENTRY_TRANSITIONS_NO_TRIGGER_ON_OUT_CODE = "entry.transitions.NoTriggerOnOut";
+
 	@Check(CheckType.FAST)
-	public void disallowTrigger(Entry entry) {
+	public void checkEntryTransitionsNoTriggerOnOut(Entry entry) {
 		for (Transition transition : entry.getOutgoingTransitions()) {
 			if (transition.getTrigger() != null) {
-				error(ENTRY_NO_TRIGGER_MSG, entry, null, -1, ENTRY_NO_TRIGGER_CODE);
+				error(ENTRY_TRANSITIONS_NO_TRIGGER_ON_OUT_MSG, entry, null, -1, ENTRY_TRANSITIONS_NO_TRIGGER_ON_OUT_CODE);
 			}
 		}
 	}

+ 58 - 0
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/validation/ExitValidator.java

@@ -0,0 +1,58 @@
+/**
+ * Copyright (c) 2012-2018 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.model.sgraph.validation;
+
+import org.eclipse.xtext.validation.Check;
+import org.eclipse.xtext.validation.CheckType;
+import org.yakindu.sct.model.sgraph.Exit;
+import org.yakindu.sct.model.sgraph.Statechart;
+
+/**
+ * 
+ * All validation contraints for the meta model elements {@link Exit}
+ *
+ */
+public class ExitValidator extends AbstractSGraphValidator {
+
+
+	private static final String EXIT_AT_LEAST_ONE_IN_TRANSITION_MSG = "Exit node should have at least one incoming transition.";
+	public static final String EXIT_AT_LEAST_ONE_IN_TRANSITION_CODE = "exit.in.transition";
+
+	private static final String EXIT_NO_OUTGOING_TRANSITION_MSG = "Exit node should have no outgoing transition.";
+	public static final String EXIT_NO_OUTGOING_TRANSITION_CODE = "exit.out.transition";
+
+	private static final String EXIT_NO_TOPLEVEL_REGION_MSG = "Exit node in top level region not supported - use final states instead.";
+	public static final String EXIT_NO_TOPLEVEL_REGION_CODE = "exit.not.toplevel";
+
+	
+	
+	@Check(CheckType.FAST)
+	public void exitWithoutIncomingTransition(Exit exit) {
+		if (exit.getIncomingTransitions().size() == 0) {
+			warning(EXIT_AT_LEAST_ONE_IN_TRANSITION_MSG, exit, null, -1, EXIT_AT_LEAST_ONE_IN_TRANSITION_CODE);
+		}
+	}
+
+	@Check(CheckType.FAST)
+	public void exitWithOutgoingTransition(Exit exit) {
+		if (exit.getOutgoingTransitions().size() > 0) {
+			error(EXIT_NO_OUTGOING_TRANSITION_MSG, exit, null, -1, EXIT_NO_OUTGOING_TRANSITION_CODE);
+		}
+	}
+
+	@Check(CheckType.FAST)
+	public void exitOnStatechart(Exit exit) {
+		if (exit.getParentRegion().getComposite() instanceof Statechart) {
+			error(EXIT_NO_TOPLEVEL_REGION_MSG, exit, null, -1, EXIT_NO_TOPLEVEL_REGION_CODE);
+		}
+	}
+
+}

+ 1 - 1
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/validation/SGraphJavaValidator.java

@@ -23,7 +23,7 @@ import org.yakindu.sct.model.sgraph.SGraphPackage;
  *
  */
 @ComposedChecks(validators = { ResourceValidator.class, StatechartValidator.class, StateValidator.class,
-		ChoiceValidator.class, EntryExitValidator.class, FinalStateValidator.class, SynchronizationValidator.class,
+		ChoiceValidator.class, EntryValidator.class, ExitValidator.class, FinalStateValidator.class, SynchronizationValidator.class,
 		TransitionValidator.class, VertexValidator.class })
 public class SGraphJavaValidator extends AbstractSGraphValidator {
 

+ 12 - 4
test-plugins/org.yakindu.sct.model.sgraph.test/src/org/yakindu/sct/model/sgraph/test/AllTests.java

@@ -14,7 +14,8 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
 import org.yakindu.sct.model.sgraph.test.validation.ChoiceValidatorTest;
-import org.yakindu.sct.model.sgraph.test.validation.EntryExitValidatorTest;
+import org.yakindu.sct.model.sgraph.test.validation.EntryValidatorTest;
+import org.yakindu.sct.model.sgraph.test.validation.ExitValidatorTest;
 import org.yakindu.sct.model.sgraph.test.validation.FinalStateNoOutTransitionsValidatorTest;
 import org.yakindu.sct.model.sgraph.test.validation.StateValidatorTest;
 import org.yakindu.sct.model.sgraph.test.validation.StatechartValidatorTest;
@@ -23,9 +24,16 @@ import org.yakindu.sct.model.sgraph.test.validation.TransitionValidatorTest;
 import org.yakindu.sct.model.sgraph.test.validation.VertexValidatorTest;
 
 @RunWith(value = Suite.class)
-@SuiteClasses(value = { StatechartValidatorTest.class, ChoiceValidatorTest.class, EntryExitValidatorTest.class,
-		FinalStateNoOutTransitionsValidatorTest.class, StateValidatorTest.class, SynchronizationValidatorTest.class,
-		TransitionValidatorTest.class, VertexValidatorTest.class })
+@SuiteClasses(value = { 
+		StatechartValidatorTest.class, 
+		ChoiceValidatorTest.class, 
+		EntryValidatorTest.class, 
+		ExitValidatorTest.class,
+		FinalStateNoOutTransitionsValidatorTest.class, 
+		StateValidatorTest.class, 
+		SynchronizationValidatorTest.class,
+		TransitionValidatorTest.class, 
+		VertexValidatorTest.class })
 public class AllTests {
 
 }

+ 14 - 58
test-plugins/org.yakindu.sct.model.sgraph.test/src/org/yakindu/sct/model/sgraph/test/validation/EntryExitValidatorTest.java

@@ -11,7 +11,7 @@
 package org.yakindu.sct.model.sgraph.test.validation;
 
 import static org.junit.Assert.assertEquals;
-import static org.yakindu.sct.model.sgraph.validation.EntryExitValidator.*;
+import static org.yakindu.sct.model.sgraph.validation.EntryValidator.*;
 
 import org.eclipse.xtext.junit4.validation.AssertableDiagnostics;
 import org.junit.Test;
@@ -23,19 +23,19 @@ 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.test.util.SGraphJavaValidatorTester;
-import org.yakindu.sct.model.sgraph.validation.EntryExitValidator;
+import org.yakindu.sct.model.sgraph.validation.EntryValidator;
 
 import com.google.inject.Inject;
 
 /**
  * 
- * Tests for {@link EntryExitValidator}
+ * Tests for {@link EntryValidator}
  *
  */
-public class EntryExitValidatorTest extends AbstractSGraphValidatorTest {
+public class EntryValidatorTest extends AbstractSGraphValidatorTest {
 
 	@Inject
-	protected SGraphJavaValidatorTester<EntryExitValidator> tester;
+	protected SGraphJavaValidatorTester<EntryValidator> tester;
 
 	/**
 	 * An initial entry should have no incoming transition
@@ -50,7 +50,7 @@ public class EntryExitValidatorTest extends AbstractSGraphValidatorTest {
 		createTransition(entry, state);
 
 		assertEquals(EntryKind.INITIAL, entry.getKind());
-		tester.validate(entry).assertWarning(INITIAL_ENTRY_NO_IN_TRANSITION_CODE);
+		tester.validate(entry).assertWarning(ENTRY_TRANSITIONS_NO_IN_IF_INITIAL_CODE);
 	}
 
 	/**
@@ -79,7 +79,7 @@ public class EntryExitValidatorTest extends AbstractSGraphValidatorTest {
 		region.getVertices().add(entry);
 
 		assertEquals(EntryKind.INITIAL, entry.getKind());
-		tester.validate(entry).assertWarning(INITIAL_ENTRY_ONE_OUT_TRANSITION_CODE);
+		tester.validate(entry).assertError(ENTRY_TRANSITIONS_REQUIRE_OUT_IF_INITIAL_CODE);
 
 	}
 
@@ -96,13 +96,13 @@ public class EntryExitValidatorTest extends AbstractSGraphValidatorTest {
 		createTransition(entry, state);
 
 		assertEquals(EntryKind.INITIAL, entry.getKind());
-		tester.validate(entry).assertError(INITIAL_ENTRY_ONE_OUT_TRANSITION_CODE);
+		tester.validate(entry).assertError(ENTRY_TRANSITIONS_NO_MULTIPLE_OUT_CODE);
 
 		entry.setKind(EntryKind.DEEP_HISTORY);
-		tester.validate(entry).assertError(INITIAL_ENTRY_ONE_OUT_TRANSITION_CODE);
+		tester.validate(entry).assertError(ENTRY_TRANSITIONS_NO_MULTIPLE_OUT_CODE);
 
 		entry.setKind(EntryKind.SHALLOW_HISTORY);
-		tester.validate(entry).assertError(INITIAL_ENTRY_ONE_OUT_TRANSITION_CODE);
+		tester.validate(entry).assertError(ENTRY_TRANSITIONS_NO_MULTIPLE_OUT_CODE);
 	}
 
 	/**
@@ -118,59 +118,15 @@ public class EntryExitValidatorTest extends AbstractSGraphValidatorTest {
 		createTransition(entry, state);
 
 		assertEquals(EntryKind.INITIAL, entry.getKind());
-		tester.validate(entry).assertError(INITIAL_ENTRY_ONE_OUT_TRANSITION_CODE);
+		tester.validate(entry).assertError(ENTRY_TRANSITIONS_NO_MULTIPLE_OUT_CODE);
 
 		entry.setKind(EntryKind.SHALLOW_HISTORY);
-		tester.validate(entry).assertError(INITIAL_ENTRY_ONE_OUT_TRANSITION_CODE);
+		tester.validate(entry).assertError(ENTRY_TRANSITIONS_NO_MULTIPLE_OUT_CODE);
 
 		entry.setKind(EntryKind.DEEP_HISTORY);
-		tester.validate(entry).assertError(INITIAL_ENTRY_ONE_OUT_TRANSITION_CODE);
+		tester.validate(entry).assertError(ENTRY_TRANSITIONS_NO_MULTIPLE_OUT_CODE);
 	}
 
-	/**
-	 * An exit node should have at leat one incoming transition.
-	 */
-	@Test
-	public void exitWithoutIncomingTransition() {
-		State state = createState();
-		Region subRegion = factory.createRegion();
-		state.getRegions().add(subRegion);
-		Exit exit = factory.createExit();
-		subRegion.getVertices().add(exit);
-
-		tester.validate(exit).assertWarning(EXIT_AT_LEAST_ONE_IN_TRANSITION_CODE);
-	}
-
-	/**
-	 * An exit node must have no outgoing transitions.
-	 */
-	@Test
-	public void exitWithOutgoingTransition() {
-		State state = createState();
-		Region subRegion = factory.createRegion();
-		state.getRegions().add(subRegion);
-		Exit exit = factory.createExit();
-		subRegion.getVertices().add(exit);
-		State s = factory.createState();
-		subRegion.getVertices().add(s);
-		createTransition(exit, s);
-		createTransition(s, exit);
-
-		tester.validate(exit).assertError(EXIT_NO_OUTGOING_TRANSITION_CODE);
-	}
-
-	/**
-	 * An exit node must not be used in top level regions.
-	 */
-	@Test
-	public void exitOnStatechart() {
-		State state = createState();
-		Region region = (Region) state.eContainer();
-		Exit exit = factory.createExit();
-		createTransition(state, exit);
-		region.getVertices().add(exit);
-		tester.validate(exit).assertError(EXIT_NO_TOPLEVEL_REGION_CODE);
-	}
 
 	/**
 	 * Tests a scenario where no issues for an exit nodes exists.
@@ -199,7 +155,7 @@ public class EntryExitValidatorTest extends AbstractSGraphValidatorTest {
 		region.getVertices().add(entry);
 		Transition trans = createTransition(entry, state);
 		trans.setTrigger(sTextFactory.createReactionTrigger());
-		tester.validate(entry).assertError(ENTRY_NO_TRIGGER_CODE);
+		tester.validate(entry).assertError(ENTRY_TRANSITIONS_NO_TRIGGER_ON_OUT_CODE);
 	}
 
 	@Test

+ 105 - 0
test-plugins/org.yakindu.sct.model.sgraph.test/src/org/yakindu/sct/model/sgraph/test/validation/ExitValidatorTest.java

@@ -0,0 +1,105 @@
+/**
+ * Copyright (c) 2012-2018 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.model.sgraph.test.validation;
+
+import static org.yakindu.sct.model.sgraph.validation.ExitValidator.*;
+
+import org.junit.Test;
+import org.yakindu.sct.model.sgraph.Exit;
+import org.yakindu.sct.model.sgraph.Region;
+import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.model.sgraph.Transition;
+import org.yakindu.sct.model.sgraph.test.util.SGraphJavaValidatorTester;
+import org.yakindu.sct.model.sgraph.validation.EntryValidator;
+import org.yakindu.sct.model.sgraph.validation.ExitValidator;
+
+import com.google.inject.Inject;
+
+/**
+ * 
+ * Tests for {@link EntryValidator}
+ *
+ */
+public class ExitValidatorTest extends AbstractSGraphValidatorTest {
+
+	@Inject
+	protected SGraphJavaValidatorTester<ExitValidator> tester;
+
+
+
+
+
+
+	/**
+	 * An exit node should have at leat one incoming transition.
+	 */
+	@Test
+	public void exitWithoutIncomingTransition() {
+		State state = createState();
+		Region subRegion = factory.createRegion();
+		state.getRegions().add(subRegion);
+		Exit exit = factory.createExit();
+		subRegion.getVertices().add(exit);
+
+		tester.validate(exit).assertWarning(EXIT_AT_LEAST_ONE_IN_TRANSITION_CODE);
+	}
+
+	/**
+	 * An exit node must have no outgoing transitions.
+	 */
+	@Test
+	public void exitWithOutgoingTransition() {
+		State state = createState();
+		Region subRegion = factory.createRegion();
+		state.getRegions().add(subRegion);
+		Exit exit = factory.createExit();
+		subRegion.getVertices().add(exit);
+		State s = factory.createState();
+		subRegion.getVertices().add(s);
+		createTransition(exit, s);
+		createTransition(s, exit);
+
+		tester.validate(exit).assertError(EXIT_NO_OUTGOING_TRANSITION_CODE);
+	}
+
+	/**
+	 * An exit node must not be used in top level regions.
+	 */
+	@Test
+	public void exitOnStatechart() {
+		State state = createState();
+		Region region = (Region) state.eContainer();
+		Exit exit = factory.createExit();
+		createTransition(state, exit);
+		region.getVertices().add(exit);
+		tester.validate(exit).assertError(EXIT_NO_TOPLEVEL_REGION_CODE);
+	}
+
+	/**
+	 * Tests a scenario where no issues for an exit nodes exists.
+	 */
+	@Test
+	public void cleanExit() {
+		State state = createState();
+		Region subRegion = factory.createRegion();
+		state.getRegions().add(subRegion);
+		Exit exit = factory.createExit();
+		subRegion.getVertices().add(exit);
+		State s = factory.createState();
+		subRegion.getVertices().add(s);
+		Transition t = factory.createTransition();
+		t.setTarget(exit);
+		t.setSource(s);
+
+		tester.validate(exit).assertOK();
+	}
+	
+}