Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Notot2013-01-24 11:39:37 -0500
committerCedric Notot2013-01-24 11:55:27 -0500
commitd536c92b88b21b16d5402e2625351d3e48603ff6 (patch)
tree114911ef15d245e164ee3c1e7a3b81fdf2958bd8
parent0e16023621b6343b1234d0743bd3a3756e5e4224 (diff)
downloadorg.eclipse.emf.compare-d536c92b88b21b16d5402e2625351d3e48603ff6.tar.gz
org.eclipse.emf.compare-d536c92b88b21b16d5402e2625351d3e48603ff6.tar.xz
org.eclipse.emf.compare-d536c92b88b21b16d5402e2625351d3e48603ff6.zip
[398863] Provide a merge extension mechanism
Tests
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/AbstractTest.java8
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/merge/ExtensionMergeTest.java64
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/suite/AllTests.java3
-rw-r--r--plugins/org.eclipse.emf.compare.tests/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/ExtensionMergeTest.java103
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java3
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/ExtensionMergeTest.java70
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/suite/AllTests.java5
8 files changed, 253 insertions, 4 deletions
diff --git a/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/AbstractTest.java b/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/AbstractTest.java
index 5c4e0b68e..7dd6cc3c0 100644
--- a/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/AbstractTest.java
+++ b/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/AbstractTest.java
@@ -4,6 +4,7 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.diagram.diff.DiagramDiffExtensionPostProcessor;
import org.eclipse.emf.compare.extension.PostProcessorDescriptor;
import org.eclipse.emf.compare.extension.PostProcessorRegistry;
@@ -18,6 +19,8 @@ import com.google.common.collect.Iterators;
@SuppressWarnings("nls")
public abstract class AbstractTest {
+ private EMFCompare emfCompare;
+
private PostProcessorRegistry postProcessorRegistry;
@Before
@@ -27,8 +30,13 @@ public abstract class AbstractTest {
"http://www.eclipse.org/gmf/runtime/\\d.\\d.\\d/notation", null,
"org.eclipse.emf.compare.diagram.diff.DiagramDiffExtensionPostProcessor",
new DiagramDiffExtensionPostProcessor()));
+ emfCompare = EMFCompare.builder().setPostProcessorRegistry(postProcessorRegistry).build();
}
+ protected EMFCompare getCompare() {
+ return emfCompare;
+ }
+
/**
* @return the postProcessorRegistry
*/
diff --git a/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/merge/ExtensionMergeTest.java b/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/merge/ExtensionMergeTest.java
new file mode 100644
index 000000000..fee082eef
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/merge/ExtensionMergeTest.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.diagram.ecoretools.tests.merge;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.diagram.ecoretools.tests.AbstractTest;
+import org.eclipse.emf.compare.diagram.ecoretools.tests.DiagramInputData;
+import org.eclipse.emf.compare.diagram.ecoretools.tests.edgechanges.data.EdgeChangesInputData;
+import org.eclipse.emf.compare.extension.merge.DefaultMerger;
+import org.eclipse.emf.compare.extension.merge.IMerger;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.junit.Test;
+
+@SuppressWarnings("nls")
+public class ExtensionMergeTest extends AbstractTest {
+ private EdgeChangesInputData input = new EdgeChangesInputData();
+
+ @Test
+ public void testInstantiationMerger() throws IOException {
+ final Resource left = input.getA1Left();
+ final Resource right = input.getA1Right();
+
+ testMergeRightToLeft(left, right, null);
+ }
+
+
+ protected void testMergeRightToLeft(Notifier left, Notifier right, Notifier origin) {
+ final IComparisonScope scope = EMFCompare.createDefaultScope(left, right, origin);
+ final Comparison comparisonBefore = getCompare().compare(scope);
+ EList<Diff> differences = comparisonBefore.getDifferences();
+ for (Diff diff : differences) {
+ IMerger merger = org.eclipse.emf.compare.tests.merge.ExtensionMergeTest.getMerger(diff,
+ new ArrayList<IMerger>(), DefaultMerger.class);
+ merger.copyRightToLeft(diff, null);
+ }
+ final Comparison comparisonAfter = getCompare().compare(scope);
+ assertTrue("Comparison#getDifferences() must be empty after copyAllRightToLeft", comparisonAfter
+ .getDifferences().isEmpty());
+ }
+
+ @Override
+ protected DiagramInputData getInput() {
+ return input;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/suite/AllTests.java b/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/suite/AllTests.java
index 687416147..1a7cb9c70 100644
--- a/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/suite/AllTests.java
+++ b/plugins/org.eclipse.emf.compare.diagram.ecoretools.tests/src/org/eclipse/emf/compare/diagram/ecoretools/tests/suite/AllTests.java
@@ -18,6 +18,7 @@ import org.eclipse.emf.compare.ComparePackage;
import org.eclipse.emf.compare.diagram.DiagramComparePackage;
import org.eclipse.emf.compare.diagram.ecoretools.tests.edgechanges.EdgechangesTest;
import org.eclipse.emf.compare.diagram.ecoretools.tests.hide.HideTest;
+import org.eclipse.emf.compare.diagram.ecoretools.tests.merge.ExtensionMergeTest;
import org.eclipse.emf.compare.diagram.ecoretools.tests.nodechanges.NodechangesTest;
import org.eclipse.emf.compare.diagram.ecoretools.tests.show.ShowTest;
import org.eclipse.emf.compare.tests.suite.CompareTestSuite;
@@ -38,7 +39,7 @@ import org.junit.runners.Suite.SuiteClasses;
* @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
*/
@RunWith(Suite.class)
-@SuiteClasses({HideTest.class, ShowTest.class, NodechangesTest.class, EdgechangesTest.class})
+@SuiteClasses({HideTest.class, ShowTest.class, NodechangesTest.class, EdgechangesTest.class, ExtensionMergeTest.class})
public class AllTests {
/**
diff --git a/plugins/org.eclipse.emf.compare.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.compare.tests/META-INF/MANIFEST.MF
index cee9ebe6f..9876c270b 100644
--- a/plugins/org.eclipse.emf.compare.tests/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.compare.tests/META-INF/MANIFEST.MF
@@ -20,6 +20,7 @@ Require-Bundle: org.eclipse.core.runtime,
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.eclipse.emf.compare.tests.framework,
+ org.eclipse.emf.compare.tests.merge,
org.eclipse.emf.compare.tests.nodes,
org.eclipse.emf.compare.tests.nodes.impl,
org.eclipse.emf.compare.tests.nodes.util,
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/ExtensionMergeTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/ExtensionMergeTest.java
new file mode 100644
index 000000000..f512ee821
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/ExtensionMergeTest.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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 junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertSame;
+import static junit.framework.Assert.assertTrue;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.changedAttribute;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
+
+import com.google.common.collect.Iterators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceSource;
+import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.extension.merge.DefaultMerger;
+import org.eclipse.emf.compare.extension.merge.IMerger;
+import org.eclipse.emf.compare.extension.merge.IMerger.RegistryImpl;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.compare.tests.merge.data.IndividualDiffInputData;
+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 ExtensionMergeTest {
+ private IndividualDiffInputData input = new IndividualDiffInputData();
+
+ @Test
+ public void testInstantiationMerger() throws IOException {
+ final Resource left = input.getAttributeMonoChangeLeft();
+ final Resource right = input.getAttributeMonoChangeRight();
+
+ final IComparisonScope scope = EMFCompare.createDefaultScope(left, right);
+ Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ final List<Diff> differences = comparison.getDifferences();
+ assertSame(Integer.valueOf(1), Integer.valueOf(differences.size()));
+
+ final String featureName = "singleValuedAttribute";
+ final Diff diff = Iterators.find(differences.iterator(), and(fromSide(DifferenceSource.LEFT),
+ changedAttribute("root.origin", featureName, "originValue", "leftValue")));
+
+ IMerger merger = getMerger(diff, new ArrayList<IMerger>(), DefaultMerger.class);
+ merger.copyLeftToRight(diff, null);
+
+ final EObject originNode = getNodeNamed(right, "origin");
+ assertNotNull(originNode);
+ final EStructuralFeature feature = originNode.eClass().getEStructuralFeature(featureName);
+ assertNotNull(feature);
+
+ assertEquals("leftValue", originNode.eGet(feature));
+
+ comparison = EMFCompare.builder().build().compare(scope);
+ assertSame(Integer.valueOf(0), Integer.valueOf(comparison.getDifferences().size()));
+ }
+
+ public static IMerger getMerger(final Diff diff, final List<? extends IMerger> specificMergers,
+ final Class<? extends IMerger> expectedMerger) {
+ IMerger.Registry registry = new RegistryImpl();
+ IMerger coreMerger = new DefaultMerger();
+ coreMerger.setRanking(0);
+ registry.add(coreMerger);
+ for (Iterator<? extends IMerger> iterator = specificMergers.iterator(); iterator.hasNext();) {
+ IMerger iMerger = iterator.next();
+ registry.add(iMerger);
+ }
+ IMerger merger = registry.getHighestRankingMerger(diff);
+ assertNotNull("No merger has been found for the diff: " + diff, merger);
+ assertTrue("The found merger is not an expexted CoreDiffMerger", expectedMerger.isInstance(merger));
+ return merger;
+ }
+
+ 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/suite/AllTests.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
index 971515a06..d6b107d68 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
@@ -26,6 +26,7 @@ import org.eclipse.emf.compare.tests.fullcomparison.DynamicInstanceComparisonTes
import org.eclipse.emf.compare.tests.fullcomparison.ExtLibraryTest;
import org.eclipse.emf.compare.tests.fullcomparison.IdentifierComparisonTest;
import org.eclipse.emf.compare.tests.fullcomparison.ProximityComparisonTest;
+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;
@@ -50,7 +51,7 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({CompareTestSuite.class, DefaultComparisonScopeTest.class, IdentifierComparisonTest.class,
ExtLibraryTest.class, ConflictDetectionTest.class, ReqComputingTest.class, EquiComputingTest.class,
DiffUtilTest.class, MultipleMergeTest.class, PostProcessorTest.class, IndividualMergeTest.class,
- IndividualMergeOutOfScopeValuesTest.class, ProximityComparisonTest.class,
+ ExtensionMergeTest.class, IndividualMergeOutOfScopeValuesTest.class, ProximityComparisonTest.class,
DynamicInstanceComparisonTest.class, URIDistanceTest.class, FragmentationTest.class,
AllEditTests.class, CommandStackTestSuite.class, })
public class AllTests {
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/ExtensionMergeTest.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/ExtensionMergeTest.java
new file mode 100644
index 000000000..b00dba858
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/ExtensionMergeTest.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.uml2.tests.merge;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.extension.merge.DefaultMerger;
+import org.eclipse.emf.compare.extension.merge.IMerger;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.compare.tests.framework.AbstractInputData;
+import org.eclipse.emf.compare.uml2.tests.AbstractTest;
+import org.eclipse.emf.compare.uml2.tests.association.data.AssociationInputData;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.junit.Test;
+
+@SuppressWarnings("nls")
+public class ExtensionMergeTest extends AbstractTest {
+ private AssociationInputData input = new AssociationInputData();
+
+ @Test
+ public void testInstantiationMerger() throws IOException {
+ final Resource left = input.getA1Left();
+ final Resource right = input.getA1Right();
+
+ testMergeRightToLeft(left, right, null);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.uml2.tests.AbstractTest#testMergeRightToLeft(org.eclipse.emf.common.notify.Notifier,
+ * org.eclipse.emf.common.notify.Notifier, org.eclipse.emf.common.notify.Notifier)
+ */
+ @Override
+ protected void testMergeRightToLeft(Notifier left, Notifier right, Notifier origin) {
+ final IComparisonScope scope = EMFCompare.createDefaultScope(left, right, origin);
+ final Comparison comparisonBefore = getCompare().compare(scope);
+ EList<Diff> differences = comparisonBefore.getDifferences();
+ for (Diff diff : differences) {
+ IMerger merger = org.eclipse.emf.compare.tests.merge.ExtensionMergeTest.getMerger(diff,
+ new ArrayList<IMerger>(), DefaultMerger.class);
+ merger.copyRightToLeft(diff, null);
+ }
+ final Comparison comparisonAfter = getCompare().compare(scope);
+ assertTrue("Comparison#getDifferences() must be empty after copyAllRightToLeft", comparisonAfter
+ .getDifferences().isEmpty());
+ }
+
+ @Override
+ protected AbstractInputData getInput() {
+ return input;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/suite/AllTests.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/suite/AllTests.java
index 08d62b853..e2a648b22 100644
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/suite/AllTests.java
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/suite/AllTests.java
@@ -32,6 +32,7 @@ import org.eclipse.emf.compare.uml2.tests.executionSpecification.AddBehaviorExec
import org.eclipse.emf.compare.uml2.tests.extend.AddExtendTest;
import org.eclipse.emf.compare.uml2.tests.generalizationSet.AddGeneralizationSetTest;
import org.eclipse.emf.compare.uml2.tests.include.AddIncludeTest;
+import org.eclipse.emf.compare.uml2.tests.merge.ExtensionMergeTest;
import org.eclipse.emf.compare.uml2.tests.message.AddMessageTest;
import org.eclipse.emf.compare.uml2.tests.profiles.ProfileTest;
import org.eclipse.emf.compare.uml2.tests.stereotypes.DynamicStereotypeTest;
@@ -48,8 +49,8 @@ import org.junit.runners.Suite.SuiteClasses;
*/
@RunWith(Suite.class)
@SuiteClasses({AddDependencyTest.class, AddAbstractionTest.class, AddAssociationTest.class,
- AddAssociation2Test.class, ChangeAssociationTest.class, ChangeDependencyTest.class,
- ChangeUsageTest.class, AddAssociation3Test.class, AddExtendTest.class,
+ ExtensionMergeTest.class, AddAssociation2Test.class, ChangeAssociationTest.class,
+ ChangeDependencyTest.class, ChangeUsageTest.class, AddAssociation3Test.class, AddExtendTest.class,
AddGeneralizationSetTest.class, AddInterfaceRealizationTest.class, AddRealizationTest.class,
AddSubstitutionTest.class, AddUsageTest.class, AddMessageTest.class,
AddActionExecutionSpecificationTest.class, AddBehaviorExecutionSpecificationTest.class,

Back to the top