Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Cartaud2016-04-25 08:42:37 -0400
committerLaurent Delaigue2016-05-10 02:38:04 -0400
commit118b62be3c4744c47df68aedfb3bc29696c92f78 (patch)
tree85f4ba5db5367fe1e2c115660428397d2fb76f85 /plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare
parentad2007e30c3bb99a07803c666c0326286970ad26 (diff)
downloadorg.eclipse.emf.compare-118b62be3c4744c47df68aedfb3bc29696c92f78.tar.gz
org.eclipse.emf.compare-118b62be3c4744c47df68aedfb3bc29696c92f78.tar.xz
org.eclipse.emf.compare-118b62be3c4744c47df68aedfb3bc29696c92f78.zip
[492261] Merge ResourceAttChange in the right resource
Add test to make sure that diffs linked to a merged RAC are now created in the right resource Bug: 492261 Change-Id: I4de6c63d16add447241c891a22e46c224f819cd3 Signed-off-by: Mathieu Cartaud <mathieu.cartaud@obeo.fr>
Diffstat (limited to 'plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/ResourceAttachmentChangeBug492261.java247
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/FragmentationInputData.java18
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/ancestor/control/origin.nodes7
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/ancestor/uncontrol/fragment.nodes4
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/ancestor/uncontrol/origin.nodes10
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/left/origin.nodes7
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/right/fragment.nodes4
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/right/origin.nodes4
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java3
9 files changed, 303 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/ResourceAttachmentChangeBug492261.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/ResourceAttachmentChangeBug492261.java
new file mode 100644
index 000000000..b3ee01c19
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/ResourceAttachmentChangeBug492261.java
@@ -0,0 +1,247 @@
+/**
+ * Copyright (c) 2016 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.fragmentation;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.common.util.BasicMonitor;
+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.ResourceAttachmentChange;
+import org.eclipse.emf.compare.merge.IMerger;
+import org.eclipse.emf.compare.scope.DefaultComparisonScope;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.compare.tests.fragmentation.data.FragmentationInputData;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.junit.Test;
+
+public class ResourceAttachmentChangeBug492261 {
+
+ private final FragmentationInputData input = new FragmentationInputData();
+
+ private final IMerger.Registry mergerRegistry = IMerger.RegistryImpl.createStandaloneInstance();
+
+ @Test
+ public void testUncontrolRootResourceImplication_1() throws IOException {
+ final Resource left = input.getRootElementImplicationLeft();
+ final Resource origin = input.getRootElementImplicationUncontrolOrigin();
+ final Resource right = input.getRootElementImplicationRight();
+
+ final ResourceSet leftSet = left.getResourceSet();
+ final ResourceSet originSet = origin.getResourceSet();
+ final ResourceSet rightSet = right.getResourceSet();
+
+ assertNotNull(leftSet);
+ assertNotNull(originSet);
+ assertNotNull(rightSet);
+
+ EcoreUtil.resolveAll(leftSet);
+ EcoreUtil.resolveAll(originSet);
+ EcoreUtil.resolveAll(rightSet);
+
+ assertEquals(1, leftSet.getResources().size());
+ assertEquals(2, originSet.getResources().size());
+ assertEquals(2, rightSet.getResources().size());
+
+ mergeUncontrolDiffsAndAssertResult(leftSet, originSet, rightSet, true);
+ }
+
+ @Test
+ public void testUncontrolRootResourceImplication_2() throws IOException {
+ final Resource left = input.getRootElementImplicationRight();
+ final Resource origin = input.getRootElementImplicationUncontrolOrigin();
+ final Resource right = input.getRootElementImplicationLeft();
+
+ final ResourceSet leftSet = left.getResourceSet();
+ final ResourceSet originSet = origin.getResourceSet();
+ final ResourceSet rightSet = right.getResourceSet();
+
+ assertNotNull(leftSet);
+ assertNotNull(originSet);
+ assertNotNull(rightSet);
+
+ EcoreUtil.resolveAll(leftSet);
+ EcoreUtil.resolveAll(originSet);
+ EcoreUtil.resolveAll(rightSet);
+
+ assertEquals(2, leftSet.getResources().size());
+ assertEquals(2, originSet.getResources().size());
+ assertEquals(1, rightSet.getResources().size());
+
+ mergeUncontrolDiffsAndAssertResult(leftSet, originSet, rightSet, false);
+ }
+
+ @Test
+ public void testControlRootResourceImplication_1() throws IOException {
+ final Resource left = input.getRootElementImplicationLeft();
+ final Resource origin = input.getRootElementImplicationControlOrigin();
+ final Resource right = input.getRootElementImplicationRight();
+
+ final ResourceSet leftSet = left.getResourceSet();
+ final ResourceSet originSet = origin.getResourceSet();
+ final ResourceSet rightSet = right.getResourceSet();
+
+ assertNotNull(leftSet);
+ assertNotNull(originSet);
+ assertNotNull(rightSet);
+
+ EcoreUtil.resolveAll(leftSet);
+ EcoreUtil.resolveAll(originSet);
+ EcoreUtil.resolveAll(rightSet);
+
+ assertEquals(1, leftSet.getResources().size());
+ assertEquals(1, originSet.getResources().size());
+ assertEquals(2, rightSet.getResources().size());
+
+ mergeControlDiffsAndAssertResult(leftSet, originSet, rightSet, false);
+ }
+
+ @Test
+ public void testControlRootResourceImplication_2() throws IOException {
+ final Resource left = input.getRootElementImplicationRight();
+ final Resource origin = input.getRootElementImplicationControlOrigin();
+ final Resource right = input.getRootElementImplicationLeft();
+
+ final ResourceSet leftSet = left.getResourceSet();
+ final ResourceSet originSet = origin.getResourceSet();
+ final ResourceSet rightSet = right.getResourceSet();
+
+ assertNotNull(leftSet);
+ assertNotNull(originSet);
+ assertNotNull(rightSet);
+
+ EcoreUtil.resolveAll(leftSet);
+ EcoreUtil.resolveAll(originSet);
+ EcoreUtil.resolveAll(rightSet);
+
+ assertEquals(2, leftSet.getResources().size());
+ assertEquals(1, originSet.getResources().size());
+ assertEquals(1, rightSet.getResources().size());
+
+ mergeControlDiffsAndAssertResult(leftSet, originSet, rightSet, true);
+ }
+
+ private void mergeUncontrolDiffsAndAssertResult(final ResourceSet leftSet, final ResourceSet originSet,
+ final ResourceSet rightSet, boolean fragmentedOnLeft) {
+ final IComparisonScope scope = new DefaultComparisonScope(leftSet, rightSet, originSet);
+ Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ final List<Diff> differences = comparison.getDifferences();
+
+ Collection<Diff> racFilter = Collections2.filter(differences, Predicates
+ .instanceOf(ResourceAttachmentChange.class));
+ Collection<Diff> rcFilter = Collections2.filter(differences, Predicates
+ .instanceOf(ReferenceChange.class));
+ assertEquals(1, racFilter.size());
+ assertEquals(2, rcFilter.size());
+ Diff rac = racFilter.iterator().next();
+ Diff container = null;
+ Diff innerNode = null;
+ for (Diff diff : rcFilter) {
+ if (fragmentedOnLeft && diff.getMatch().getLeft() == null) {
+ innerNode = diff;
+ } else if (!fragmentedOnLeft && diff.getMatch().getRight() == null) {
+ innerNode = diff;
+ } else {
+ container = diff;
+ }
+ }
+
+ assertNotNull(container);
+ assertNotNull(innerNode);
+
+ if (fragmentedOnLeft) {
+ mergerRegistry.getHighestRankingMerger(rac).copyRightToLeft(rac, new BasicMonitor());
+ } else {
+ mergerRegistry.getHighestRankingMerger(rac).copyLeftToRight(rac, new BasicMonitor());
+ }
+ assertEquals(DifferenceState.MERGED, rac.getState());
+ assertEquals(DifferenceState.MERGED, container.getState());
+ assertEquals(DifferenceState.UNRESOLVED, innerNode.getState());
+
+ if (fragmentedOnLeft) {
+ mergerRegistry.getHighestRankingMerger(innerNode).copyRightToLeft(innerNode, new BasicMonitor());
+ } else {
+ mergerRegistry.getHighestRankingMerger(innerNode).copyLeftToRight(innerNode, new BasicMonitor());
+ }
+ assertEquals(DifferenceState.MERGED, rac.getState());
+ assertEquals(DifferenceState.MERGED, container.getState());
+ assertEquals(DifferenceState.MERGED, innerNode.getState());
+
+ comparison = EMFCompare.builder().build().compare(scope);
+ assertEquals(0, comparison.getDifferences().size());
+ }
+
+ private void mergeControlDiffsAndAssertResult(final ResourceSet leftSet, final ResourceSet originSet,
+ final ResourceSet rightSet, boolean fragmentedOnLeft) {
+ final IComparisonScope scope = new DefaultComparisonScope(leftSet, rightSet, originSet);
+ Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ final List<Diff> differences = comparison.getDifferences();
+
+ Collection<Diff> racFilter = Collections2.filter(differences, Predicates
+ .instanceOf(ResourceAttachmentChange.class));
+ Collection<Diff> rcFilter = Collections2.filter(differences, Predicates
+ .instanceOf(ReferenceChange.class));
+ assertEquals(1, racFilter.size());
+ assertEquals(2, rcFilter.size());
+ Diff rac = racFilter.iterator().next();
+ Diff container = null;
+ Diff innerNode = null;
+ for (Diff diff : rcFilter) {
+ if (fragmentedOnLeft && diff.getMatch().getRight() == null) {
+ innerNode = diff;
+ } else if (!fragmentedOnLeft && diff.getMatch().getLeft() == null) {
+ innerNode = diff;
+ } else {
+ container = diff;
+ }
+ }
+
+ assertNotNull(container);
+ assertNotNull(innerNode);
+
+ if (fragmentedOnLeft) {
+ mergerRegistry.getHighestRankingMerger(rac).copyRightToLeft(rac, new BasicMonitor());
+ } else {
+ mergerRegistry.getHighestRankingMerger(rac).copyLeftToRight(rac, new BasicMonitor());
+ }
+ assertEquals(DifferenceState.MERGED, rac.getState());
+ assertEquals(DifferenceState.UNRESOLVED, container.getState());
+ assertEquals(DifferenceState.UNRESOLVED, innerNode.getState());
+
+ if (fragmentedOnLeft) {
+ mergerRegistry.getHighestRankingMerger(container).copyRightToLeft(container, new BasicMonitor());
+ } else {
+ mergerRegistry.getHighestRankingMerger(container).copyLeftToRight(container, new BasicMonitor());
+ }
+ assertEquals(DifferenceState.MERGED, rac.getState());
+ assertEquals(DifferenceState.MERGED, container.getState());
+ assertEquals(DifferenceState.MERGED, innerNode.getState());
+
+ comparison = EMFCompare.builder().build().compare(scope);
+ assertEquals(0, comparison.getDifferences().size());
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/FragmentationInputData.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/FragmentationInputData.java
index 7d2f3eb7d..a32d37334 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/FragmentationInputData.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/FragmentationInputData.java
@@ -78,4 +78,22 @@ public class FragmentationInputData extends AbstractInputData {
public Resource getNewRootRight() throws IOException {
return loadFromClassLoader("newroot/right.nodes", new ResourceSetImpl());
}
+
+ public Resource getRootElementImplicationLeft() throws IOException {
+ return loadFromClassLoader("rootelementimplication/left/origin.nodes", new ResourceSetImpl());
+ }
+
+ public Resource getRootElementImplicationUncontrolOrigin() throws IOException {
+ return loadFromClassLoader("rootelementimplication/ancestor/uncontrol/origin.nodes",
+ new ResourceSetImpl());
+ }
+
+ public Resource getRootElementImplicationControlOrigin() throws IOException {
+ return loadFromClassLoader("rootelementimplication/ancestor/control/origin.nodes",
+ new ResourceSetImpl());
+ }
+
+ public Resource getRootElementImplicationRight() throws IOException {
+ return loadFromClassLoader("rootelementimplication/right/origin.nodes", new ResourceSetImpl());
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/ancestor/control/origin.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/ancestor/control/origin.nodes
new file mode 100644
index 000000000..3c737e8e0
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/ancestor/control/origin.nodes
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nodes:Node
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes"
+ xmi:id="_ORexoLlNEeGmS9ESxeCLvg"
+ name="root"/>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/ancestor/uncontrol/fragment.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/ancestor/uncontrol/fragment.nodes
new file mode 100644
index 000000000..0eba84fee
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/ancestor/uncontrol/fragment.nodes
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nodes:Node xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes" xmi:id="_QE6YYAcQEeKTxJtDIb3mMw" name="fragmented">
+ <containmentRef1 xmi:id="_gUHAUArkEeaHsdquODvaLA" name="innerNode"/>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/ancestor/uncontrol/origin.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/ancestor/uncontrol/origin.nodes
new file mode 100644
index 000000000..7192229e8
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/ancestor/uncontrol/origin.nodes
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nodes:Node
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes"
+ xmi:id="_ORexoLlNEeGmS9ESxeCLvg"
+ name="root">
+ <containmentRef1
+ href="fragment.nodes#_QE6YYAcQEeKTxJtDIb3mMw"/>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/left/origin.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/left/origin.nodes
new file mode 100644
index 000000000..3c737e8e0
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/left/origin.nodes
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nodes:Node
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes"
+ xmi:id="_ORexoLlNEeGmS9ESxeCLvg"
+ name="root"/>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/right/fragment.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/right/fragment.nodes
new file mode 100644
index 000000000..0eba84fee
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/right/fragment.nodes
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nodes:Node xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes" xmi:id="_QE6YYAcQEeKTxJtDIb3mMw" name="fragmented">
+ <containmentRef1 xmi:id="_gUHAUArkEeaHsdquODvaLA" name="innerNode"/>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/right/origin.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/right/origin.nodes
new file mode 100644
index 000000000..b75ab1666
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/data/rootelementimplication/right/origin.nodes
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nodes:Node xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes" xmi:id="_ORexoLlNEeGmS9ESxeCLvg" name="root">
+ <containmentRef1 href="fragment.nodes#_QE6YYAcQEeKTxJtDIb3mMw"/>
+</nodes:Node>
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 11b6cad45..749e98933 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
@@ -32,6 +32,7 @@ import org.eclipse.emf.compare.tests.diff.URIDistanceTest;
import org.eclipse.emf.compare.tests.edit.AllEditTests;
import org.eclipse.emf.compare.tests.equi.EquiComputingTest;
import org.eclipse.emf.compare.tests.fragmentation.FragmentationTest;
+import org.eclipse.emf.compare.tests.fragmentation.ResourceAttachmentChangeBug492261;
import org.eclipse.emf.compare.tests.fullcomparison.DynamicInstanceComparisonTest;
import org.eclipse.emf.compare.tests.fullcomparison.ExtLibraryTest;
import org.eclipse.emf.compare.tests.fullcomparison.IdentifierComparisonTest;
@@ -93,7 +94,7 @@ import org.junit.runners.Suite.SuiteClasses;
MultiLineAttributeConflictDetectionTest.class, ThreeWayTextDiffTest.class,
MultiLineAttributeMergeTest.class, MonitorCancelTest.class, IdentifierEObjectMatcherTest.class,
MatchUtilFeatureContainsTest.class, RefineMergeTest.class, Bug484557ConflictTest.class,
- Bug485266_MoveDeleteConflict_Test.class })
+ Bug485266_MoveDeleteConflict_Test.class, ResourceAttachmentChangeBug492261.class })
public class AllTests {
/**
* Standalone launcher for all of compare's tests.

Back to the top