Selaa lähdekoodia

Tests in stextJavaValidatorTest activated again

benjamin.schwertfeger@gmail.com 13 vuotta sitten
vanhempi
commit
58c1538ccd

+ 33 - 27
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/validation/STextJavaValidator.java

@@ -63,6 +63,9 @@ import de.itemis.xtext.utils.gmf.resource.InjectMembersResource;
  */
 public class STextJavaValidator extends AbstractSTextJavaValidator {
 
+	public static final String FEATURE_CALL_HAS_NO_EFFECT = "FeatureCall has no effect";
+	public static final String ENTRY_EXIT_TRIGGER_NOT_ALLOWED = "Entry/Exit trigger not allowed";
+	public static final String LOCAL_REACTIONS_NOT_ALLOWED = "Local reactions not allowed";
 	public static final String FEATURE_CALL_TO_SCOPE = "FEATURE_CALL_TO_SCOPE";
 	public static final String ONLY_ONE_INTERFACE = "Only one default/unnamed interface is allowed.";
 	public static final String IN_OUT_DECLARATIONS = "In/Out declarations are not allowed in internal scope.";
@@ -132,17 +135,20 @@ public class STextJavaValidator extends AbstractSTextJavaValidator {
 							|| eventSpec instanceof OnCycleEvent || eventSpec instanceof AlwaysEvent)) {
 
 				error("entry, exit, oncycle and always events are allowed as local reactions only.",
-						StextPackage.Literals.REACTION_TRIGGER__TRIGGERS);
+						StextPackage.Literals.REACTION_TRIGGER__TRIGGERS,
+						INSIGNIFICANT_INDEX, LOCAL_REACTIONS_NOT_ALLOWED);
 			}
 
 			// Context StatechartDefiniton
 			if (isStatechartDefinitionChild(reactionTrigger)) {
 				if (eventSpec instanceof EntryEvent) {
 					error("Entry events are not allowed in statechart definition.",
-							StextPackage.Literals.REACTION_TRIGGER__TRIGGERS);
+							StextPackage.Literals.REACTION_TRIGGER__TRIGGERS,
+							INSIGNIFICANT_INDEX, ENTRY_EXIT_TRIGGER_NOT_ALLOWED);
 				} else if (eventSpec instanceof ExitEvent) {
 					error("Exit events are not allowed in statechart definition.",
-							StextPackage.Literals.REACTION_TRIGGER__TRIGGERS);
+							StextPackage.Literals.REACTION_TRIGGER__TRIGGERS,
+							INSIGNIFICANT_INDEX, ENTRY_EXIT_TRIGGER_NOT_ALLOWED);
 				}
 			}
 		}
@@ -167,7 +173,8 @@ public class STextJavaValidator extends AbstractSTextJavaValidator {
 				} else {
 					error("Action has no effect.",
 							StextPackage.Literals.REACTION_EFFECT__ACTIONS,
-							effect.getActions().indexOf(exp));
+							effect.getActions().indexOf(exp),
+							FEATURE_CALL_HAS_NO_EFFECT);
 				}
 
 			}
@@ -179,23 +186,18 @@ public class STextJavaValidator extends AbstractSTextJavaValidator {
 			if (call.getFeature() instanceof Property) {
 				error("Access to property '" + call.getFeature().getName()
 						+ "' has no effect.", call,
-						StextPackage.Literals.FEATURE_CALL__FEATURE, 0);
+						StextPackage.Literals.FEATURE_CALL__FEATURE,
+						INSIGNIFICANT_INDEX, FEATURE_CALL_HAS_NO_EFFECT);
 			} else if (call.getFeature() instanceof Event) {
 				error("Access to event '" + call.getFeature().getName()
 						+ "' has no effect.", call,
-						StextPackage.Literals.FEATURE_CALL__FEATURE, 0);
+						StextPackage.Literals.FEATURE_CALL__FEATURE,
+						INSIGNIFICANT_INDEX, FEATURE_CALL_HAS_NO_EFFECT);
 			} else {
 				error("Access to feature '" + call.getFeature().getName()
 						+ "' has no effect.", call,
-						StextPackage.Literals.FEATURE_CALL__FEATURE, 0);
-			}
-
-			if (call.getOwner() != null) {
-				if (call.getOwner() instanceof FeatureCall)
-					checkFeatureCallEffect((FeatureCall) call.getOwner());
-				else if (call.getOwner() instanceof TypedElementReferenceExpression)
-					checkTypedElementReferenceEffect((TypedElementReferenceExpression) call
-							.getOwner());
+						StextPackage.Literals.FEATURE_CALL__FEATURE,
+						INSIGNIFICANT_INDEX, FEATURE_CALL_HAS_NO_EFFECT);
 			}
 		}
 
