Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Notot2013-06-07 05:40:20 -0400
committerLaurent Goubet2013-06-21 07:04:50 -0400
commit4a8ef93f5473bca8faa7dadd6dc6a123542ce0c6 (patch)
tree6c8b7d46ef18389ed5041652b7b39ec6cbae72b5 /plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff
parent099f3f702c577f1ee81b66680a2f81c548e5f031 (diff)
downloadorg.eclipse.emf.compare-4a8ef93f5473bca8faa7dadd6dc6a123542ce0c6.tar.gz
org.eclipse.emf.compare-4a8ef93f5473bca8faa7dadd6dc6a123542ce0c6.tar.xz
org.eclipse.emf.compare-4a8ef93f5473bca8faa7dadd6dc6a123542ce0c6.zip
Filling of the implication link with UML subsets.
Like equivalences, the merge of a difference may imply the merge of other ones. But, contrary to equivalences, this implication link is unidirectional. So, if A implies B, B does not imply A. In the context of UML, references can be defined as subset of other ones. So, the merge of the add of a reference which is subset of another one implies the add of this last one. In the same way, the delete of a reference which is superset of other ones implies the delete of these last ones. Note that some superset references can be defined as 'union' (that is to say that each superset reference is in one of the subsets). Union supersets are derived, so they are not managed by EMF Compare. The implications are set in Diff#implies and Diff#impliedBy. The reference merger of EMF Compare scans these links to mark as merged the impacted differences without merging them (because the merge itself will be managed by the 'meta-model'). Change-Id: If3a62076c3569b1ba0aa4628c657765cd8ad7711
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/ComparisonUtilTest.java120
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java101
2 files changed, 122 insertions, 99 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/ComparisonUtilTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/ComparisonUtilTest.java
new file mode 100644
index 000000000..098875513
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/ComparisonUtilTest.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 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.diff;
+
+import static com.google.common.base.Predicates.and;
+import static junit.framework.Assert.assertEquals;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.referenceValueMatch;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
+
+import java.io.IOException;
+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.DifferenceSource;
+import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.internal.utils.ComparisonUtil;
+import org.eclipse.emf.compare.scope.DefaultComparisonScope;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.compare.tests.fullcomparison.data.identifier.IdentifierMatchInputData;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.junit.Test;
+
+@SuppressWarnings("all")
+public class ComparisonUtilTest {
+ @Test
+ public void testSubDiffs() throws IOException {
+ IdentifierMatchInputData inputData = new IdentifierMatchInputData();
+
+ final Resource left = inputData.getExtlibraryLeft();
+ final Resource origin = inputData.getExtlibraryOrigin();
+ final Resource right = inputData.getExtlibraryRight();
+
+ // 2-way
+ IComparisonScope scope = new DefaultComparisonScope(left, right, null);
+ Comparison comparison = EMFCompare.builder().build().compare(scope);
+ List<Diff> differences = comparison.getDifferences();
+
+ // Right to left on a deleted element
+ final Predicate<? super Diff> leftPeriodical = and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.DELETE), referenceValueMatch("eClassifiers", "extlibrary.Periodical",
+ true));
+ final Diff leftPeriodicalDiff = Iterators.find(differences.iterator(), leftPeriodical);
+ boolean leftToRight = false;
+ Iterable<Diff> subDiffs = ComparisonUtil.getSubDiffs(leftToRight).apply(leftPeriodicalDiff);
+
+ assertEquals(7, Iterables.size(subDiffs));
+
+ // Left to right on a deleted element
+ leftToRight = true;
+ subDiffs = ComparisonUtil.getSubDiffs(leftToRight).apply(leftPeriodicalDiff);
+
+ assertEquals(4, Iterables.size(subDiffs));
+
+ // Right to left on an added element
+ final Predicate<? super Diff> leftMagazine = and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.ADD), referenceValueMatch("eClassifiers", "extlibrary.Magazine", true));
+ final Diff leftMagazineDiff = Iterators.find(differences.iterator(), leftMagazine);
+ leftToRight = false;
+ subDiffs = ComparisonUtil.getSubDiffs(leftToRight).apply(leftMagazineDiff);
+
+ assertEquals(5, Iterables.size(subDiffs));
+
+ // Left to right on an added element
+ leftToRight = true;
+ subDiffs = ComparisonUtil.getSubDiffs(leftToRight).apply(leftMagazineDiff);
+
+ assertEquals(5, Iterables.size(subDiffs));
+
+ // 3-way
+ scope = new DefaultComparisonScope(left, right, origin);
+ comparison = EMFCompare.builder().build().compare(scope);
+ differences = comparison.getDifferences();
+
+ // Right to left on a deleted element
+ final Predicate<? super Diff> leftPeriodical3Way = and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.DELETE), referenceValueMatch("eClassifiers", "extlibrary.Periodical",
+ true));
+ final Diff leftPeriodicalDiff3Way = Iterators.find(differences.iterator(), leftPeriodical3Way);
+ leftToRight = false;
+ subDiffs = ComparisonUtil.getSubDiffs(leftToRight).apply(leftPeriodicalDiff3Way);
+
+ assertEquals(11, Iterables.size(subDiffs));
+
+ // Left to right on a deleted element
+ leftToRight = true;
+ subDiffs = ComparisonUtil.getSubDiffs(leftToRight).apply(leftPeriodicalDiff3Way);
+
+ assertEquals(8, Iterables.size(subDiffs));
+
+ // Right to left on a added element
+ final Predicate<? super Diff> leftMagazine3Way = and(fromSide(DifferenceSource.LEFT),
+ ofKind(DifferenceKind.ADD), referenceValueMatch("eClassifiers", "extlibrary.Magazine", true));
+ final Diff leftMagazineDiff3Way = Iterators.find(differences.iterator(), leftMagazine3Way);
+ leftToRight = false;
+ subDiffs = ComparisonUtil.getSubDiffs(leftToRight).apply(leftMagazineDiff3Way);
+
+ assertEquals(5, Iterables.size(subDiffs));
+
+ // Left to right on an added element
+ leftToRight = true;
+ subDiffs = ComparisonUtil.getSubDiffs(leftToRight).apply(leftMagazineDiff3Way);
+
+ assertEquals(5, Iterables.size(subDiffs));
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java
index 34cb0b6a7..60d65a22a 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/DiffUtilTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Obeo.
+ * Copyright (c) 2012, 2013 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
@@ -10,33 +10,17 @@
*******************************************************************************/
package org.eclipse.emf.compare.tests.diff;
-import static com.google.common.base.Predicates.and;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.fail;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.referenceValueMatch;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
-import java.io.IOException;
import java.util.List;
import org.eclipse.emf.compare.CompareFactory;
import org.eclipse.emf.compare.Comparison;
-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;
-import org.eclipse.emf.compare.scope.IComparisonScope;
-import org.eclipse.emf.compare.tests.fullcomparison.data.identifier.IdentifierMatchInputData;
-import org.eclipse.emf.compare.utils.DiffUtil;
-import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.compare.internal.utils.DiffUtil;
import org.junit.Test;
/**
@@ -477,87 +461,6 @@ public class DiffUtilTest {
}
}
- @Test
- public void testSubDiffs() throws IOException {
- IdentifierMatchInputData inputData = new IdentifierMatchInputData();
-
- final Resource left = inputData.getExtlibraryLeft();
- final Resource origin = inputData.getExtlibraryOrigin();
- final Resource right = inputData.getExtlibraryRight();
-
- // 2-way
- IComparisonScope scope = new DefaultComparisonScope(left, right, null);
- Comparison comparison = EMFCompare.builder().build().compare(scope);
- List<Diff> differences = comparison.getDifferences();
-
- // Right to left on a deleted element
- final Predicate<? super Diff> leftPeriodical = and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.DELETE), referenceValueMatch("eClassifiers", "extlibrary.Periodical",
- true));
- final Diff leftPeriodicalDiff = Iterators.find(differences.iterator(), leftPeriodical);
- boolean leftToRight = false;
- Iterable<Diff> subDiffs = DiffUtil.getSubDiffs(leftToRight).apply(leftPeriodicalDiff);
-
- assertEquals(7, Iterables.size(subDiffs));
-
- // Left to right on a deleted element
- leftToRight = true;
- subDiffs = DiffUtil.getSubDiffs(leftToRight).apply(leftPeriodicalDiff);
-
- assertEquals(4, Iterables.size(subDiffs));
-
- // Right to left on an added element
- final Predicate<? super Diff> leftMagazine = and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.ADD), referenceValueMatch("eClassifiers", "extlibrary.Magazine", true));
- final Diff leftMagazineDiff = Iterators.find(differences.iterator(), leftMagazine);
- leftToRight = false;
- subDiffs = DiffUtil.getSubDiffs(leftToRight).apply(leftMagazineDiff);
-
- assertEquals(5, Iterables.size(subDiffs));
-
- // Left to right on an added element
- leftToRight = true;
- subDiffs = DiffUtil.getSubDiffs(leftToRight).apply(leftMagazineDiff);
-
- assertEquals(5, Iterables.size(subDiffs));
-
- // 3-way
- scope = new DefaultComparisonScope(left, right, origin);
- comparison = EMFCompare.builder().build().compare(scope);
- differences = comparison.getDifferences();
-
- // Right to left on a deleted element
- final Predicate<? super Diff> leftPeriodical3Way = and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.DELETE), referenceValueMatch("eClassifiers", "extlibrary.Periodical",
- true));
- final Diff leftPeriodicalDiff3Way = Iterators.find(differences.iterator(), leftPeriodical3Way);
- leftToRight = false;
- subDiffs = DiffUtil.getSubDiffs(leftToRight).apply(leftPeriodicalDiff3Way);
-
- assertEquals(11, Iterables.size(subDiffs));
-
- // Left to right on a deleted element
- leftToRight = true;
- subDiffs = DiffUtil.getSubDiffs(leftToRight).apply(leftPeriodicalDiff3Way);
-
- assertEquals(8, Iterables.size(subDiffs));
-
- // Right to left on a added element
- final Predicate<? super Diff> leftMagazine3Way = and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.ADD), referenceValueMatch("eClassifiers", "extlibrary.Magazine", true));
- final Diff leftMagazineDiff3Way = Iterators.find(differences.iterator(), leftMagazine3Way);
- leftToRight = false;
- subDiffs = DiffUtil.getSubDiffs(leftToRight).apply(leftMagazineDiff3Way);
-
- assertEquals(5, Iterables.size(subDiffs));
-
- // Left to right on an added element
- leftToRight = true;
- subDiffs = DiffUtil.getSubDiffs(leftToRight).apply(leftMagazineDiff3Way);
-
- assertEquals(5, Iterables.size(subDiffs));
- }
-
public void diceCoefficientFailure() {
try {
DiffUtil.diceCoefficient(null, null);

Back to the top