Browse Source

Added stext.resource.test.plugin

Andreas Mülder 13 years ago
parent
commit
5404ddbb50

+ 7 - 0
test-plugins/org.yakindu.sct.model.stext.resource.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/JavaSE-1.7"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

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

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.yakindu.sct.model.stext.resource.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>

+ 7 - 0
test-plugins/org.yakindu.sct.model.stext.resource.test/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7

+ 9 - 0
test-plugins/org.yakindu.sct.model.stext.resource.test/META-INF/MANIFEST.MF

@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Test
+Bundle-SymbolicName: org.yakindu.sct.model.stext.resource.test
+Bundle-Version: 1.0.0.qualifier
+Fragment-Host: org.yakindu.sct.model.stext.resource;bundle-version="1.0.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Require-Bundle: org.junit,
+ de.itemis.xtext.utils.jface;bundle-version="1.0.0"

BIN
test-plugins/org.yakindu.sct.model.stext.resource.test/bin/org/yakindu/sct/model/stext/resource/test/SCTResourceTest$1.class


BIN
test-plugins/org.yakindu.sct.model.stext.resource.test/bin/org/yakindu/sct/model/stext/resource/test/SCTResourceTest.class


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

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

+ 91 - 0
test-plugins/org.yakindu.sct.model.stext.resource.test/pom.xml

@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.yakindu.sct</groupId>
+		<artifactId>org.yakindu.sct.releng</artifactId>
+		<version>1.0.0-SNAPSHOT</version>
+		<relativePath>../org.yakindu.sct.releng/pom.xml</relativePath>
+	</parent>
+	<artifactId>org.yakindu.sct.model.stext.resource.test</artifactId>
+	<groupId>org.yakindu.sct.plugins</groupId>
+	<packaging>eclipse-test-plugin</packaging>
+	
+	<profiles>
+		<profile>
+			<id>CI</id>
+			<!-- Test failures are collected by jenkins and evaluated for instable builds -->
+			<properties>
+				<testFailureIgnore>true</testFailureIgnore>
+			</properties>
+		</profile>
+		<profile>
+			<id>macosx</id>
+			<activation>
+				<os>
+					<family>mac</family>
+				</os>
+			</activation>
+			<properties>
+				<test.vmargs>-Xmx512m -XX:MaxPermSize=256m -XstartOnFirstThread</test.vmargs>
+			</properties>
+		</profile>
+		<profile>
+			<id>other-os</id>
+			<activation>
+				<os>
+					<family>!mac</family>
+				</os>
+			</activation>
+			<properties>
+				<test.vmargs>-Xmx512m -XX:MaxPermSize=256m</test.vmargs>
+			</properties>
+		</profile>
+	</profiles>
+	
+	<properties>
+		<testFailureIgnore>false</testFailureIgnore>
+	</properties>
+	
+	<build>
+		<sourceDirectory>src</sourceDirectory>
+		<plugins>
+			<plugin>
+				<groupId>org.eclipse.tycho</groupId>
+				<artifactId>tycho-surefire-plugin</artifactId>
+				<version>${tycho-version}</version>
+				<configuration>
+					<!-- 
+					<includes>
+						<include>**/All*Tests.class</include>
+					</includes>
+					 -->
+					<excludes>
+						<exclude>**/util/TestModels.class</exclude>
+						<!-- It's toooo slow in the interpreter -->
+						<exclude>**/PerformanceTestTest.class</exclude>
+					</excludes>
+					<useUIHarness>false</useUIHarness>
+					<useUIThread>false</useUIThread>
+					<testFailureIgnore>${testFailureIgnore}</testFailureIgnore>
+					<argLine>${test.vmargs}</argLine>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.eclipse.tycho</groupId>
+				<artifactId>tycho-source-plugin</artifactId>
+				<version>${tycho-version}</version>
+				<executions>
+					<execution>
+						<id>plugin-source</id>
+						<goals>
+							<goal>plugin-source</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+</project>

+ 294 - 0
test-plugins/org.yakindu.sct.model.stext.resource.test/src/org/yakindu/sct/model/stext/resource/test/SCTResourceTest.java