@@ -209,19 +211,19 @@ public class STextJavaValidator extends AbstractSTextJavaValidator {
 						+ "' has no effect.",
 						ter,
 						StextPackage.Literals.TYPED_ELEMENT_REFERENCE_EXPRESSION__REFERENCE,
-						0);
+						INSIGNIFICANT_INDEX, FEATURE_CALL_HAS_NO_EFFECT);
 			} else if (ter.getReference() instanceof Event) {
 				error("Access to event '" + ter.getReference().getName()
 						+ "' has no effect.",
 						ter,
 						StextPackage.Literals.TYPED_ELEMENT_REFERENCE_EXPRESSION__REFERENCE,
-						0);
+						INSIGNIFICANT_INDEX, FEATURE_CALL_HAS_NO_EFFECT);
 			} else {
 				error("Access to feature '" + ter.getReference().getName()
 						+ "' has no effect.",
 						ter,
 						StextPackage.Literals.TYPED_ELEMENT_REFERENCE_EXPRESSION__REFERENCE,
-						0);
+						INSIGNIFICANT_INDEX, FEATURE_CALL_HAS_NO_EFFECT);
 			}
 		}
 	}
@@ -240,15 +242,19 @@ public class STextJavaValidator extends AbstractSTextJavaValidator {
 		}
 	}
 
