Pārlūkot izejas kodu

Extracted region tests from entry tests

Axel Terfloth 7 gadi atpakaļ
vecāks
revīzija
797918e1af

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

@@ -10,20 +10,11 @@
  */
 package org.yakindu.sct.model.sgraph.validation;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
 import org.eclipse.xtext.validation.Check;
 import org.eclipse.xtext.validation.CheckType;
-import org.yakindu.sct.model.sgraph.CompositeElement;
 import org.yakindu.sct.model.sgraph.Entry;
 import org.yakindu.sct.model.sgraph.EntryKind;
-import org.yakindu.sct.model.sgraph.Exit;
-import org.yakindu.sct.model.sgraph.Region;
-import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.model.sgraph.Transition;
-import org.yakindu.sct.model.sgraph.Vertex;
 
 /**
  * 
@@ -33,15 +24,6 @@ import org.yakindu.sct.model.sgraph.Vertex;
 public class EntryValidator extends AbstractSGraphValidator {
 
 
-	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";
-
-	private static final String REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_MSG = "The region can't be entered using the shallow history. Add a transition from default entry to a state.";
-	public static final String REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_CODE = "entry.in.transition";
-
-	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";
-
 
 	
 	
@@ -78,7 +60,7 @@ public class EntryValidator extends AbstractSGraphValidator {
 	}
 
 	
-	private static final String ENTRY_TRANSITIONS_NO_TRIGGER_ON_OUT_MSG = "Outgoing transitions from entry points must not have a trigger or guard.";
+	private static final String ENTRY_TRANSITIONS_NO_TRIGGER_ON_OUT_MSG = "The outgoing transitions of an entry must not have a trigger or guard.";
 	public static final String ENTRY_TRANSITIONS_NO_TRIGGER_ON_OUT_CODE = "entry.transitions.NoTriggerOnOut";
 
 	@Check(CheckType.FAST)
@@ -90,50 +72,5 @@ public class EntryValidator extends AbstractSGraphValidator {
 		}
 	}
 
-	@Check(CheckType.FAST)
-	public void regionCantBeEnteredUsingShallowHistory(Entry e) {
-		if (e.getKind() == EntryKind.SHALLOW_HISTORY) {
-			List<Region> regions = new ArrayList<>();
-			for (Vertex v : e.getParentRegion().getVertices()) {
-				if (v instanceof CompositeElement) {
-					regions.addAll(((CompositeElement) v).getRegions());
-				}
-			}
-			for (Region r : regions) {
-				Entry defaultEntry = null;
-				for (Vertex v : r.getVertices()) {
-					if (v instanceof Entry) {
-						String name = v.getName().trim().toLowerCase();
-						if (name != null || "".equals(name) || "default".equals(name)) {
-							defaultEntry = (Entry) v;
-							break;
-						}
-					}
-				}
-				if (defaultEntry == null) {
-					error(REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY_MSG, r, null, -1,
-							REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY_CODE);
-				} else if (defaultEntry.getOutgoingTransitions().size() != 1) {
-					error(REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_MSG, r, null, -1,
-							REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_CODE);
-				}
-			}
-
-		}
-
-	}
-
-	@Check
-	public void checkOnlyOneDefaultEntryPermitted(Entry entry) {
-		Region region = (Region) entry.eContainer();
-		List<Entry> initialEntires = region.getVertices().stream().filter(Entry.class::isInstance)
-				.map(Entry.class::cast).filter(v -> v.getKind() == EntryKind.INITIAL).collect(Collectors.toList());
-		boolean unamedEntryExists = initialEntires.stream().filter(v -> v.getName().equals("")).count() > 0;
-		boolean defaultNamedEntryExists = initialEntires.stream()
-				.filter(v -> v.getName().trim().equalsIgnoreCase("default")).count() > 0;
-		if (unamedEntryExists && defaultNamedEntryExists) {
-			error(REGION_MULTIPLE_DEFAULT_ENTRIES_MSG, region, null, -1, REGION_MULTIPLE_DEFAULT_ENTRIES_CODE);
-		}
-	}
 
 }

+ 95 - 0
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/validation/RegionValidator.java

@@ -0,0 +1,95 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.eclipse.xtext.validation.Check;
+import org.eclipse.xtext.validation.CheckType;
+import org.yakindu.sct.model.sgraph.CompositeElement;
+import org.yakindu.sct.model.sgraph.Entry;
+import org.yakindu.sct.model.sgraph.EntryKind;
+import org.yakindu.sct.model.sgraph.Exit;
+import org.yakindu.sct.model.sgraph.Region;
+import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.model.sgraph.Transition;
+import org.yakindu.sct.model.sgraph.Vertex;
+
+/**
+ * 
+ * All validation contraints for the meta model elements {@link Region}
+ *
+ */
+public class RegionValidator extends AbstractSGraphValidator {
+
+
+	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";
+
+	private static final String REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_MSG = "The region can't be entered using the shallow history. Add a transition from default entry to a state.";
+	public static final String REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_CODE = "entry.in.transition";
+
+	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";
+
+
+	
+	
+
+	@Check(CheckType.FAST)
+	public void regionCantBeEnteredUsingShallowHistory(Entry e) {
+		if (e.getKind() == EntryKind.SHALLOW_HISTORY) {
+			List<Region> regions = new ArrayList<>();
+			for (Vertex v : e.getParentRegion().getVertices()) {
+				if (v instanceof CompositeElement) {
+					regions.addAll(((CompositeElement) v).getRegions());
+				}
+			}
+			for (Region r : regions) {
+				Entry defaultEntry = null;
+				for (Vertex v : r.getVertices()) {
+					if (v instanceof Entry) {
+						String name = v.getName().trim().toLowerCase();
+						if (name != null || "".equals(name) || "default".equals(name)) {
+							defaultEntry = (Entry) v;
+							break;
+						}
+					}
+				}
+				if (defaultEntry == null) {
+					error(REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY_MSG, r, null, -1,
+							REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY_CODE);
+				} else if (defaultEntry.getOutgoingTransitions().size() != 1) {
+					error(REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_MSG, r, null, -1,
+							REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_CODE);
+				}
+			}
+
+		}
+
+	}
+
+	@Check
+	public void checkOnlyOneDefaultEntryPermitted(Entry entry) {
+		Region region = (Region) entry.eContainer();
+		List<Entry> initialEntires = region.getVertices().stream().filter(Entry.class::isInstance)
+				.map(Entry.class::cast).filter(v -> v.getKind() == EntryKind.INITIAL).collect(Collectors.toList());
+		boolean unamedEntryExists = initialEntires.stream().filter(v -> v.getName().equals("")).count() > 0;
+		boolean defaultNamedEntryExists = initialEntires.stream()
+				.filter(v -> v.getName().trim().equalsIgnoreCase("default")).count() > 0;
+		if (unamedEntryExists && defaultNamedEntryExists) {
+			error(REGION_MULTIPLE_DEFAULT_ENTRIES_MSG, region, null, -1, REGION_MULTIPLE_DEFAULT_ENTRIES_CODE);
+		}
+	}
+
+}

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

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

