summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarton Bur2014-07-07 10:48:07 (EDT)
committerZoltan Ujhelyi2014-07-08 10:25:04 (EDT)
commit0a58dfe48f3e40bf682cc3edf9979786ea498de2 (patch)
tree51e4361281efde78433c0153be1af8e4ecdb3e8c
parent382790474bed4253001953d60f058ac471d7a5d5 (diff)
downloadorg.eclipse.incquery.examples-0a58dfe48f3e40bf682cc3edf9979786ea498de2.zip
org.eclipse.incquery.examples-0a58dfe48f3e40bf682cc3edf9979786ea498de2.tar.gz
org.eclipse.incquery.examples-0a58dfe48f3e40bf682cc3edf9979786ea498de2.tar.bz2
[431204] Test cases for flattenerrefs/changes/51/29551/2
The flattener was introduced in Idab73ff775a44c81dcbedc82fd138cafa1e317ee Change-Id: Iaa1652f06088a14533a4073b6f13eebcc529e682 Signed-off-by: Marton Bur <marton.bur@gmail.com>
-rwxr-xr-xpapyrus-uml/org.eclipse.incquery.examples.uml.queries/src/org/eclipse/incquery/examples/uml/queries/EmptyClass.eiq7
-rw-r--r--papyrus-uml/org.eclipse.incquery.examples.uml.tests/.classpath7
-rw-r--r--papyrus-uml/org.eclipse.incquery.examples.uml.tests/.project28
-rw-r--r--papyrus-uml/org.eclipse.incquery.examples.uml.tests/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--papyrus-uml/org.eclipse.incquery.examples.uml.tests/META-INF/MANIFEST.MF11
-rw-r--r--papyrus-uml/org.eclipse.incquery.examples.uml.tests/build.properties4
-rw-r--r--papyrus-uml/org.eclipse.incquery.examples.uml.tests/src/org/eclipse/incquery/examples/uml/tests/FlattenerTest.java121
7 files changed, 185 insertions, 0 deletions
diff --git a/papyrus-uml/org.eclipse.incquery.examples.uml.queries/src/org/eclipse/incquery/examples/uml/queries/EmptyClass.eiq b/papyrus-uml/org.eclipse.incquery.examples.uml.queries/src/org/eclipse/incquery/examples/uml/queries/EmptyClass.eiq
index 00fad3d..82d6933 100755
--- a/papyrus-uml/org.eclipse.incquery.examples.uml.queries/src/org/eclipse/incquery/examples/uml/queries/EmptyClass.eiq
+++ b/papyrus-uml/org.eclipse.incquery.examples.uml.queries/src/org/eclipse/incquery/examples/uml/queries/EmptyClass.eiq
@@ -56,4 +56,11 @@ pattern emptyClass(cl : Class) {
@Item(item = cl, label = "Class $cl$")
pattern nonEmptyClass(cl : Class) {
neg find emptyClass(cl);
+}
+
+// flattener test queries
+pattern hasPropertyOrOperation(cl) {
+ find hasOperation(cl,_);
+} or {
+ find hasProperty(cl,_);
} \ No newline at end of file
diff --git a/papyrus-uml/org.eclipse.incquery.examples.uml.tests/.classpath b/papyrus-uml/org.eclipse.incquery.examples.uml.tests/.classpath
new file mode 100644
index 0000000..ad32c83
--- /dev/null
+++ b/papyrus-uml/org.eclipse.incquery.examples.uml.tests/.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.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/papyrus-uml/org.eclipse.incquery.examples.uml.tests/.project b/papyrus-uml/org.eclipse.incquery.examples.uml.tests/.project
new file mode 100644
index 0000000..37a29a9
--- /dev/null
+++ b/papyrus-uml/org.eclipse.incquery.examples.uml.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.incquery.examples.uml.tests</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>
diff --git a/papyrus-uml/org.eclipse.incquery.examples.uml.tests/.settings/org.eclipse.jdt.core.prefs b/papyrus-uml/org.eclipse.incquery.examples.uml.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..c537b63
--- /dev/null
+++ b/papyrus-uml/org.eclipse.incquery.examples.uml.tests/.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.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/papyrus-uml/org.eclipse.incquery.examples.uml.tests/META-INF/MANIFEST.MF b/papyrus-uml/org.eclipse.incquery.examples.uml.tests/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..4fbd916
--- /dev/null
+++ b/papyrus-uml/org.eclipse.incquery.examples.uml.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,11 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Tests
+Bundle-SymbolicName: org.eclipse.incquery.examples.uml.tests
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.junit,
+ org.eclipse.emf;bundle-version="2.6.0",
+ org.eclipse.incquery.runtime;bundle-version="0.9.0",
+ org.eclipse.incquery.examples.uml.queries;bundle-version="0.0.1",
+ org.eclipse.incquery.testing.core
diff --git a/papyrus-uml/org.eclipse.incquery.examples.uml.tests/build.properties b/papyrus-uml/org.eclipse.incquery.examples.uml.tests/build.properties
new file mode 100644
index 0000000..34d2e4d
--- /dev/null
+++ b/papyrus-uml/org.eclipse.incquery.examples.uml.tests/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/papyrus-uml/org.eclipse.incquery.examples.uml.tests/src/org/eclipse/incquery/examples/uml/tests/FlattenerTest.java b/papyrus-uml/org.eclipse.incquery.examples.uml.tests/src/org/eclipse/incquery/examples/uml/tests/FlattenerTest.java
new file mode 100644
index 0000000..155dfac
--- /dev/null
+++ b/papyrus-uml/org.eclipse.incquery.examples.uml.tests/src/org/eclipse/incquery/examples/uml/tests/FlattenerTest.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2014, Marton Bur, Akos Horvath, Zoltan Ujhelyi, Istvan Rath and Daniel Varro
+ * 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:
+ * Marton Bur - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.incquery.examples.uml.tests;
+
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.URI;
+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.incquery.examples.uml.queries.util.EmptyClassQuerySpecification;
+import org.eclipse.incquery.examples.uml.queries.util.HasPropertyOrOperationQuerySpecification;
+import org.eclipse.incquery.examples.uml.queries.util.HasPropertyQuerySpecification;
+import org.eclipse.incquery.runtime.api.IQuerySpecification;
+import org.eclipse.incquery.runtime.api.IncQueryEngine;
+import org.eclipse.incquery.runtime.exception.IncQueryException;
+import org.eclipse.incquery.runtime.matchers.psystem.PBody;
+import org.eclipse.incquery.runtime.matchers.psystem.PConstraint;
+import org.eclipse.incquery.runtime.matchers.psystem.PVariable;
+import org.eclipse.incquery.runtime.matchers.psystem.queries.PDisjunction;
+import org.eclipse.incquery.runtime.matchers.psystem.queries.PQuery;
+import org.eclipse.incquery.runtime.matchers.psystem.rewriters.PQueryFlattener;
+import org.eclipse.incquery.testing.core.base.CompareQueryTester;
+import org.eclipse.incquery.testing.core.base.DisjunctionBasedQuerySpecification;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class FlattenerTest {
+
+ @Parameters
+ public static Collection<Object[]> querySpecifications() throws IncQueryException {
+ return Arrays.asList(new Object[][] {
+ { HasPropertyOrOperationQuerySpecification.instance() },
+ { HasPropertyQuerySpecification.instance() },
+ { EmptyClassQuerySpecification.instance() }
+ });
+ }
+
+ @Parameter
+ public IQuerySpecification<?> querySpecification;
+
+ @Test
+ public void compareMatches() throws Exception{
+ // Load the UML model
+ ResourceSet rs = new ResourceSetImpl();
+ // TODO eliminate URI
+ Resource model = rs.getResource(URI.createPlatformPluginURI("org.eclipse.incquery.examples.uml.evm/testmodels/Testmodel.uml", false), true);
+ // Create an engine
+ IncQueryEngine engine = IncQueryEngine.on(model);
+
+ // Do the flattening
+ PDisjunction flatDisjunction = flatten(querySpecification);
+ // Create a new query specification with the flattened body
+ IQuerySpecification<?> flattenedQuerySpecification = new DisjunctionBasedQuerySpecification(querySpecification, flatDisjunction);
+
+ CompareQueryTester.assertQueriesEquivalent(engine, querySpecification, flattenedQuerySpecification);
+ }
+
+ /**
+ * Helper method to print the result of a flattening - no matching is done
+ *
+ * @throws Exception
+ */
+ public void printFlattenedDisjunction() throws Exception {
+ IQuerySpecification<?> query = querySpecification;
+ PDisjunction flattenedDisjunction = flatten(query);
+ printDisjunction(flattenedDisjunction);
+ }
+
+ private PDisjunction flatten(PQuery query) throws Exception {
+ PQueryFlattener flattener = new PQueryFlattener();
+ PDisjunction flattenedDisjunction = flattener.flatten(query);
+ return flattenedDisjunction;
+ }
+
+ private void printDisjunction(PDisjunction flattenedDisjunction) {
+ Set<PBody> bodies = flattenedDisjunction.getBodies();
+ int i = 0;
+
+ System.out.println("Variables");
+ for (PBody pBody : bodies) {
+ System.out.println("Body " + (i++));
+
+ Set<PVariable> variables = pBody.getAllVariables();
+ for (PVariable pVariable : variables) {
+ System.out.println(pVariable.toString());
+ }
+ }
+
+ System.out.println("Constarints");
+ i = 0;
+ for (PBody pBody : bodies) {
+ System.out.println("Body " + (i++));
+
+ Set<PConstraint> constraints = pBody.getConstraints();
+ for (PConstraint pConstraint : constraints) {
+ System.out.println(pConstraint.toString());
+ }
+ }
+
+ System.out.println("Exported Parameters:");
+ for (PBody pBody : bodies) {
+ System.out.println(pBody.getSymbolicParameters());
+ }
+ }
+}