-	@Check(CheckType.FAST)
-	public void checkLocalReaction(LocalReaction localReaction) {
-		if (localReaction.eContainer() instanceof InterfaceScope) {
-			error("Local reactions are not allowed in interface scope.",
-					localReaction,
-					StextPackage.Literals.LOCAL_REACTION__PROPERTIES,
-					ValidationMessageAcceptor.INSIGNIFICANT_INDEX);
-		}
-	}
+	// Check not possible by grammar. Testcase shows now error until 1.5.'12
+	// because it will be neccessary again, if
+	// entry in statechart is available again
+	// @Check(CheckType.FAST)
+	// public void checkLocalReaction(LocalReaction localReaction) {
+	// if (localReaction.eContainer() instanceof InterfaceScope) {
+	// error("Local reactions are not allowed in interface scope.",
+	// localReaction,
+	// StextPackage.Literals.LOCAL_REACTION__PROPERTIES,
+	// ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
+	// LOCAL_REACTIONS_NOT_ALLOWED);
+	// }
+	// }
 
 	@Check(CheckType.FAST)
 	public void checkInterfaceScope(ScopedElement statechart) {

+ 91 - 9
test-plugins/org.yakindu.sct.model.stext.test/src/org/yakindu/sct/model/stext/test/STextJavaValidatorTest.java

@@ -13,13 +13,19 @@ package org.yakindu.sct.model.stext.test;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
-import static org.yakindu.sct.model.sgraph.test.util.SgraphTestFactory._createStatechart;
+import static org.yakindu.sct.model.stext.validation.STextJavaValidator.ENTRY_EXIT_TRIGGER_NOT_ALLOWED;
+import static org.yakindu.sct.model.stext.validation.STextJavaValidator.FEATURE_CALL_HAS_NO_EFFECT;
 import static org.yakindu.sct.model.stext.validation.STextJavaValidator.FEATURE_CALL_TO_SCOPE;
 import static org.yakindu.sct.model.stext.validation.STextJavaValidator.IN_OUT_DECLARATIONS;
 import static org.yakindu.sct.model.stext.validation.STextJavaValidator.LOCAL_DECLARATIONS;
+import static org.yakindu.sct.model.stext.validation.STextJavaValidator.LOCAL_REACTIONS_NOT_ALLOWED;
 import static org.yakindu.sct.model.stext.validation.STextJavaValidator.ONLY_ONE_INTERFACE;
 
 import java.lang.reflect.Method;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.xtext.junit4.InjectWith;
@@ -29,7 +35,6 @@ import org.eclipse.xtext.junit4.validation.ValidatorTester;
 import org.eclipse.xtext.validation.Check;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.yakindu.sct.model.sgraph.Scope;
@@ -37,6 +42,7 @@ import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.model.stext.stext.Expression;
 import org.yakindu.sct.model.stext.stext.InterfaceScope;
 import org.yakindu.sct.model.stext.stext.InternalScope;
+import org.yakindu.sct.model.stext.stext.ReactionEffect;
 import org.yakindu.sct.model.stext.stext.StatechartSpecification;
 import org.yakindu.sct.model.stext.stext.TransitionSpecification;
 import org.yakindu.sct.model.stext.stext.TypedElementReferenceExpression;
@@ -127,18 +133,92 @@ public class STextJavaValidatorTest extends AbstractSTextTest {
 	 * @see STextJavaValidator#checkReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger)
 	 */
 	@Test
-	@Ignore("Implement me")
 	public void checkReactionTrigger() {
-		fail("implement me");
+		// ENTRY, EXIT, ALWAYS, ONCYCLE not allowed in transitions
+		Scope context = (Scope) parseExpression(
+				"internal : event a : integer var myVar : integer", null,
+				InternalScope.class.getSimpleName());
+		EObject model = super.parseExpression("entry / myVar = 5", context,
+				TransitionSpecification.class.getSimpleName());
+		AssertableDiagnostics validationResult = tester.validate(model);
+		validationResult.assertError(LOCAL_REACTIONS_NOT_ALLOWED);
+
+		model = super.parseExpression("exit / myVar = 5", context,
+				TransitionSpecification.class.getSimpleName());
+		validationResult = tester.validate(model);
+		validationResult.assertError(LOCAL_REACTIONS_NOT_ALLOWED);
+
+		model = super.parseExpression("oncycle / myVar = 5", context,
+				TransitionSpecification.class.getSimpleName());
+		validationResult = tester.validate(model);
+		validationResult.assertError(LOCAL_REACTIONS_NOT_ALLOWED);
+
+		model = super.parseExpression("always / myVar = 5", context,
+				TransitionSpecification.class.getSimpleName());
+		validationResult = tester.validate(model);
+		validationResult.assertError(LOCAL_REACTIONS_NOT_ALLOWED);
+
+		// ENTRY / EXIT not allowed in definition
+		model = (StatechartSpecification) parseExpression(
+				"internal : var a : integer entry / a=2", null,
+				StatechartSpecification.class.getSimpleName());
+		validationResult = tester.validate(model);
+		validationResult.assertError(ENTRY_EXIT_TRIGGER_NOT_ALLOWED);
+
+		model = (StatechartSpecification) parseExpression(
+				"internal : var a : integer exit / a=2", null,
+				StatechartSpecification.class.getSimpleName());
+		validationResult = tester.validate(model);
+		validationResult.assertError(ENTRY_EXIT_TRIGGER_NOT_ALLOWED);
 	}
 
 	/**
 	 * @see STextJavaValidator#checkReactionEffectActions(org.yakindu.sct.model.stext.stext.ReactionEffect)
 	 */
 	@Test
-	@Ignore("Implement me")
 	public void checkReactionEffectActions() {
-		fail("Implement me");
+		Scope s1 = (InternalScope) parseExpression(
+				"internal : var a : integer event e operation o () : void",
+				null, InternalScope.class.getSimpleName());
+		Scope s2 = (InterfaceScope) parseExpression(
+				"interface if : var a : integer in event e operation o()",
+				null, InterfaceScope.class.getSimpleName());
+
+		EObject model = super.parseExpression("a", s1,
+				ReactionEffect.class.getSimpleName());
+		AssertableDiagnostics result = tester.validate(model);
+		result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
+
+		model = super.parseExpression("1+3", s1,
+				ReactionEffect.class.getSimpleName());
+		result = tester.validate(model);
+		result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
+
+		model = super.parseExpression("valueof(e)", s1,
+				ReactionEffect.class.getSimpleName());
+		result = tester.validate(model);
+		result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
+
+		model = super.parseExpression("o()", s1,
+				ReactionEffect.class.getSimpleName());
+		result = tester.validate(model);
+		result.assertOK();
+
+		model = super.parseExpression("if.a", s2,
+				ReactionEffect.class.getSimpleName());
+		result = tester.validate(model);
+		result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
+
+		model = super.parseExpression("valueof(if.e)", s2,
+				ReactionEffect.class.getSimpleName());
+		result = tester.validate(model);
+		result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
+
+		model = super.parseExpression("if.o", s2,
+				ReactionEffect.class.getSimpleName());
+		result = tester.validate(model);
+		result.assertOK();
+
 	}
 
 	/**
@@ -167,12 +247,14 @@ public class STextJavaValidatorTest extends AbstractSTextTest {
 	}
 
 	/**
+	 * @throws ParseException
 	 * @see STextJavaValidator#checkLocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction)
 	 */
 	@Test
-	@Ignore("Implement me")
-	public void checkLocalReaction() {
-		fail("Implement me");
+	public void checkLocalReaction() throws ParseException {
+		if (new Date().after(new SimpleDateFormat().parse("01.05.12 12:00"))) {
+			fail("Local Reaction should be activated for Statecharts again");
+		}
 	}
 
 	/**

+ 3 - 1
test-plugins/org.yakindu.sct.model.stext.test/src/org/yakindu/sct/model/stext/test/util/AbstractSTextTest.java

@@ -68,7 +68,9 @@ public abstract class AbstractSTextTest {
 		XtextResource resource = getResource();
 		Statechart sc = _createStatechart("myStatechart");
 		resource.getContents().add(sc);
-		sc.getScopes().add(context);
+		if (context != null) {
+			sc.getScopes().add(context);
+		}
 		resource.setURI(URI.createPlatformPluginURI("path", true));
 		ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
 		parserRule.setName(ruleName);