ソースを参照

Share project "org.yakindu.sct.model.statechart.test" into "https://svn.codespot.com/a/eclipselabs.org/yakindu"

terfloth@itemis.de 14 年 前
コミット
0b7027c3e2

+ 7 - 0
plugins/org.yakindu.sct.model.statechart.test/.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 28 - 0
plugins/org.yakindu.sct.model.statechart.test/.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.yakindu.sct.model.statechart.test</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 8 - 0
plugins/org.yakindu.sct.model.statechart.test/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,8 @@
+#Thu Jun 09 09:40:38 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5

+ 12 - 0
plugins/org.yakindu.sct.model.statechart.test/META-INF/MANIFEST.MF

@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: YSCT model tests
+Bundle-SymbolicName: org.yakindu.sct.model.statechart.test
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.yakindu.sct.model.statechart.test.Activator
+Require-Bundle: org.yakindu.sct.model.statechart;bundle-version="1.0.0",
+ org.junit;bundle-version="3.8.2",
+ org.eclipse.ui,
+ org.eclipse.core.runtime
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5

+ 4 - 0
plugins/org.yakindu.sct.model.statechart.test/build.properties

@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .

+ 50 - 0
plugins/org.yakindu.sct.model.statechart.test/src/org/yakindu/sct/model/statechart/test/Activator.java