+ 6 - 0
test-plugins/org.yakindu.sct.model.sgraph.test/.project

@@ -5,6 +5,11 @@
 	<projects>
 	</projects>
 	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
 		<buildCommand>
 			<name>org.eclipse.jdt.core.javabuilder</name>
 			<arguments>
@@ -24,6 +29,7 @@
 	<natures>
 		<nature>org.eclipse.pde.PluginNature</nature>
 		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
 	</natures>
 	<filteredResources>
 		<filter>

+ 1 - 1
test-plugins/org.yakindu.sct.model.sgraph.test/.settings/org.eclipse.core.resources.prefs

@@ -1,3 +1,3 @@
 eclipse.preferences.version=1
-encoding//testmodels/entry/RegionCantBeEnteredUsingShallowHistory.sct=UTF-8
+encoding//testmodels/region/RegionCantBeEnteredUsingShallowHistory.sct=UTF-8
 encoding/<project>=UTF-8

+ 2 - 0
test-plugins/org.yakindu.sct.model.sgraph.test/src/org/yakindu/sct/model/sgraph/test/AllTests.java

@@ -17,6 +17,7 @@ import org.yakindu.sct.model.sgraph.test.validation.ChoiceValidatorTest;
 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.RegionValidatorTest;
 import org.yakindu.sct.model.sgraph.test.validation.StateValidatorTest;
 import org.yakindu.sct.model.sgraph.test.validation.StatechartValidatorTest;
 import org.yakindu.sct.model.sgraph.test.validation.SynchronizationValidatorTest;
