Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Dirix2014-11-11 08:54:21 -0500
committerAxel RICHARD2014-11-17 09:21:00 -0500
commit4cb1d5c40ada252f0b2cce4580523291b87dff20 (patch)
tree86ff0d44979d880e4dbce53a96ad391d8d9f0991 /plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests
parent02ca3d53eceec5d3c0abf3d2c6af64ea115e5d61 (diff)
downloadorg.eclipse.emf.compare-4cb1d5c40ada252f0b2cce4580523291b87dff20.tar.gz
org.eclipse.emf.compare-4cb1d5c40ada252f0b2cce4580523291b87dff20.tar.xz
org.eclipse.emf.compare-4cb1d5c40ada252f0b2cce4580523291b87dff20.zip
[450949] Avoid shortcuts in DefaultDiffEngine for certain FeatureMaps
Changes in FeatureMaps should be merged via FeatureMapChanges in the FeatureMapChangeMerger. In cases of added / removed elements the DefaultDiffEngine prevents the calculation of required FeatureMapChanges since they only affect attributes of those elements. This leads to ordering problems since the ReferenceChangeMerger can not handle FeatureMaps properly. This fix removes the calculation prevention for these cases. Includes testcases for this issue. Bug: 450949 Signed-off-by: Stefan Dirix <sdirix@eclipsesource.com> Change-Id: Ie21a54c2e08b27bcc421f1c28d42e542407b990d
Diffstat (limited to 'plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/FeatureMapMoveDiffTest.java90
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/FeatureMapMoveDiffInputData.java27
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/left.nodes13
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/right.nodes13
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java7
5 files changed, 147 insertions, 3 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/FeatureMapMoveDiffTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/FeatureMapMoveDiffTest.java
new file mode 100644
index 000000000..08b428a29
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/FeatureMapMoveDiffTest.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2014 EclipseSource Muenchen GmbH 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:
+ * Stefan Dirix - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.diff;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceKind;
+import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.FeatureMapChange;
+import org.eclipse.emf.compare.ReferenceChange;
+import org.eclipse.emf.compare.scope.DefaultComparisonScope;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.compare.tests.diff.data.FeatureMapMoveDiffInputData;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.junit.Test;
+
+/**
+ * Tests the DiffEngine for its handling of FeatureMap Changes.
+ *
+ * @author Stefan Dirix <sdirix@eclipsesource.com>
+ */
+@SuppressWarnings("nls")
+public class FeatureMapMoveDiffTest {
+
+ private FeatureMapMoveDiffInputData input = new FeatureMapMoveDiffInputData();
+
+ /**
+ * Tests a scenario in which an element is moved from one FeatureMap to another whereby the Nodes
+ * containing the FeatureMaps are also added / removed. For this case the DiffEngine must calculate
+ * additional FeatureMapChanges to keep the order of the elements during merging.
+ *
+ * @throws IOException
+ * if {@link FeatureMapMoveDiffInputData} fails to load the test models.
+ */
+ @Test
+ public void testFeatureMapMoveDiffs() throws IOException {
+ final Resource left = input.getFeatureMapMoveLeft();
+ final Resource right = input.getFeatureMapMoveRight();
+
+ final IComparisonScope scope = new DefaultComparisonScope(right, left, null);
+ Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ // should detect 6 differences when diffengine does not cut off featuremap changes
+ final List<Diff> differences = comparison.getDifferences();
+ assertEquals(6, differences.size());
+
+ // 2 of them should be move reference changes
+ final List<Diff> moveDifferences = new ArrayList<Diff>(2);
+ for (Diff diff : differences) {
+ if (diff instanceof ReferenceChange && diff.getKind() == DifferenceKind.MOVE) {
+ moveDifferences.add(diff);
+ }
+ }
+ assertEquals(2, moveDifferences.size());
+
+ // check if move reference changes are accompanied with featuremap changes
+ for (Diff mdiff : moveDifferences) {
+ // moveDiff itself + featuremap change
+ assertEquals(2, mdiff.getEquivalence().getDifferences().size());
+
+ boolean foundFeatureMapChange = false;
+ for (Diff equivalent : mdiff.getEquivalence().getDifferences()) {
+ if (equivalent != mdiff) {
+ assertTrue(equivalent instanceof FeatureMapChange);
+ foundFeatureMapChange = true;
+ }
+ }
+ if (!foundFeatureMapChange) {
+ fail("ReferenceChange should have FeatureMapChange as equivalent");
+ }
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/FeatureMapMoveDiffInputData.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/FeatureMapMoveDiffInputData.java
new file mode 100644
index 000000000..6f88c9521
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/FeatureMapMoveDiffInputData.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2014 EclipseSource Muenchen GmbH 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:
+ * Stefan Dirix - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.diff.data;
+
+import java.io.IOException;
+
+import org.eclipse.emf.compare.tests.framework.AbstractInputData;
+import org.eclipse.emf.ecore.resource.Resource;
+
+@SuppressWarnings("nls")
+public class FeatureMapMoveDiffInputData extends AbstractInputData {
+ public Resource getFeatureMapMoveLeft() throws IOException {
+ return loadFromClassLoader("featuremapmove/left.nodes");
+ }
+
+ public Resource getFeatureMapMoveRight() throws IOException {
+ return loadFromClassLoader("featuremapmove/right.nodes");
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/left.nodes
new file mode 100644
index 000000000..ec5f2a5ac
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/left.nodes
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nodes:Node
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes"
+ xmi:id="_root"
+ name="Root">
+ <containmentRef1 xsi:type="nodes:NodeFeatureMapContainment2" name="n1">
+ <single name="a"/>
+ <multiple name="b"/>
+ </containmentRef1>
+</nodes:Node> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/right.nodes
new file mode 100644
index 000000000..54602874f
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/data/featuremapmove/right.nodes
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nodes:Node
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes"
+ xmi:id="_root"
+ name="Root">
+ <containmentRef1 xsi:type="nodes:NodeFeatureMapContainment2" name="n2">
+ <multiple name="b"/>
+ <single name="a"/>
+ </containmentRef1>
+</nodes:Node> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
index 2ba7be843..3ffa48368 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
@@ -20,6 +20,7 @@ import org.eclipse.emf.compare.tests.command.CommandStackTestSuite;
import org.eclipse.emf.compare.tests.conflict.ConflictDetectionTest;
import org.eclipse.emf.compare.tests.conflict.MultiLineAttributeConflictDetectionTest;
import org.eclipse.emf.compare.tests.diff.ComparisonUtilTest;
+import org.eclipse.emf.compare.tests.diff.FeatureMapMoveDiffTest;
import org.eclipse.emf.compare.tests.diff.DiffUtilTest;
import org.eclipse.emf.compare.tests.diff.FeatureFilterTest;
import org.eclipse.emf.compare.tests.diff.LCSPerformanceTest;
@@ -69,9 +70,9 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({CompareTestSuite.class, DefaultComparisonScopeTest.class, IdentifierComparisonTest.class,
ExtLibraryTest.class, ConflictDetectionTest.class, ReqComputingTest.class, EquiComputingTest.class,
- DiffUtilTest.class, ComparisonUtilTest.class, LCSPerformanceTest.class, MultipleMergeTest.class,
- PostProcessorTest.class, IndividualMergeTest.class, ExtensionMergeTest.class,
- IndividualMergeOutOfScopeValuesTest.class, ProximityComparisonTest.class,
+ DiffUtilTest.class, FeatureMapMoveDiffTest.class, ComparisonUtilTest.class, LCSPerformanceTest.class,
+ MultipleMergeTest.class, PostProcessorTest.class, IndividualMergeTest.class,
+ ExtensionMergeTest.class, IndividualMergeOutOfScopeValuesTest.class, ProximityComparisonTest.class,
DynamicInstanceComparisonTest.class, URIDistanceTest.class, FragmentationTest.class,
AllEditTests.class, CommandStackTestSuite.class, MatchEngineFactoryRegistryTest.class,
ConflictMergeTest.class, PseudoConflictMergeTest.class, ProximityIndexTest.class, AllRCPTests.class,

Back to the top