Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Langer2015-10-20 10:36:32 -0400
committerPhilip Langer2015-12-04 03:32:16 -0500
commitab2602c796b9b5e7f90efe31140399304b22dd91 (patch)
treee748bcf6e26cc179b25e5ecba69b855754e634ca /plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests
parent41be0aad9c4b7f7daf02922683f1b8a1cad9dfd8 (diff)
downloadorg.eclipse.emf.compare-ab2602c796b9b5e7f90efe31140399304b22dd91.tar.gz
org.eclipse.emf.compare-ab2602c796b9b5e7f90efe31140399304b22dd91.tar.xz
org.eclipse.emf.compare-ab2602c796b9b5e7f90efe31140399304b22dd91.zip
[479449] Raise conflict for addition to single-valued containment ref
If there is no value in a single-valued containment reference and a new value is set on both sides, it cannot be merged commutatively. However, EMF Compare did not raise a conflict so far. With this change, a conflict is raised on such changes. A test case is included. Note that I didn't put the predicate ConflictDetectionTest.setOfReference() in EMFComparePredicates in this change to allow for merging this change without breaking the API. I move it into EMFComparePredicates in a subsequent change. Bug: 479449 Change-Id: Ic7d2ea91ca87b0fb47ac0b77db7a87eb78cce5ca Signed-off-by: Philip Langer <planger@eclipsesource.com>
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/conflict/ConflictDetectionTest.java75
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/ConflictInputData.java15
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/b3/conflict_b3_containment_reference_left.nodes9
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/b3/conflict_b3_containment_reference_origin.nodes7
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/b3/conflict_b3_containment_reference_right.nodes9
5 files changed, 113 insertions, 2 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/ConflictDetectionTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/ConflictDetectionTest.java
index b445f01ef..ceee2605d 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/ConflictDetectionTest.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/ConflictDetectionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2014 Obeo.
+ * Copyright (c) 2012, 2015 Obeo 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Obeo - initial API and implementation
+ * Philip Langer - bug 479449
*******************************************************************************/
package org.eclipse.emf.compare.tests.conflict;
@@ -20,6 +21,9 @@ import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.moved;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.movedInAttribute;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.movedInReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.onEObject;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.referenceValueMatch;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.removed;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.removedFromAttribute;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.removedFromReference;
@@ -39,6 +43,7 @@ import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Conflict;
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.scope.DefaultComparisonScope;
@@ -49,6 +54,35 @@ import org.junit.Test;
@SuppressWarnings("nls")
public class ConflictDetectionTest {
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the setting of a value in a
+ * single-valued reference going by {@code referenceName} on an EObject which name matches
+ * {@code qualifiedName}.
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
+ * for us to compare it with the given qualified name.
+ * </p>
+ * <p>
+ * TODO this is only here to allow us to avoid changing API; should be moved to EMFComparePredicates
+ * </p>
+ *
+ * @param qualifiedName
+ * Qualified name of the EObject which we expect to present a ReferenceChange.
+ * @param referenceName
+ * Name of the multi-valued reference on which we expect a change.
+ * @param addedQualifiedName
+ * Qualified name of the EObject which we expect to have been added to this reference.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ private static Predicate<? super Diff> setOfReference(final String qualifiedName,
+ final String referenceName, final String addedQualifiedName) {
+ // This is only meant for multi-valued references
+ return and(ofKind(DifferenceKind.ADD), onEObject(qualifiedName), referenceValueMatch(referenceName,
+ addedQualifiedName, false));
+ }
+
private ConflictInputData input = new ConflictInputData();
@Test
@@ -533,6 +567,45 @@ public class ConflictDetectionTest {
}
@Test
+ public void testB3UseCaseForContainmentReference() throws IOException {
+ final Resource left = input.getB3ContainmentReferenceLeft();
+ final Resource origin = input.getB3ContainmentReferenceOrigin();
+ final Resource right = input.getB3ContainmentReferenceRight();
+
+ final IComparisonScope scope = new DefaultComparisonScope(left, right, origin);
+ final Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ final List<Diff> differences = comparison.getDifferences();
+ final List<Conflict> conflicts = comparison.getConflicts();
+
+ // We should have no less and no more than 2 differences, composing a single conflict
+ assertEquals(2, differences.size());
+ assertEquals(1, conflicts.size());
+
+ final Predicate<? super Diff> leftDiffDescription = setOfReference("root.conflictHolder",
+ "singleValueContainment", "root.conflictHolder.newleft");
+ final Predicate<? super Diff> rightDiffDescription = setOfReference("root.conflictHolder",
+ "singleValueContainment", "root.conflictHolder.newright");
+
+ final Diff leftDiff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.LEFT),
+ leftDiffDescription));
+ final Diff rightDiff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.RIGHT),
+ rightDiffDescription));
+
+ assertNotNull(leftDiff);
+ assertNotNull(rightDiff);
+
+ // We know there's only one conflict
+ final Conflict conflict = conflicts.get(0);
+
+ final List<Diff> conflictDiff = conflict.getDifferences();
+ assertEquals(2, conflictDiff.size());
+ assertTrue(conflictDiff.contains(leftDiff));
+ assertTrue(conflictDiff.contains(rightDiff));
+ assertSame(ConflictKind.REAL, conflict.getKind());
+ }
+
+ @Test
public void testB4UseCaseForAttribute() throws IOException {
final Resource left = input.getB4AttributeLeft();
final Resource origin = input.getB4AttributeOrigin();
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/ConflictInputData.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/ConflictInputData.java
index 52cacbc41..2fb05d6f4 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/ConflictInputData.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/ConflictInputData.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 Obeo.
+ * Copyright (c) 2012, 2015 Obeo 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Obeo - initial API and implementation
+ * Philip Langer - bug 479449
*******************************************************************************/
package org.eclipse.emf.compare.tests.conflict.data;
@@ -166,6 +167,18 @@ public class ConflictInputData extends AbstractInputData {
return loadFromClassLoader("b3/conflict_b3_reference_right.nodes");
}
+ public Resource getB3ContainmentReferenceLeft() throws IOException {
+ return loadFromClassLoader("b3/conflict_b3_containment_reference_left.nodes");
+ }
+
+ public Resource getB3ContainmentReferenceOrigin() throws IOException {
+ return loadFromClassLoader("b3/conflict_b3_containment_reference_origin.nodes");
+ }
+
+ public Resource getB3ContainmentReferenceRight() throws IOException {
+ return loadFromClassLoader("b3/conflict_b3_containment_reference_right.nodes");
+ }
+
public Resource getB4AttributeLeft() throws IOException {
return loadFromClassLoader("b4/conflict_b4_attribute_left.nodes");
}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/b3/conflict_b3_containment_reference_left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/b3/conflict_b3_containment_reference_left.nodes
new file mode 100644
index 000000000..05a6433bd
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/b3/conflict_b3_containment_reference_left.nodes
@@ -0,0 +1,9 @@
+<?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="_ioJ60JQ1EeGUu8zWDEISZA" name="root">
+ <containmentRef1 xmi:id="_ioJ60ZQ1EeGUu8zWDEISZA" name="origin"/>
+ <containmentRef1 xmi:id="_ioJ60pQ1EeGUu8zWDEISZA" name="left"/>
+ <containmentRef1 xmi:id="_0EQv4JQ2EeGUu8zWDEISZA" name="right"/>
+ <containmentRef1 xsi:type="nodes:NodeSingleValueContainment" xmi:id="_ioJ605Q1EeGUu8zWDEISZA" name="conflictHolder">
+ <singleValueContainment xmi:id="_newleft" name="newleft"/>
+ </containmentRef1>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/b3/conflict_b3_containment_reference_origin.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/b3/conflict_b3_containment_reference_origin.nodes
new file mode 100644
index 000000000..3c6bfaf73
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/b3/conflict_b3_containment_reference_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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes" xmi:id="_ioJ60JQ1EeGUu8zWDEISZA" name="root">
+ <containmentRef1 xmi:id="_ioJ60ZQ1EeGUu8zWDEISZA" name="origin"/>
+ <containmentRef1 xmi:id="_ioJ60pQ1EeGUu8zWDEISZA" name="left"/>
+ <containmentRef1 xmi:id="_0EQv4JQ2EeGUu8zWDEISZA" name="right"/>
+ <containmentRef1 xsi:type="nodes:NodeSingleValueContainment" xmi:id="_ioJ605Q1EeGUu8zWDEISZA" name="conflictHolder"/>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/b3/conflict_b3_containment_reference_right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/b3/conflict_b3_containment_reference_right.nodes
new file mode 100644
index 000000000..84fce0fbc
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/conflict/data/b3/conflict_b3_containment_reference_right.nodes
@@ -0,0 +1,9 @@
+<?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="_ioJ60JQ1EeGUu8zWDEISZA" name="root">
+ <containmentRef1 xmi:id="_ioJ60ZQ1EeGUu8zWDEISZA" name="origin"/>
+ <containmentRef1 xmi:id="_ioJ60pQ1EeGUu8zWDEISZA" name="left"/>
+ <containmentRef1 xmi:id="_0EQv4JQ2EeGUu8zWDEISZA" name="right"/>
+ <containmentRef1 xsi:type="nodes:NodeSingleValueContainment" xmi:id="_ioJ605Q1EeGUu8zWDEISZA" name="conflictHolder">
+ <singleValueContainment xmi:id="_newright" name="newright"/>
+ </containmentRef1>
+</nodes:Node>

Back to the top