Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff')
-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
4 files changed, 143 insertions, 0 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

Back to the top