@@ -0,0 +1,294 @@
+/**
+ * Copyright (c) 2012 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.stext.resource.test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
+
+import java.io.File;
+import java.util.Collections;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+import org.eclipse.xtext.resource.XtextSyntaxDiagnostic;
+import org.eclipse.xtext.util.CancelIndicator;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.yakindu.sct.model.sgraph.Declaration;
+import org.yakindu.sct.model.sgraph.Event;
+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.stext.resource.impl.StextResource;
+import org.yakindu.sct.model.stext.stext.ElementReferenceExpression;
+import org.yakindu.sct.model.stext.stext.EventDefinition;
+import org.yakindu.sct.model.stext.stext.ExitEvent;
+import org.yakindu.sct.model.stext.stext.IntLiteral;
+import org.yakindu.sct.model.stext.stext.InternalScope;
+import org.yakindu.sct.model.stext.stext.LocalReaction;
+import org.yakindu.sct.model.stext.stext.PrimitiveValueExpression;
+import org.yakindu.sct.model.stext.stext.ReactionTrigger;
+import org.yakindu.sct.model.stext.stext.RegularEventSpec;
+import org.yakindu.sct.model.stext.stext.StextFactory;
+import org.yakindu.sct.model.stext.stext.TimeEventSpec;
+import org.yakindu.sct.model.stext.stext.TimeEventType;
+import org.yakindu.sct.model.stext.stext.TimeUnit;
+import org.yakindu.sct.model.stext.ui.internal.STextActivator;
+
+import com.google.inject.Injector;
+
+import de.itemis.xtext.utils.jface.viewers.ContextElementAdapter;
+import de.itemis.xtext.utils.jface.viewers.ContextElementAdapter.IContextElementProvider;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class SCTResourceTest {
+
+	private StextFactory stextFac = StextFactory.eINSTANCE;
+
+	private StextResource res;
+
+	@Before
+	public void setUp() throws Exception {
+		Injector injector = STextActivator.getInstance().getInjector(
+				STextActivator.ORG_YAKINDU_SCT_MODEL_STEXT_STEXT);
+		ResourceSet resourceSet = new ResourceSetImpl();
+		res = new StextResource(URI.createURI("test.test"));
+		res.eAdapters().add(
+				new ContextElementAdapter(new IContextElementProvider() {
+
+					@Override
+					public EObject getContextObject() {
+						return res.getContents().get(0);
+					}
+				}));
+		resourceSet.getResources().add(res);
+		injector.injectMembers(res);
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		res = null;
+	}
+
+	@Test
+	public void testStatechartParsing() {
+		Statechart statechart = createStatechart("internal: event Event1");
+		assertEquals(0, statechart.getScopes().size());
+		res.getContents().add(statechart);
+		assertEquals(1, statechart.getScopes().size());
+		Scope scope = statechart.getScopes().get(0);
+		assertTrue(scope instanceof InternalScope);
+		EList<Declaration> declarations = ((InternalScope) scope)
+				.getDeclarations();
+		Declaration declaration = declarations.get(0);
+		assertTrue(declaration instanceof EventDefinition);
+		assertEquals("" + res.getSyntaxDiagnostics(), 0, res
+				.getSyntaxDiagnostics().size());
+	}
+
+	@Test
+	public void testTransitionParsing() throws Exception {
+		Transition transition = createTransition("after 10 s [true] / 3 * 3");
+		assertNull(transition.getTrigger());
+		assertNull(transition.getEffect());
+		res.getContents().add(transition);
+		assertNotNull(transition.getTrigger());
+		assertNotNull(transition.getEffect());
+	}
+
+	@Test
+	public void testStateParsing() throws Exception {
+		State state = createState("entry / 3 * 3");
+		assertEquals(0, state.getReactions().size());
+		res.getContents().add(state);
+		assertEquals(1, state.getReactions().size());
+		assertEquals("" + res.getSyntaxDiagnostics(), 0, res
+				.getSyntaxDiagnostics().size());
+	}
+
+	public void testInvalidExpressionParsing() {
+		State state = createState("This is not a valid expression");
+		res.getContents().add(state);
+		assertEquals(1, res.getSyntaxDiagnostics().size());
+		assertTrue(res.getErrors().get(0) instanceof XtextSyntaxDiagnostic);
+	}
+
+	@Test
+	public void testStatechartSerializing1() throws Exception {
+		res.setSerializerEnabled(true);
+		Statechart statechart = createStatechart("internal: event Event1");
+		res.getContents().add(statechart);
+		Scope internalScope = (InternalScope) statechart.getScopes().get(0);
+		Event event = internalScope.getEvents().get(0);
+		event.setName("Event2");
+		assertEquals("internal: event Event2", statechart.getSpecification());
+		assertEquals("" + res.getSyntaxDiagnostics(), 0, res
+				.getSyntaxDiagnostics().size());
+	}
+
+	@Test
+	public void testTransitionSerializing() throws Exception {
+		res.setSerializerEnabled(true);
+		Transition transition = createTransition("after 10\n s [true] / 3 * 3");
+		res.getContents().add(transition);
+		ReactionTrigger trigger = (ReactionTrigger) transition.getTrigger();
+		TimeEventSpec timeTrigger = stextFac.createTimeEventSpec();
+		timeTrigger.setType(TimeEventType.EVERY);
+		timeTrigger.setUnit(TimeUnit.SECOND);
+		PrimitiveValueExpression exp = stextFac
+				.createPrimitiveValueExpression();
+		IntLiteral literal = stextFac.createIntLiteral();
+		literal.setValue(42);
+		exp.setValue(literal);
+		timeTrigger.setValue(exp);
+		trigger.getTriggers().add(timeTrigger);
+		assertEquals("after 10\n s , every 42 s [true] / 3 * 3",
+				transition.getSpecification());
+		assertEquals("" + res.getErrors(), 0, res.getErrors().size());
+	}
+
+	@Test
+	public void testStateSerializing() throws Exception {
+		res.setSerializerEnabled(true);
+		State state = createState("entry / 3 * 3");
+		res.getContents().add(state);
+		LocalReaction reaction = (LocalReaction) state.getLocalReactions().get(
+				0);
+		ReactionTrigger trigger = (ReactionTrigger) reaction.getTrigger();
+		ExitEvent exitEvent = stextFac.createExitEvent();
+		trigger.getTriggers().add(exitEvent);
+		assertEquals("entry , exit / 3 * 3", state.getSpecification());
+		assertEquals("" + res.getErrors(), 0, res.getErrors().size());
+	}
+
+	@Test
+	public void testLinkingSuccess() throws Exception {
+		Statechart statechart = createStatechart("internal: event Event1");
+		res.getContents().add(statechart);
+		Transition transition = createTransition("Event1 [true] / 3 * 3");
+		res.getContents().add(transition);
+		res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
+		assertEquals("" + res.getLinkingDiagnostics(), 0, res
+				.getLinkingDiagnostics().size());
+		ReactionTrigger trigger = (ReactionTrigger) transition.getTrigger();
+		RegularEventSpec eventSpec = (RegularEventSpec) trigger.getTriggers()
+				.get(0);
+		ElementReferenceExpression expression = (ElementReferenceExpression) eventSpec
+				.getEvent();
+		EventDefinition reference = (EventDefinition) expression.getReference();
+		assertNotNull(reference);
+		assertEquals("Event1", reference.getName());
+	}
+
+	@Test
+	public void testLinkingError1() throws Exception {
+		Statechart statechart = createStatechart("internal: event Event1");
+		res.getContents().add(statechart);
+		Transition transition = createTransition("Event2 [true] / 3 * 3");
+		res.getContents().add(transition);
+		res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
+		System.out.println(res.getLinkingDiagnostics());
+		assertEquals(1, res.getLinkingDiagnostics().size());
+	}
+
+	@Test
+	public void testLinkingError2() throws Exception {
+		Statechart statechart = createStatechart("internal: event Event1");
+		res.getContents().add(statechart);
+		Transition transition = createTransition("Event1 [true] / 3 * 3");
+		res.getContents().add(transition);
+		statechart.setSpecification("internal: event Event2");
+		res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
+		assertEquals(1, res.getLinkingDiagnostics().size());
+	}
+
+	@Test
+	public void testParsingOnLoad() throws Exception {
+		File tmpFile = File.createTempFile("SCTResource", "test.test");
+		tmpFile.deleteOnExit();
+		URI uri = URI.createFileURI(tmpFile.getPath().toString());
+		Resource resource = new XMIResourceImpl(uri);
+		Statechart statechart = createStatechart("internal: event Event1");
+		resource.getContents().add(statechart);
+		Transition transition = createTransition("Event1 [true] / 3 * 3");
+		resource.getContents().add(transition);
+		resource.save(Collections.EMPTY_MAP);
+
+		res.setURI(uri);
+		res.load(Collections.EMPTY_MAP);
+		statechart = (Statechart) res.getContents().get(0);
+		transition = (Transition) res.getContents().get(1);
+
+		assertEquals("" + res.getErrors(), 0, res.getErrors().size());
+		ReactionTrigger trigger = (ReactionTrigger) transition.getTrigger();
+		RegularEventSpec eventSpec = (RegularEventSpec) trigger.getTriggers()
+				.get(0);
+		ElementReferenceExpression expression = (ElementReferenceExpression) eventSpec
+				.getEvent();
+		EventDefinition reference = (EventDefinition) expression.getReference();
+		assertNotNull(reference);
+		assertEquals("Event1", reference.getName());
+	}
+
+	@Test
+	public void testRemoveOrphanedSyntaxDiagnostics() throws Exception {
+		Statechart statechart = createStatechart("invalid expression");
+		res.getContents().add(statechart);
+		assertEquals(1, res.getSyntaxDiagnostics().size());
+		statechart.setSpecification("internal: event Event1");
+		assertEquals(0, res.getSyntaxDiagnostics().size());
+	}
+
+	@Test
+	public void testRemoveOrphanedLinkingDiagnostics() throws Exception {
+		Statechart statechart = createStatechart("internal: event Event1");
+		res.getContents().add(statechart);
+		Transition transition = createTransition("Event2 [true] / 3 * 3");
+		res.getContents().add(transition);
+		res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
+		assertEquals(1, res.getLinkingDiagnostics().size());
+		transition.setSpecification("Event1 [true] / 3 * 3");
+		res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
+		assertEquals(0, res.getLinkingDiagnostics().size());
+	}
+
+	protected Statechart createStatechart(String exp) {
+		Statechart statechart = SGraphFactory.eINSTANCE.createStatechart();
+		statechart.setSpecification(exp);
+		return statechart;
+	}
+
+	protected Transition createTransition(String exp) {
+		Transition transition = SGraphFactory.eINSTANCE.createTransition();
+		transition.setSpecification(exp);
+		return transition;
+	}
+
+	protected State createState(String exp) {
+		State state = SGraphFactory.eINSTANCE.createState();
+		state.setSpecification(exp);
+		return state;
+	}
+}