@@ -26,6 +27,7 @@ import org.yakindu.sct.model.sgraph.test.validation.VertexValidatorTest;
 @RunWith(value = Suite.class)
 @SuiteClasses(value = { 
 		StatechartValidatorTest.class, 
+		RegionValidatorTest.class,
 		ChoiceValidatorTest.class, 
 		EntryValidatorTest.class, 
 		ExitValidatorTest.class,

+ 4 - 54
test-plugins/org.yakindu.sct.model.sgraph.test/src/org/yakindu/sct/model/sgraph/test/validation/EntryValidatorTest.java

@@ -24,12 +24,15 @@ 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.EntryValidator;
+import org.yakindu.sct.model.sgraph.validation.RegionValidator;
 
 import com.google.inject.Inject;
 
 /**
  * 
  * Tests for {@link EntryValidator}
+ * 
+ * TODO: Test composite state regions
  *
  */
 public class EntryValidatorTest extends AbstractSGraphValidatorTest {
@@ -128,24 +131,6 @@ public class EntryValidatorTest extends AbstractSGraphValidatorTest {
 	}
 
 
-	/**
-	 * 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();
-	}
 
 	@Test
 	public void disallowTrigger() {
@@ -158,40 +143,5 @@ public class EntryValidatorTest extends AbstractSGraphValidatorTest {
 		tester.validate(entry).assertError(ENTRY_TRANSITIONS_NO_TRIGGER_ON_OUT_CODE);
 	}
 
-	@Test
-	public void checkOnlyOneDefaultEntryPermitted() {
-		State state = createState();
-		Region region = ((Region) state.eContainer());
-		Entry entry = factory.createEntry();
-		region.getVertices().add(entry);
-		Entry entry2 = factory.createEntry();
-		entry2.setName("default");
-		region.getVertices().add(entry2);
-		createTransition(entry, state);
-		createTransition(entry2, state);
-		tester.validate(entry).assertError(REGION_MULTIPLE_DEFAULT_ENTRIES_CODE);
-	}
-
-	@Test
-	public void regionCantBeEnteredUsingShallowHistory() {
-		Statechart statechart = loadStatechart("RegionCantBeEnteredUsingShallowHistory.sct");
-		AssertableDiagnostics result = tester.validate(statechart);
-		result.assertDiagnosticsCount(2);
-
-		result.assertAny(
-				AssertableDiagnostics.errorCode(REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY_CODE));
-		result.assertAny(AssertableDiagnostics
-				.errorCode(REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_CODE));
-	}
-
-	@Test
-	public void validTransitionToInnerChoice() {
-		Statechart statechart = loadStatechart("ValidTransitionToInnerChoice.sct");
-		tester.validate(statechart).assertOK();
-	}
-
-	@Override
-	protected Statechart loadStatechart(String path) {
-		return super.loadStatechart("entry/" + path);
-	}
+	
 }

+ 75 - 0
test-plugins/org.yakindu.sct.model.sgraph.test/src/org/yakindu/sct/model/sgraph/test/validation/RegionValidatorTest.java

@@ -0,0 +1,75 @@
+/**
+ * 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.RegionValidator.*;
+
+import org.eclipse.xtext.junit4.validation.AssertableDiagnostics;
+import org.junit.Test;
+import org.yakindu.sct.model.sgraph.Entry;
+import org.yakindu.sct.model.sgraph.Region;
+import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.model.sgraph.test.util.SGraphJavaValidatorTester;
+import org.yakindu.sct.model.sgraph.validation.RegionValidator;
+
+import com.google.inject.Inject;
+
+/**
+ * 
+ * Tests for {@link RegionValidator}
+ *
+ */
+public class RegionValidatorTest extends AbstractSGraphValidatorTest {
+
+	@Inject
+	protected SGraphJavaValidatorTester<RegionValidator> tester;
+
+
+
+
+	@Test
+	public void checkOnlyOneDefaultEntryPermitted() {
+		State state = createState();
+		Region region = ((Region) state.eContainer());
+		Entry entry = factory.createEntry();
+		region.getVertices().add(entry);
+		Entry entry2 = factory.createEntry();
+		entry2.setName("default");
+		region.getVertices().add(entry2);
+		createTransition(entry, state);
+		createTransition(entry2, state);
+		tester.validate(entry).assertError(REGION_MULTIPLE_DEFAULT_ENTRIES_CODE);
+	}
+
+	@Test
+	public void regionCantBeEnteredUsingShallowHistory() {
+		Statechart statechart = loadStatechart("RegionCantBeEnteredUsingShallowHistory.sct");
+		AssertableDiagnostics result = tester.validate(statechart);
+		result.assertDiagnosticsCount(2);
+
+		result.assertAny(
+				AssertableDiagnostics.errorCode(REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY_CODE));
+		result.assertAny(AssertableDiagnostics
+				.errorCode(REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_CODE));
+	}
+
+	@Test
+	public void validTransitionToInnerChoice() {
+		Statechart statechart = loadStatechart("ValidTransitionToInnerChoice.sct");
+		tester.validate(statechart).assertOK();
+	}
+
+	@Override
+	protected Statechart loadStatechart(String path) {
+		return super.loadStatechart("region/" + path);
+	}
+}

test-plugins/org.yakindu.sct.model.sgraph.test/testmodels/entry/RegionCantBeEnteredUsingShallowHistory.sct → test-plugins/org.yakindu.sct.model.sgraph.test/testmodels/region/RegionCantBeEnteredUsingShallowHistory.sct


test-plugins/org.yakindu.sct.model.sgraph.test/testmodels/entry/ValidTransitionToInnerChoice.sct → test-plugins/org.yakindu.sct.model.sgraph.test/testmodels/region/ValidTransitionToInnerChoice.sct