Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbrun2013-01-08 16:12:43 +0000
committercbrun2013-01-08 16:12:43 +0000
commite73eac475750e74f3c348bf6c5ca972eb1f1178e (patch)
treeac182e2054bd49484d15a23848085db1dff8f20d /plugins
parent9914ac93cf20a2082a36c6509fbee0c7c5858ea4 (diff)
downloadorg.eclipse.emf.compare-e73eac475750e74f3c348bf6c5ca972eb1f1178e.tar.gz
org.eclipse.emf.compare-e73eac475750e74f3c348bf6c5ca972eb1f1178e.tar.xz
org.eclipse.emf.compare-e73eac475750e74f3c348bf6c5ca972eb1f1178e.zip
Enable Fuzzy tests for the Nodes ecore model.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/fuzzy/fuzzyConfig.fuzzy5
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/FuzzyTest.java36
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/NodesFuzzyTest.java27
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllPluginTests.java3
4 files changed, 70 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/fuzzy/fuzzyConfig.fuzzy b/plugins/org.eclipse.emf.compare.tests/fuzzy/fuzzyConfig.fuzzy
index 18dfb3443..f8fdfe028 100644
--- a/plugins/org.eclipse.emf.compare.tests/fuzzy/fuzzyConfig.fuzzy
+++ b/plugins/org.eclipse.emf.compare.tests/fuzzy/fuzzyConfig.fuzzy
@@ -5,4 +5,9 @@
<ePackages href="http://www.eclipse.org/emf/2002/Ecore#/"/>
</mutatorConfig>
</org.eclipse.emf.emfstore.fuzzy.emf.config:TestConfig>
+ <org.eclipse.emf.emfstore.fuzzy.emf.config:TestConfig seed="1" count="500" testClass="org.eclipse.emf.compare.tests.NodesFuzzyTest" id="_r78GhIvSEeGC3oFJZ-5HoM">
+ <mutatorConfig minObjectsCount="100">
+ <ePackages href="http://www.eclipse.org/emf/compare/tests/nodes#/"/>
+ </mutatorConfig>
+ </org.eclipse.emf.emfstore.fuzzy.emf.config:TestConfig>
</xmi:XMI>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/FuzzyTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/FuzzyTest.java
index bf932568d..cfd3f0b2f 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/FuzzyTest.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/FuzzyTest.java
@@ -10,6 +10,9 @@
*/
package org.eclipse.emf.compare.tests;
+import static org.junit.Assert.assertSame;
+
+import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import java.util.Iterator;
@@ -18,7 +21,10 @@ import java.util.Set;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.ReferenceChange;
+import org.eclipse.emf.compare.match.eobject.URIDistance;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EcorePackage;
@@ -70,6 +76,7 @@ public class FuzzyTest {
EObject backup = EcoreUtil.copy(root);
util.mutate(createConfig());
+ EObject mutated = EcoreUtil.copy(root);
removeAllDuplicateCrossReferencesFrom(root);
Comparison result = EMFCompare.builder().build().compare(EMFCompare.createDefaultScope(root, backup));
@@ -79,8 +86,37 @@ public class FuzzyTest {
delta.copyRightToLeft();
}
+ for (Diff delta : result.getDifferences()) {
+ assertSame(delta.getState(), DifferenceState.MERGED);
+ }
+
Comparison valid = EMFCompare.builder().build().compare(EMFCompare.createDefaultScope(root, backup));
List<Diff> differences = valid.getDifferences();
+
+ Set<String> urisToDebug = Sets.newLinkedHashSet();
+ for (ReferenceChange diff : Iterables.filter(differences, ReferenceChange.class)) {
+ if (diff.getMatch().getRight() != null) {
+ urisToDebug.add(new URIDistance().apply(diff.getMatch().getRight()).toString());
+ }
+
+ }
+
+ if (urisToDebug.size() > 0) {
+ /*
+ * restart
+ */
+ root = EcoreUtil.copy(mutated);
+ result = EMFCompare.builder().build().compare(EMFCompare.createDefaultScope(root, backup));
+ for (Diff diff : result.getDifferences()) {
+ if (diff.getMatch().getRight() != null) {
+ String uri = new URIDistance().apply(diff.getMatch().getRight()).toString();
+ if (urisToDebug.contains(uri)) {
+ diff.copyRightToLeft();
+ }
+ }
+ }
+ }
+
Assert.assertEquals("We still have differences after merging all of them (had " + nbDiffs
+ " to merge in the beginning)", 0, differences.size());
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/NodesFuzzyTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/NodesFuzzyTest.java
new file mode 100644
index 000000000..2cf29d4b2
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/NodesFuzzyTest.java
@@ -0,0 +1,27 @@
+/**
+ * Copyright (c) 2012 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ */
+package org.eclipse.emf.compare.tests;
+
+import org.eclipse.emf.emfstore.fuzzy.Annotations.DataProvider;
+import org.eclipse.emf.emfstore.fuzzy.FuzzyRunner;
+import org.eclipse.emf.emfstore.fuzzy.emf.EMFDataProvider;
+import org.junit.runner.RunWith;
+
+/**
+ * A brute force test using fuzzy testing. On the Nodes metamodel.
+ *
+ * @author <a href="mailto:cedric.brun@obeo.fr">Cedric Brun</a>
+ */
+@RunWith(FuzzyRunner.class)
+@DataProvider(EMFDataProvider.class)
+public class NodesFuzzyTest extends FuzzyTest {
+
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllPluginTests.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllPluginTests.java
index 4e2cd8b49..33fda6d46 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllPluginTests.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllPluginTests.java
@@ -14,6 +14,7 @@ import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
import org.eclipse.emf.compare.tests.FuzzyTest;
+import org.eclipse.emf.compare.tests.NodesFuzzyTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -26,7 +27,7 @@ import org.junit.runners.Suite.SuiteClasses;
* @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
*/
@RunWith(Suite.class)
-@SuiteClasses({FuzzyTest.class, })
+@SuiteClasses({FuzzyTest.class, NodesFuzzyTest.class })
public class AllPluginTests {
/**
* This will return a suite populated with all tests available through this class.

Back to the top