@@ -0,0 +1,50 @@
+package org.yakindu.sct.model.statechart.test;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+	// The plug-in ID
+	public static final String PLUGIN_ID = "org.yakindu.sct.model.statechart.test"; //$NON-NLS-1$
+
+	// The shared instance
+	private static Activator plugin;
+	
+	/**
+	 * The constructor
+	 */
+	public Activator() {
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+	 */
+	public void start(BundleContext context) throws Exception {
+		super.start(context);
+		plugin = this;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+	 */
+	public void stop(BundleContext context) throws Exception {
+		plugin = null;
+		super.stop(context);
+	}
+
+	/**
+	 * Returns the shared instance
+	 *
+	 * @return the shared instance
+	 */
+	public static Activator getDefault() {
+		return plugin;
+	}
+
+}

+ 38 - 0
plugins/org.yakindu.sct.model.statechart.test/src/org/yakindu/sct/model/statechart/test/AllTests.java

@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2011 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.statechart.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * 
+ * @author terfloth
+ * 
+@RunWith(value=Suite.class)
+@SuiteClasses(value={
+		ExpressionsTest.class, 
+		FunctionsTest.class,
+		CoreFunctionsTest.class
+		}) 
+*/
+public class AllTests extends TestSuite{
+	
+	public static Test suite() {
+		TestSuite suite = new AllTests();
+		suite.addTestSuite(StatechartBaseValidationTest.class);
+			
+		return suite;
+	}
+
+	
+
+}

+ 253 - 0
plugins/org.yakindu.sct.model.statechart.test/src/org/yakindu/sct/model/statechart/test/StatechartBaseValidationTest.java

@@ -0,0 +1,253 @@
+/**
+ * Copyright (c) 2011 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.statechart.test;
+
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.yakindu.model.sct.statechart.Entry;
+import org.yakindu.model.sct.statechart.FinalState;
+import org.yakindu.model.sct.statechart.Region;
+import org.yakindu.model.sct.statechart.State;
+import org.yakindu.model.sct.statechart.Statechart;
+import org.yakindu.model.sct.statechart.StatechartFactory;
+import org.yakindu.model.sct.statechart.StatechartPackage;
+import org.yakindu.model.sct.statechart.Transition;
+import org.yakindu.model.sct.statechart.Vertex;
+import org.yakindu.model.sct.statechart.util.StatechartValidator;
+import static org.yakindu.model.sct.statechart.util.StatechartValidator.*;
+
+/**
+ * Test of all validation rules that test very basic properties of statecharts.
+ * 
+ * @author terfloth
+ */
+public class StatechartBaseValidationTest extends TestCase {
+	
+
+	static {
+		// set up EMF - the EPackage.Registry requires a context class loader ...
+		if (Thread.currentThread().getContextClassLoader() == null) {
+			Thread.currentThread().setContextClassLoader(StatechartBaseValidationTest.class.getClassLoader());	
+		}
+		StatechartPackage.eINSTANCE.eClass();
+	}
+	
+	protected StatechartFactory factory;
+	protected StatechartValidator validator;
+	protected BasicDiagnostic diagnostics;
+	
+	protected Statechart statechart;
+	protected Region region;
+	private State state;
+
+
+	@Override
+	protected void setUp() throws Exception {
+		super.setUp();
+		validator = new StatechartValidator();
+		diagnostics = new BasicDiagnostic();
+		factory = StatechartFactory.eINSTANCE;
+		statechart = factory.createStatechart();
+		statechart.setName("SC");
+	}
+
+	
+	protected void prepareStateTest() {
+		region = factory.createRegion();
+		statechart.getRegions().add(region);
+		state = factory.createState();
+		state.setName(getName());
+		region.getVertices().add(state);
+	}
+	
+	
+	/**
+	 * A regular state must have a name.
+	 */
+	public void testStateWithoutName() {
+		prepareStateTest();
+		
+		state.setName(null);
+		assertFalse(validator.validate(state,  diagnostics, new HashMap<Object,Object>()));
+		assertError(diagnostics, ISSUE_STATE_WITHOUT_NAME);
+	}
+
+	/**
+	 * A states name must not be empty.
+	 */
+	public void testStateWithEmptyName() {
+		prepareStateTest();
+		
+		state.setName("");
+		assertFalse(validator.validate(state,  diagnostics, new HashMap<Object,Object>()));
+		assertError(diagnostics, ISSUE_STATE_WITHOUT_NAME);
+	}
+	
+	
+	/**
+	 * A state name with just white spaces is not valid.
+	 */
+	public void testStateWithWhitespaceName() {
+		prepareStateTest();
+		
+		state.setName(" 	");
+		assertFalse(validator.validate(state,  diagnostics, new HashMap<Object,Object>()));
+		assertError(diagnostics, ISSUE_STATE_WITHOUT_NAME);
+	}
+
+	
+	/**
+	 * A state must be reachable.
+	 */
+	public void testStateUnreachable() {
+		prepareStateTest();
+		
+		assertFalse(validator.validate(state,  diagnostics, new HashMap<Object,Object>()));
+		assertError(diagnostics, ISSUE_NODE_NOT_REACHABLE);
+	}
+
+	
+	/**
+	 * A regular state may be a dead end.
+	 */
+	public void testStateDeadEnd() {
+		prepareStateTest();
+		
+		validator.validate(state,  diagnostics, new HashMap<Object,Object>());
+		assertNoIssue(diagnostics, ISSUE_STATE_WITHOUT_OUTGOING_TRANSITION);
+	}
+
+	
+	/**
+	 * A valid regular state must produce no issues.
+	 */
+	public void testValidState() {
+		prepareStateTest();
+		Entry entry = factory.createEntry();
+		createTransition(entry, state);
+				
+		assertTrue(validator.validate(state,  diagnostics, new HashMap<Object,Object>()));
+		assertIssueCount(diagnostics, 0);
+	}
+
+	
+	
+	/**
+	 * A final state should have at least one incoming transition.
+	 */
+	public void testFinalStateIsolated() {
+		statechart = factory.createStatechart();
+		Region region = factory.createRegion();
+		statechart.getRegions().add(region);
+		FinalState finalState = factory.createFinalState();
+		region.getVertices().add(finalState);
+		
+		assertFalse(validator.validate(finalState,  diagnostics, new HashMap<Object,Object>()));
+		
+		assertIssueCount(diagnostics, 1);
+		assertError(diagnostics, ISSUE_NODE_NOT_REACHABLE);
+	}
+
+
+	/**
+	 * A positive case for a valid final state.
+	 */
+	public void testFinalStateValid() {
+		statechart = factory.createStatechart();
+		Region region = factory.createRegion();
+		statechart.getRegions().add(region);
+		FinalState finalState = factory.createFinalState();
+		region.getVertices().add(finalState);
+		State state = factory.createState();
+		region.getVertices().add(state);
+		createTransition(state, finalState);
+
+		assertTrue(validator.validate(finalState,  diagnostics, new HashMap<Object,Object>()));
+		assertIssueCount(diagnostics, 0);
+	}
+
+	
+	/**
+	 * A final state should have at least one incoming transition.
+	 */
+	public void testFinalStateOutgoingTransitions() {
+		statechart = factory.createStatechart();
+		Region region = factory.createRegion();
+		statechart.getRegions().add(region);
+		FinalState finalState = factory.createFinalState();
+		region.getVertices().add(finalState);
+		State state = factory.createState();
+		region.getVertices().add(state);
+
+		createTransition(state, finalState);
+		createTransition(finalState, state);
+
+
+		assertFalse(validator.validate(finalState,  diagnostics, new HashMap<Object,Object>()));
+		
+		assertIssueCount(diagnostics, 1);
+		assertWarning(diagnostics, StatechartValidator.ISSUE_FINAL_STATE_OUTGOING_TRANSITION);
+	}
+
+
+	
+	
+	protected Transition createTransition(Vertex source, Vertex target) {
+		Transition trans = factory.createTransition();
+		trans.setSource(source);
+		trans.setTarget(target);
+		source.getOutgoingTransitions().add(trans);
+		target.getIncomingTransitions().add(trans);
+		return trans;
+	}
+	
+
+	
+	protected void assertError(BasicDiagnostic 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(BasicDiagnostic 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 assertIssue(BasicDiagnostic diag, String message) {
+		assertNotNull("Issue '" + message + "' does not exist.", issueByName(diag, message));
+	}
+	
+	protected void assertNoIssue(BasicDiagnostic diag, String message) {
+		assertNull("Issue '" + message + "' does exist.", issueByName(diag, message));
+	}
+
+	protected void assertIssueCount(BasicDiagnostic diag, int count) {
+		int c = diagnostics.getChildren().size();
+		assertEquals("expected " + count + " issue(s) but were " + c + " [" + diag.toString() + "]", count, c);
+	}
+	
+	
+	protected Diagnostic issueByName(BasicDiagnostic diag, String message) {
+		for (Diagnostic issue : diag.getChildren()) {
+			if (message.equals(issue.getMessage())) return issue;
+		}
+		
+		return null;
+	}
+
+}