diff options
author | Axel Richard | 2014-05-21 09:26:26 +0000 |
---|---|---|
committer | Axel Richard | 2014-05-23 09:52:22 +0000 |
commit | 01962bfa99975d1ea70c2e08d629a63caca7da50 (patch) | |
tree | f0d439edc6a69e9e3186566c655f7c8fc97cc3cc /plugins/org.eclipse.emf.compare.tests/src | |
parent | 919590ee3a62b7f8e07efc5609c70ca505ea6846 (diff) | |
download | org.eclipse.emf.compare-01962bfa99975d1ea70c2e08d629a63caca7da50.tar.gz org.eclipse.emf.compare-01962bfa99975d1ea70c2e08d629a63caca7da50.tar.xz org.eclipse.emf.compare-01962bfa99975d1ea70c2e08d629a63caca7da50.zip |
[435053] Add Pseudo conflicts tests.
In case of a pseudo conflict, no merge action is performed, even in
ACCEPT/REJECT mode.
Add tests for pseudo conflicts.
Bug: 435053
Change-Id: I450c6676633502bb001829c889336023ee0d1cc1
Diffstat (limited to 'plugins/org.eclipse.emf.compare.tests/src')
15 files changed, 778 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/PseudoConflictMergeTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/PseudoConflictMergeTest.java new file mode 100644 index 000000000..10109fc66 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/PseudoConflictMergeTest.java @@ -0,0 +1,557 @@ +/******************************************************************************* + * Copyright (c) 2014 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.merge; + +import static com.google.common.base.Predicates.and; +import static com.google.common.base.Predicates.not; +import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide; +import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasConflict; +import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import com.google.common.collect.Iterators; + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.emf.common.util.BasicMonitor; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.compare.Comparison; +import org.eclipse.emf.compare.ConflictKind; +import org.eclipse.emf.compare.Diff; +import org.eclipse.emf.compare.DifferenceKind; +import org.eclipse.emf.compare.DifferenceSource; +import org.eclipse.emf.compare.EMFCompare; +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.merge.data.IndividualDiffInputData; +import org.eclipse.emf.compare.tests.nodes.Node; +import org.eclipse.emf.compare.tests.nodes.NodeSingleValueAttribute; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.junit.Test; + +@SuppressWarnings("nls") +public class PseudoConflictMergeTest { + + private IndividualDiffInputData input = new IndividualDiffInputData(); + + private final IMerger.Registry mergerRegistry = IMerger.RegistryImpl.createStandaloneInstance(); + + @Test + public void testPseudoAdd_LtR_1() throws IOException { + // Pseudo Conflict between Node A[containmentRef1 add] from left side and Node A[containmentRef1 add] + // from right side + + final Resource left = input.getLeftPseudoConflictAddScope(); + final Resource right = input.getRightPseudoConflictAddScope(); + final Resource origin = input.getOriginPseudoConflictAddScope(); + + final IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + Comparison comparison = EMFCompare.builder().build().compare(scope); + + List<Diff> differences = comparison.getDifferences(); + assertSame(Integer.valueOf(2), Integer.valueOf(differences.size())); + + final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.LEFT), + ofKind(DifferenceKind.ADD))); + + // Merge -> Node A[containmentRef1 add] from left to right : <- Node A[containmentRef1 add] will be + // merge from left to right too. + mergerRegistry.getHighestRankingMerger(diff).copyLeftToRight(diff, new BasicMonitor()); + + final String featureName = "containmentRef1"; + final EObject leftNodeRoot = getNodeNamed(left, "root"); + assertNotNull(leftNodeRoot); + final EObject rightNodeRoot = getNodeNamed(right, "root"); + assertNotNull(rightNodeRoot); + final EObject leftNodeA = getNodeNamed(left, "A"); + assertNotNull(leftNodeA); + final EObject rightNodeA = getNodeNamed(right, "A"); + assertNotNull(rightNodeA); + final EStructuralFeature feature = rightNodeRoot.eClass().getEStructuralFeature(featureName); + assertNotNull(feature); + final EList<Node> containmentRef1 = ((Node)rightNodeRoot).getContainmentRef1(); + assertFalse(containmentRef1.isEmpty()); + + Iterators.any(differences.iterator(), not(hasConflict(ConflictKind.PSEUDO))); + + } + + @Test + public void testPseudoAdd_LtR_2() throws IOException { + // Pseudo Conflict between Node A[containmentRef1 add] from left side and Node A[containmentRef1 add] + // from right side + + final Resource left = input.getLeftPseudoConflictAddScope(); + final Resource right = input.getRightPseudoConflictAddScope(); + final Resource origin = input.getOriginPseudoConflictAddScope(); + + final IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + Comparison comparison = EMFCompare.builder().build().compare(scope); + + List<Diff> differences = comparison.getDifferences(); + assertSame(Integer.valueOf(2), Integer.valueOf(differences.size())); + + final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.RIGHT), + ofKind(DifferenceKind.ADD))); + + // Merge <- Node A[containmentRef1 add] from left to right : -> Node A[containmentRef1 add] will be + // merge from left to right too. + mergerRegistry.getHighestRankingMerger(diff).copyLeftToRight(diff, new BasicMonitor()); + + final String featureName = "containmentRef1"; + final EObject leftNodeRoot = getNodeNamed(left, "root"); + assertNotNull(leftNodeRoot); + final EObject rightNodeRoot = getNodeNamed(right, "root"); + assertNotNull(rightNodeRoot); + final EObject leftNodeA = getNodeNamed(left, "A"); + assertNotNull(leftNodeA); + final EObject rightNodeA = getNodeNamed(right, "A"); + assertNotNull(rightNodeA); + final EStructuralFeature feature = rightNodeRoot.eClass().getEStructuralFeature(featureName); + assertNotNull(feature); + final EList<Node> containmentRef1 = ((Node)rightNodeRoot).getContainmentRef1(); + assertFalse(containmentRef1.isEmpty()); + + Iterators.any(differences.iterator(), not(hasConflict(ConflictKind.PSEUDO))); + + } + + @Test + public void testPseudoAdd_RtL_1() throws IOException { + // Pseudo Conflict between Node A[containmentRef1 add] from left side and Node A[containmentRef1 add] + // from right side + + final Resource left = input.getLeftPseudoConflictAddScope(); + final Resource right = input.getRightPseudoConflictAddScope(); + final Resource origin = input.getOriginPseudoConflictAddScope(); + + final IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + Comparison comparison = EMFCompare.builder().build().compare(scope); + + List<Diff> differences = comparison.getDifferences(); + assertSame(Integer.valueOf(2), Integer.valueOf(differences.size())); + + final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.LEFT), + ofKind(DifferenceKind.ADD))); + + // Merge -> Node A[containmentRef1 add] from right to left : <- Node A[containmentRef1 add] will be + // merge from right to left too. + mergerRegistry.getHighestRankingMerger(diff).copyRightToLeft(diff, new BasicMonitor()); + + final String featureName = "containmentRef1"; + final EObject leftNodeRoot = getNodeNamed(left, "root"); + assertNotNull(leftNodeRoot); + final EObject rightNodeRoot = getNodeNamed(right, "root"); + assertNotNull(rightNodeRoot); + final EObject leftNodeA = getNodeNamed(left, "A"); + assertNotNull(leftNodeA); + final EObject rightNodeA = getNodeNamed(right, "A"); + assertNotNull(rightNodeA); + final EStructuralFeature feature = leftNodeRoot.eClass().getEStructuralFeature(featureName); + assertNotNull(feature); + final EList<Node> containmentRef1 = ((Node)leftNodeRoot).getContainmentRef1(); + assertFalse(containmentRef1.isEmpty()); + + Iterators.any(differences.iterator(), not(hasConflict(ConflictKind.PSEUDO))); + + } + + @Test + public void testPseudoAdd_RtL_2() throws IOException { + // Pseudo Conflict between Node A[containmentRef1 add] from left side and Node A[containmentRef1 add] + // from right side + + final Resource left = input.getLeftPseudoConflictAddScope(); + final Resource right = input.getRightPseudoConflictAddScope(); + final Resource origin = input.getOriginPseudoConflictAddScope(); + + final IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + Comparison comparison = EMFCompare.builder().build().compare(scope); + + List<Diff> differences = comparison.getDifferences(); + assertSame(Integer.valueOf(2), Integer.valueOf(differences.size())); + + final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.RIGHT), + ofKind(DifferenceKind.ADD))); + + // Merge <- Node A[containmentRef1 add] from right to left : -> Node A[containmentRef1 add] will be + // merge from right to left too. + mergerRegistry.getHighestRankingMerger(diff).copyRightToLeft(diff, new BasicMonitor()); + + final String featureName = "containmentRef1"; + final EObject leftNodeRoot = getNodeNamed(left, "root"); + assertNotNull(leftNodeRoot); + final EObject rightNodeRoot = getNodeNamed(right, "root"); + assertNotNull(rightNodeRoot); + final EObject leftNodeA = getNodeNamed(left, "A"); + assertNotNull(leftNodeA); + final EObject rightNodeA = getNodeNamed(right, "A"); + assertNotNull(rightNodeA); + final EStructuralFeature feature = leftNodeRoot.eClass().getEStructuralFeature(featureName); + assertNotNull(feature); + final EList<Node> containmentRef1 = ((Node)leftNodeRoot).getContainmentRef1(); + assertFalse(containmentRef1.isEmpty()); + + Iterators.any(differences.iterator(), not(hasConflict(ConflictKind.PSEUDO))); + + } + + @Test + public void testPseudoDelete_LtR_1() throws IOException { + // Pseudo Conflict between Node B[containmentRef1 delete] from left side and Node B[containmentRef1 + // delete] from right side + + final Resource left = input.getLeftPseudoConflictDeleteScope(); + final Resource right = input.getRightPseudoConflictDeleteScope(); + final Resource origin = input.getOriginPseudoConflictDeleteScope(); + + final IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + Comparison comparison = EMFCompare.builder().build().compare(scope); + + List<Diff> differences = comparison.getDifferences(); + assertSame(Integer.valueOf(2), Integer.valueOf(differences.size())); + + final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.LEFT), + ofKind(DifferenceKind.DELETE))); + + // Merge -> Node B[containmentRef1 delete] from left to right : <- Node B[containmentRef1 delete] will + // be merge from left to right too. + mergerRegistry.getHighestRankingMerger(diff).copyLeftToRight(diff, new BasicMonitor()); + + final String featureName = "containmentRef1"; + final EObject leftNodeRoot = getNodeNamed(left, "root"); + assertNotNull(leftNodeRoot); + final EObject rightNodeRoot = getNodeNamed(right, "root"); + assertNotNull(rightNodeRoot); + final EObject leftNodeB = getNodeNamed(left, "B"); + assertNull(leftNodeB); + final EObject rightNodeB = getNodeNamed(right, "B"); + assertNull(rightNodeB); + final EStructuralFeature feature = rightNodeRoot.eClass().getEStructuralFeature(featureName); + assertNotNull(feature); + final EList<Node> containmentRef1 = ((Node)rightNodeRoot).getContainmentRef1(); + assertTrue(containmentRef1.isEmpty()); + + Iterators.any(differences.iterator(), not(hasConflict(ConflictKind.PSEUDO))); + + } + + @Test + public void testPseudoDelete_LtR_2() throws IOException { + // Pseudo Conflict between Node B[containmentRef1 delete] from left side and Node B[containmentRef1 + // delete] from right side + + final Resource left = input.getLeftPseudoConflictDeleteScope(); + final Resource right = input.getRightPseudoConflictDeleteScope(); + final Resource origin = input.getOriginPseudoConflictDeleteScope(); + + final IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + Comparison comparison = EMFCompare.builder().build().compare(scope); + + List<Diff> differences = comparison.getDifferences(); + assertSame(Integer.valueOf(2), Integer.valueOf(differences.size())); + + final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.RIGHT), + ofKind(DifferenceKind.DELETE))); + + // Merge <- Node B[containmentRef1 delete] from left to right : -> Node B[containmentRef1 delete] will + // be merge from left to right too. + mergerRegistry.getHighestRankingMerger(diff).copyLeftToRight(diff, new BasicMonitor()); + + final String featureName = "containmentRef1"; + final EObject leftNodeRoot = getNodeNamed(left, "root"); + assertNotNull(leftNodeRoot); + final EObject rightNodeRoot = getNodeNamed(right, "root"); + assertNotNull(rightNodeRoot); + final EObject leftNodeB = getNodeNamed(left, "B"); + assertNull(leftNodeB); + final EObject rightNodeB = getNodeNamed(right, "B"); + assertNull(rightNodeB); + final EStructuralFeature feature = rightNodeRoot.eClass().getEStructuralFeature(featureName); + assertNotNull(feature); + final EList<Node> containmentRef1 = ((Node)rightNodeRoot).getContainmentRef1(); + assertTrue(containmentRef1.isEmpty()); + + Iterators.any(differences.iterator(), not(hasConflict(ConflictKind.PSEUDO))); + + } + + @Test + public void testPseudoDelete_RtL_1() throws IOException { + // Pseudo Conflict between Node B[containmentRef1 delete] from left side and Node B[containmentRef1 + // delete] from right side + + final Resource left = input.getLeftPseudoConflictDeleteScope(); + final Resource right = input.getRightPseudoConflictDeleteScope(); + final Resource origin = input.getOriginPseudoConflictDeleteScope(); + + final IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + Comparison comparison = EMFCompare.builder().build().compare(scope); + + List<Diff> differences = comparison.getDifferences(); + assertSame(Integer.valueOf(2), Integer.valueOf(differences.size())); + + final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.LEFT), + ofKind(DifferenceKind.DELETE))); + + // Merge -> Node B[containmentRef1 delete] from right to left : <- Node B[containmentRef1 delete] will + // be merge from right to left too. + mergerRegistry.getHighestRankingMerger(diff).copyRightToLeft(diff, new BasicMonitor()); + + final String featureName = "containmentRef1"; + final EObject leftNodeRoot = getNodeNamed(left, "root"); + assertNotNull(leftNodeRoot); + final EObject rightNodeRoot = getNodeNamed(right, "root"); + assertNotNull(rightNodeRoot); + final EObject leftNodeB = getNodeNamed(left, "B"); + assertNull(leftNodeB); + final EObject rightNodeB = getNodeNamed(right, "B"); + assertNull(rightNodeB); + final EStructuralFeature feature = leftNodeRoot.eClass().getEStructuralFeature(featureName); + assertNotNull(feature); + final EList<Node> containmentRef1 = ((Node)leftNodeRoot).getContainmentRef1(); + assertTrue(containmentRef1.isEmpty()); + + Iterators.any(differences.iterator(), not(hasConflict(ConflictKind.PSEUDO))); + + } + + @Test + public void testPseudoDelete_RtL_2() throws IOException { + // Pseudo Conflict between Node B[containmentRef1 delete] from left side and Node B[containmentRef1 + // delete] from right side + + final Resource left = input.getLeftPseudoConflictDeleteScope(); + final Resource right = input.getRightPseudoConflictDeleteScope(); + final Resource origin = input.getOriginPseudoConflictDeleteScope(); + + final IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + Comparison comparison = EMFCompare.builder().build().compare(scope); + + List<Diff> differences = comparison.getDifferences(); + assertSame(Integer.valueOf(2), Integer.valueOf(differences.size())); + + final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.RIGHT), + ofKind(DifferenceKind.DELETE))); + + // Merge <- Node B[containmentRef1 delete] from right to left : -> Node B[containmentRef1 delete] will + // be merge from right to left too. + mergerRegistry.getHighestRankingMerger(diff).copyRightToLeft(diff, new BasicMonitor()); + + final String featureName = "containmentRef1"; + final EObject leftNodeRoot = getNodeNamed(left, "root"); + assertNotNull(leftNodeRoot); + final EObject rightNodeRoot = getNodeNamed(right, "root"); + assertNotNull(rightNodeRoot); + final EObject leftNodeB = getNodeNamed(left, "B"); + assertNull(leftNodeB); + final EObject rightNodeB = getNodeNamed(right, "B"); + assertNull(rightNodeB); + final EStructuralFeature feature = leftNodeRoot.eClass().getEStructuralFeature(featureName); + assertNotNull(feature); + final EList<Node> containmentRef1 = ((Node)leftNodeRoot).getContainmentRef1(); + assertTrue(containmentRef1.isEmpty()); + + Iterators.any(differences.iterator(), not(hasConflict(ConflictKind.PSEUDO))); + + } + + @Test + public void testPseudoChange_LtR_1() throws IOException { + // Pseudo Conflict between Hello[singleValuedAttribute changed] from left side and + // Hello[singleValuedAttribute changed] from right side + + final Resource left = input.getLeftPseudoConflictChangeScope(); + final Resource right = input.getRightPseudoConflictChangeScope(); + final Resource origin = input.getOriginPseudoConflictChangeScope(); + + final IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + Comparison comparison = EMFCompare.builder().build().compare(scope); + + List<Diff> differences = comparison.getDifferences(); + assertSame(Integer.valueOf(2), Integer.valueOf(differences.size())); + + final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.LEFT), + ofKind(DifferenceKind.CHANGE))); + + // Merge -> Hello[singleValuedAttribute changed] from left to right : <- Hello[singleValuedAttribute + // changed] will be merge from left to right too. + mergerRegistry.getHighestRankingMerger(diff).copyLeftToRight(diff, new BasicMonitor()); + + final String featureName = "singleValuedAttribute"; + final EObject leftNodeD = getNodeNamed(left, "D"); + assertNotNull(leftNodeD); + final EObject rightNodeD = getNodeNamed(right, "D"); + assertNotNull(rightNodeD); + final EStructuralFeature featureRight = rightNodeD.eClass().getEStructuralFeature(featureName); + assertNotNull(featureRight); + final EStructuralFeature featureLeft = leftNodeD.eClass().getEStructuralFeature(featureName); + assertNotNull(featureLeft); + final String singleValuedAttributeRight = ((NodeSingleValueAttribute)rightNodeD) + .getSingleValuedAttribute(); + assertEquals("GoodBye", singleValuedAttributeRight); + final String singleValuedAttributeLeft = ((NodeSingleValueAttribute)leftNodeD) + .getSingleValuedAttribute(); + assertEquals("GoodBye", singleValuedAttributeLeft); + + Iterators.any(differences.iterator(), not(hasConflict(ConflictKind.PSEUDO))); + + } + + @Test + public void testPseudoChange_LtR_2() throws IOException { + // Pseudo Conflict between Hello[singleValuedAttribute changed] from left side and + // Hello[singleValuedAttribute changed] from right side + + final Resource left = input.getLeftPseudoConflictChangeScope(); + final Resource right = input.getRightPseudoConflictChangeScope(); + final Resource origin = input.getOriginPseudoConflictChangeScope(); + + final IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + Comparison comparison = EMFCompare.builder().build().compare(scope); + + List<Diff> differences = comparison.getDifferences(); + assertSame(Integer.valueOf(2), Integer.valueOf(differences.size())); + + final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.RIGHT), + ofKind(DifferenceKind.CHANGE))); + + // Merge <- Hello[singleValuedAttribute changed] from left to right : -> Hello[singleValuedAttribute + // changed] will be merge from left to right too. + mergerRegistry.getHighestRankingMerger(diff).copyLeftToRight(diff, new BasicMonitor()); + + final String featureName = "singleValuedAttribute"; + final EObject leftNodeD = getNodeNamed(left, "D"); + assertNotNull(leftNodeD); + final EObject rightNodeD = getNodeNamed(right, "D"); + assertNotNull(rightNodeD); + final EStructuralFeature featureRight = rightNodeD.eClass().getEStructuralFeature(featureName); + assertNotNull(featureRight); + final EStructuralFeature featureLeft = leftNodeD.eClass().getEStructuralFeature(featureName); + assertNotNull(featureLeft); + final String singleValuedAttributeRight = ((NodeSingleValueAttribute)rightNodeD) + .getSingleValuedAttribute(); + assertEquals("GoodBye", singleValuedAttributeRight); + final String singleValuedAttributeLeft = ((NodeSingleValueAttribute)leftNodeD) + .getSingleValuedAttribute(); + assertEquals("GoodBye", singleValuedAttributeLeft); + + Iterators.any(differences.iterator(), not(hasConflict(ConflictKind.PSEUDO))); + + } + + @Test + public void testPseudoChange_RtL_1() throws IOException { + // Pseudo Conflict between Hello[singleValuedAttribute changed] from left side and + // Hello[singleValuedAttribute changed] from right side + + final Resource left = input.getLeftPseudoConflictChangeScope(); + final Resource right = input.getRightPseudoConflictChangeScope(); + final Resource origin = input.getOriginPseudoConflictChangeScope(); + + final IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + Comparison comparison = EMFCompare.builder().build().compare(scope); + + List<Diff> differences = comparison.getDifferences(); + assertSame(Integer.valueOf(2), Integer.valueOf(differences.size())); + + final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.LEFT), + ofKind(DifferenceKind.CHANGE))); + + // Merge -> Hello[singleValuedAttribute changed] from right to left : <- Hello[singleValuedAttribute + // changed] will be merge from right to left too. + mergerRegistry.getHighestRankingMerger(diff).copyRightToLeft(diff, new BasicMonitor()); + + final String featureName = "singleValuedAttribute"; + final EObject leftNodeD = getNodeNamed(left, "D"); + assertNotNull(leftNodeD); + final EObject rightNodeD = getNodeNamed(right, "D"); + assertNotNull(rightNodeD); + final EStructuralFeature featureRight = rightNodeD.eClass().getEStructuralFeature(featureName); + assertNotNull(featureRight); + final EStructuralFeature featureLeft = leftNodeD.eClass().getEStructuralFeature(featureName); + assertNotNull(featureLeft); + final String singleValuedAttributeRight = ((NodeSingleValueAttribute)rightNodeD) + .getSingleValuedAttribute(); + assertEquals("GoodBye", singleValuedAttributeRight); + final String singleValuedAttributeLeft = ((NodeSingleValueAttribute)leftNodeD) + .getSingleValuedAttribute(); + assertEquals("GoodBye", singleValuedAttributeLeft); + + Iterators.any(differences.iterator(), not(hasConflict(ConflictKind.PSEUDO))); + + } + + @Test + public void testPseudoChange_RtL_2() throws IOException { + // Pseudo Conflict between Hello[singleValuedAttribute changed] from left side and + // Hello[singleValuedAttribute changed] from right side + + final Resource left = input.getLeftPseudoConflictChangeScope(); + final Resource right = input.getRightPseudoConflictChangeScope(); + final Resource origin = input.getOriginPseudoConflictChangeScope(); + + final IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + Comparison comparison = EMFCompare.builder().build().compare(scope); + + List<Diff> differences = comparison.getDifferences(); + assertSame(Integer.valueOf(2), Integer.valueOf(differences.size())); + + final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.RIGHT), + ofKind(DifferenceKind.CHANGE))); + + // Merge -> Hello[singleValuedAttribute changed] from right to left : <- Hello[singleValuedAttribute + // changed] will be merge from right to left too. + mergerRegistry.getHighestRankingMerger(diff).copyRightToLeft(diff, new BasicMonitor()); + + final String featureName = "singleValuedAttribute"; + final EObject leftNodeD = getNodeNamed(left, "D"); + assertNotNull(leftNodeD); + final EObject rightNodeD = getNodeNamed(right, "D"); + assertNotNull(rightNodeD); + final EStructuralFeature featureRight = rightNodeD.eClass().getEStructuralFeature(featureName); + assertNotNull(featureRight); + final EStructuralFeature featureLeft = leftNodeD.eClass().getEStructuralFeature(featureName); + assertNotNull(featureLeft); + final String singleValuedAttributeRight = ((NodeSingleValueAttribute)rightNodeD) + .getSingleValuedAttribute(); + assertEquals("GoodBye", singleValuedAttributeRight); + final String singleValuedAttributeLeft = ((NodeSingleValueAttribute)leftNodeD) + .getSingleValuedAttribute(); + assertEquals("GoodBye", singleValuedAttributeLeft); + + Iterators.any(differences.iterator(), not(hasConflict(ConflictKind.PSEUDO))); + + } + + private EObject getNodeNamed(Resource res, String name) { + final Iterator<EObject> iterator = EcoreUtil.getAllProperContents(res, false); + while (iterator.hasNext()) { + final EObject next = iterator.next(); + final EStructuralFeature nameFeature = next.eClass().getEStructuralFeature("name"); + if (nameFeature != null && name.equals(next.eGet(nameFeature))) { + return next; + } + } + return null; + } +} diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/IndividualDiffInputData.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/IndividualDiffInputData.java index 01b9697d8..61d01ed32 100644 --- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/IndividualDiffInputData.java +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/IndividualDiffInputData.java @@ -341,4 +341,52 @@ public class IndividualDiffInputData extends AbstractInputData { public Resource getLeftMoveRightDeleteRightConflictScope() throws IOException { return loadFromClassLoader("conflictscope/leftmove_rightdelete/right.ecore"); } + + public Resource getLeftPseudoConflictAddScope() throws IOException { + return loadFromClassLoader("pseudoconflictscope/add/left.nodes"); + } + + public Resource getOriginPseudoConflictAddScope() throws IOException { + return loadFromClassLoader("pseudoconflictscope/add/ancestor.nodes"); + } + + public Resource getRightPseudoConflictAddScope() throws IOException { + return loadFromClassLoader("pseudoconflictscope/add/right.nodes"); + } + + public Resource getLeftPseudoConflictChangeScope() throws IOException { + return loadFromClassLoader("pseudoconflictscope/change/left.nodes"); + } + + public Resource getOriginPseudoConflictChangeScope() throws IOException { + return loadFromClassLoader("pseudoconflictscope/change/ancestor.nodes"); + } + + public Resource getRightPseudoConflictChangeScope() throws IOException { + return loadFromClassLoader("pseudoconflictscope/change/right.nodes"); + } + + public Resource getLeftPseudoConflictDeleteScope() throws IOException { + return loadFromClassLoader("pseudoconflictscope/delete/left.nodes"); + } + + public Resource getOriginPseudoConflictDeleteScope() throws IOException { + return loadFromClassLoader("pseudoconflictscope/delete/ancestor.nodes"); + } + + public Resource getRightPseudoConflictDeleteScope() throws IOException { + return loadFromClassLoader("pseudoconflictscope/delete/right.nodes"); + } + + public Resource getLeftPseudoConflictFullScope() throws IOException { + return loadFromClassLoader("pseudoconflictscope/fullscope/left.nodes"); + } + + public Resource getOriginPseudoConflictFullScope() throws IOException { + return loadFromClassLoader("pseudoconflictscope/fullscope/ancestor.nodes"); + } + + public Resource getRightPseudoConflictFullScope() throws IOException { + return loadFromClassLoader("pseudoconflictscope/fullscope/right.nodes"); + } } diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/add/ancestor.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/add/ancestor.nodes new file mode 100644 index 000000000..71e1fb2a0 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/add/ancestor.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="_CEv4EM7REeOlS6AUBGqBsw"
+ name="root"/>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/add/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/add/left.nodes new file mode 100644 index 000000000..f5666f5b3 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/add/left.nodes @@ -0,0 +1,11 @@ +<?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="_CEv4EM7REeOlS6AUBGqBsw"
+ name="root">
+ <containmentRef1
+ xmi:id="_AT1TgNqXEeOXstPlKfVTPg"
+ name="A"/>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/add/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/add/right.nodes new file mode 100644 index 000000000..f5666f5b3 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/add/right.nodes @@ -0,0 +1,11 @@ +<?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="_CEv4EM7REeOlS6AUBGqBsw"
+ name="root">
+ <containmentRef1
+ xmi:id="_AT1TgNqXEeOXstPlKfVTPg"
+ name="A"/>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/change/ancestor.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/change/ancestor.nodes new file mode 100644 index 000000000..b4fdaf9a1 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/change/ancestor.nodes @@ -0,0 +1,18 @@ +<?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="_CEv4EM7REeOlS6AUBGqBsw"
+ name="root">
+ <containmentRef1
+ xmi:id="_E30dAMqXEeOXstPlKfVTPg"
+ name="C">
+ <containmentRef1
+ xsi:type="nodes:NodeSingleValueAttribute"
+ xmi:id="_2N8O0OC7EeOz6tW2ExS0YQ"
+ name="D"
+ singleValuedAttribute="Hello"/>
+ </containmentRef1>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/change/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/change/left.nodes new file mode 100644 index 000000000..89fe3ef0b --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/change/left.nodes @@ -0,0 +1,18 @@ +<?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="_CEv4EM7REeOlS6AUBGqBsw"
+ name="root">
+ <containmentRef1
+ xmi:id="_E30dAMqXEeOXstPlKfVTPg"
+ name="C">
+ <containmentRef1
+ xsi:type="nodes:NodeSingleValueAttribute"
+ xmi:id="_2N8O0OC7EeOz6tW2ExS0YQ"
+ name="D"
+ singleValuedAttribute="GoodBye"/>
+ </containmentRef1>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/change/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/change/right.nodes new file mode 100644 index 000000000..89fe3ef0b --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/change/right.nodes @@ -0,0 +1,18 @@ +<?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="_CEv4EM7REeOlS6AUBGqBsw"
+ name="root">
+ <containmentRef1
+ xmi:id="_E30dAMqXEeOXstPlKfVTPg"
+ name="C">
+ <containmentRef1
+ xsi:type="nodes:NodeSingleValueAttribute"
+ xmi:id="_2N8O0OC7EeOz6tW2ExS0YQ"
+ name="D"
+ singleValuedAttribute="GoodBye"/>
+ </containmentRef1>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/delete/ancestor.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/delete/ancestor.nodes new file mode 100644 index 000000000..fed946d3f --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/delete/ancestor.nodes @@ -0,0 +1,11 @@ +<?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="_CEv4EM7REeOlS6AUBGqBsw"
+ name="root">
+ <containmentRef1
+ xmi:id="_D29cANqXEeOXstPlKfVTPg"
+ name="B"/>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/delete/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/delete/left.nodes new file mode 100644 index 000000000..71e1fb2a0 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/delete/left.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="_CEv4EM7REeOlS6AUBGqBsw"
+ name="root"/>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/delete/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/delete/right.nodes new file mode 100644 index 000000000..71e1fb2a0 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/delete/right.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="_CEv4EM7REeOlS6AUBGqBsw"
+ name="root"/>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/fullscope/ancestor.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/fullscope/ancestor.nodes new file mode 100644 index 000000000..5065e5b04 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/fullscope/ancestor.nodes @@ -0,0 +1,21 @@ +<?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="_CEv4EM7REeOlS6AUBGqBsw"
+ name="root">
+ <containmentRef1
+ xmi:id="_D29cANqXEeOXstPlKfVTPg"
+ name="B"/>
+ <containmentRef1
+ xmi:id="_E30dAMqXEeOXstPlKfVTPg"
+ name="C">
+ <containmentRef1
+ xsi:type="nodes:NodeSingleValueAttribute"
+ xmi:id="_2N8O0OC7EeOz6tW2ExS0YQ"
+ name="D"
+ singleValuedAttribute="Hello"/>
+ </containmentRef1>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/fullscope/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/fullscope/left.nodes new file mode 100644 index 000000000..28224cdcc --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/fullscope/left.nodes @@ -0,0 +1,21 @@ +<?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="_CEv4EM7REeOlS6AUBGqBsw"
+ name="root">
+ <containmentRef1
+ xmi:id="_AT1TgNqXEeOXstPlKfVTPg"
+ name="A"/>
+ <containmentRef1
+ xmi:id="_E30dAMqXEeOXstPlKfVTPg"
+ name="C">
+ <containmentRef1
+ xsi:type="nodes:NodeSingleValueAttribute"
+ xmi:id="_2N8O0OC7EeOz6tW2ExS0YQ"
+ name="D"
+ singleValuedAttribute="GoodBye"/>
+ </containmentRef1>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/fullscope/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/fullscope/right.nodes new file mode 100644 index 000000000..28224cdcc --- /dev/null +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/data/pseudoconflictscope/fullscope/right.nodes @@ -0,0 +1,21 @@ +<?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="_CEv4EM7REeOlS6AUBGqBsw"
+ name="root">
+ <containmentRef1
+ xmi:id="_AT1TgNqXEeOXstPlKfVTPg"
+ name="A"/>
+ <containmentRef1
+ xmi:id="_E30dAMqXEeOXstPlKfVTPg"
+ name="C">
+ <containmentRef1
+ xsi:type="nodes:NodeSingleValueAttribute"
+ xmi:id="_2N8O0OC7EeOz6tW2ExS0YQ"
+ name="D"
+ singleValuedAttribute="GoodBye"/>
+ </containmentRef1>
+</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 292f599f4..6f7953bae 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 @@ -35,6 +35,7 @@ import org.eclipse.emf.compare.tests.merge.ExtensionMergeTest; import org.eclipse.emf.compare.tests.merge.IndividualMergeOutOfScopeValuesTest; import org.eclipse.emf.compare.tests.merge.IndividualMergeTest; import org.eclipse.emf.compare.tests.merge.MultipleMergeTest; +import org.eclipse.emf.compare.tests.merge.PseudoConflictMergeTest; import org.eclipse.emf.compare.tests.nodes.NodesPackage; import org.eclipse.emf.compare.tests.nodes.util.NodesResourceFactoryImpl; import org.eclipse.emf.compare.tests.postprocess.PostProcessorTest; @@ -61,7 +62,7 @@ import org.junit.runners.Suite.SuiteClasses; IndividualMergeOutOfScopeValuesTest.class, ProximityComparisonTest.class, DynamicInstanceComparisonTest.class, URIDistanceTest.class, FragmentationTest.class, AllEditTests.class, CommandStackTestSuite.class, MatchEngineFactoryRegistryTest.class, - ConflictMergeTest.class, ProximityIndexTest.class, AllRCPTests.class }) + ConflictMergeTest.class, PseudoConflictMergeTest.class, ProximityIndexTest.class, AllRCPTests.class }) public class AllTests { /** * Standalone launcher for all of compare's tests. |