Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Notot2012-05-22 11:15:50 +0000
committerCedric Notot2012-05-30 09:31:36 +0000
commit75f51818620f9a47b5499ef732712d72f2864a0f (patch)
tree38e9c2fd6ca4996a0071f9477afabd998a716827 /plugins/org.eclipse.emf.compare.tests
parente26fbe664b89492304bc037a6dfdeaac81828e88 (diff)
downloadorg.eclipse.emf.compare-75f51818620f9a47b5499ef732712d72f2864a0f.tar.gz
org.eclipse.emf.compare-75f51818620f9a47b5499ef732712d72f2864a0f.tar.xz
org.eclipse.emf.compare-75f51818620f9a47b5499ef732712d72f2864a0f.zip
Use of EcoreUtil.CrossReferencer and equivalence computing development
Diffstat (limited to 'plugins/org.eclipse.emf.compare.tests')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/model/nodes.ecore18
-rw-r--r--plugins/org.eclipse.emf.compare.tests/model/nodes.genmodel12
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/EquiComputingTest.java83
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/EquiInputData.java16
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/a1/left.nodes9
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/a1/right.nodes9
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/useCases9
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java9
8 files changed, 161 insertions, 4 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/model/nodes.ecore b/plugins/org.eclipse.emf.compare.tests/model/nodes.ecore
index dd1a4c0d0..0a9ad7160 100644
--- a/plugins/org.eclipse.emf.compare.tests/model/nodes.ecore
+++ b/plugins/org.eclipse.emf.compare.tests/model/nodes.ecore
@@ -34,4 +34,22 @@
<eStructuralFeatures xsi:type="ecore:EReference" name="multiValuedReference" upperBound="-1"
eType="#//Node"/>
</eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="NodeOppositeRefOneToOne" eSuperTypes="#//Node">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="source" eType="#//NodeOppositeRefOneToOne"
+ eOpposite="#//NodeOppositeRefOneToOne/destination"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="destination" eType="#//NodeOppositeRefOneToOne"
+ eOpposite="#//NodeOppositeRefOneToOne/source"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="NodeOppositeRefOneToMany" eSuperTypes="#//Node">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="source" eType="#//NodeOppositeRefOneToMany"
+ eOpposite="#//NodeOppositeRefOneToMany/destination"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="destination" upperBound="-1"
+ eType="#//NodeOppositeRefOneToMany" eOpposite="#//NodeOppositeRefOneToMany/source"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="NodeOppositeRefManyToMany" eSuperTypes="#//Node">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="source" upperBound="-1"
+ eType="#//NodeOppositeRefManyToMany" eOpposite="#//NodeOppositeRefManyToMany/destination"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="destination" upperBound="-1"
+ eType="#//NodeOppositeRefManyToMany" eOpposite="#//NodeOppositeRefManyToMany/source"/>
+ </eClassifiers>
</ecore:EPackage>
diff --git a/plugins/org.eclipse.emf.compare.tests/model/nodes.genmodel b/plugins/org.eclipse.emf.compare.tests/model/nodes.genmodel
index cc57fd36f..50c4129e2 100644
--- a/plugins/org.eclipse.emf.compare.tests/model/nodes.genmodel
+++ b/plugins/org.eclipse.emf.compare.tests/model/nodes.genmodel
@@ -31,5 +31,17 @@
<genClasses ecoreClass="nodes.ecore#//NodeMultiValueReference">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference nodes.ecore#//NodeMultiValueReference/multiValuedReference"/>
</genClasses>
+ <genClasses ecoreClass="nodes.ecore#//NodeOppositeRefOneToOne">
+ <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference nodes.ecore#//NodeOppositeRefOneToOne/source"/>
+ <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference nodes.ecore#//NodeOppositeRefOneToOne/destination"/>
+ </genClasses>
+ <genClasses ecoreClass="nodes.ecore#//NodeOppositeRefOneToMany">
+ <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference nodes.ecore#//NodeOppositeRefOneToMany/source"/>
+ <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference nodes.ecore#//NodeOppositeRefOneToMany/destination"/>
+ </genClasses>
+ <genClasses ecoreClass="nodes.ecore#//NodeOppositeRefManyToMany">
+ <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference nodes.ecore#//NodeOppositeRefManyToMany/source"/>
+ <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference nodes.ecore#//NodeOppositeRefManyToMany/destination"/>
+ </genClasses>
</genPackages>
</genmodel:GenModel>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/EquiComputingTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/EquiComputingTest.java
new file mode 100644
index 000000000..a3dac6a28
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/EquiComputingTest.java
@@ -0,0 +1,83 @@
+package org.eclipse.emf.compare.tests.equi;
+
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertSame;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.addedToReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.changedReference;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.base.Predicate;
+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.EMFCompare;
+import org.eclipse.emf.compare.tests.equi.data.EquiInputData;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.junit.Test;
+
+public class EquiComputingTest {
+
+ private EquiInputData input = new EquiInputData();
+
+ @Test
+ public void testA1UseCase() throws IOException {
+ final Resource left = input.getA1Left();
+ final Resource right = input.getA1Right();
+
+ final Comparison comparison = EMFCompare.compare(left, right);
+
+ List<Diff> differences = comparison.getDifferences();
+
+ // We should have no less and no more than 6 differences
+ assertSame(Integer.valueOf(6), Integer.valueOf(differences.size()));
+
+ Predicate<? super Diff> changeRefA2BDiffDescription = changedReference("Requirements.A",
+ "destination", null, "Requirements.B");
+ Predicate<? super Diff> changeRefB2ADiffDescription = changedReference("Requirements.B", "source",
+ null, "Requirements.A");
+ Predicate<? super Diff> changeRefC2DDiffDescription = addedToReference("Requirements.C",
+ "destination", "Requirements.D");
+ Predicate<? super Diff> changeRefD2CDiffDescription = changedReference("Requirements.D", "source",
+ null, "Requirements.C");
+ Predicate<? super Diff> changeRefE2FDiffDescription = addedToReference("Requirements.E",
+ "destination", "Requirements.F");
+ Predicate<? super Diff> changeRefF2EDiffDescription = addedToReference("Requirements.F", "source",
+ "Requirements.E");
+
+ final Diff changeRefA2BDiff = Iterators.find(differences.iterator(), changeRefA2BDiffDescription);
+ final Diff changeRefB2ADiff = Iterators.find(differences.iterator(), changeRefB2ADiffDescription);
+ final Diff changeRefC2DDiff = Iterators.find(differences.iterator(), changeRefC2DDiffDescription);
+ final Diff changeRefD2CDiff = Iterators.find(differences.iterator(), changeRefD2CDiffDescription);
+ final Diff changeRefE2FDiff = Iterators.find(differences.iterator(), changeRefE2FDiffDescription);
+ final Diff changeRefF2EDiff = Iterators.find(differences.iterator(), changeRefF2EDiffDescription);
+
+ assertNotNull(changeRefA2BDiff);
+ assertNotNull(changeRefB2ADiff);
+ assertNotNull(changeRefC2DDiff);
+ assertNotNull(changeRefD2CDiff);
+ assertNotNull(changeRefE2FDiff);
+ assertNotNull(changeRefF2EDiff);
+
+ // CHECK EQUIVALENCE
+ assertNotNull(changeRefA2BDiff.getEquivalence());
+ assertSame(Integer.valueOf(2), changeRefA2BDiff.getEquivalence().getDifferences().size());
+ assertTrue(changeRefA2BDiff.getEquivalence().getDifferences().contains(changeRefA2BDiff));
+ assertTrue(changeRefA2BDiff.getEquivalence().getDifferences().contains(changeRefB2ADiff));
+
+ assertNotNull(changeRefC2DDiff.getEquivalence());
+ assertSame(Integer.valueOf(2), changeRefC2DDiff.getEquivalence().getDifferences().size());
+ assertTrue(changeRefC2DDiff.getEquivalence().getDifferences().contains(changeRefC2DDiff));
+ assertTrue(changeRefC2DDiff.getEquivalence().getDifferences().contains(changeRefD2CDiff));
+
+ assertNotNull(changeRefE2FDiff.getEquivalence());
+ assertSame(Integer.valueOf(2), changeRefE2FDiff.getEquivalence().getDifferences().size());
+ assertTrue(changeRefE2FDiff.getEquivalence().getDifferences().contains(changeRefE2FDiff));
+ assertTrue(changeRefE2FDiff.getEquivalence().getDifferences().contains(changeRefF2EDiff));
+
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/EquiInputData.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/EquiInputData.java
new file mode 100644
index 000000000..9f1af3860
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/EquiInputData.java
@@ -0,0 +1,16 @@
+package org.eclipse.emf.compare.tests.equi.data;
+
+import java.io.IOException;
+
+import org.eclipse.emf.compare.tests.framework.AbstractInputData;
+import org.eclipse.emf.ecore.resource.Resource;
+
+public class EquiInputData extends AbstractInputData {
+ public Resource getA1Left() throws IOException {
+ return loadFromClassloader("a1/left.nodes"); //$NON-NLS-1$
+ }
+
+ public Resource getA1Right() throws IOException {
+ return loadFromClassloader("a1/right.nodes"); //$NON-NLS-1$
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/a1/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/a1/left.nodes
new file mode 100644
index 000000000..d3a7808e6
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/a1/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="_yWc_0JUeEeGiestbncRZoQ" name="Requirements">
+ <containmentRef1 xsi:type="nodes:NodeOppositeRefOneToOne" xmi:id="_ZB0jcJtsEeGMQeoeefOsHA" name="A" destination="_dRiFIJtsEeGMQeoeefOsHA"/>
+ <containmentRef1 xsi:type="nodes:NodeOppositeRefOneToOne" xmi:id="_dRiFIJtsEeGMQeoeefOsHA" name="B" source="_ZB0jcJtsEeGMQeoeefOsHA"/>
+ <containmentRef1 xsi:type="nodes:NodeOppositeRefOneToMany" xmi:id="_m5FOMJtsEeGMQeoeefOsHA" name="C" destination="_njLUEJtsEeGMQeoeefOsHA"/>
+ <containmentRef1 xsi:type="nodes:NodeOppositeRefOneToMany" xmi:id="_njLUEJtsEeGMQeoeefOsHA" name="D" source="_m5FOMJtsEeGMQeoeefOsHA"/>
+ <containmentRef1 xsi:type="nodes:NodeOppositeRefManyToMany" xmi:id="_xjrvsJtsEeGMQeoeefOsHA" name="E" destination="_zbOgIJtsEeGMQeoeefOsHA"/>
+ <containmentRef1 xsi:type="nodes:NodeOppositeRefManyToMany" xmi:id="_zbOgIJtsEeGMQeoeefOsHA" name="F" source="_xjrvsJtsEeGMQeoeefOsHA"/>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/a1/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/a1/right.nodes
new file mode 100644
index 000000000..c2295d20e
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/a1/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="_yWc_0JUeEeGiestbncRZoQ" name="Requirements">
+ <containmentRef1 xsi:type="nodes:NodeOppositeRefOneToOne" xmi:id="_ZB0jcJtsEeGMQeoeefOsHA" name="A"/>
+ <containmentRef1 xsi:type="nodes:NodeOppositeRefOneToOne" xmi:id="_dRiFIJtsEeGMQeoeefOsHA" name="B"/>
+ <containmentRef1 xsi:type="nodes:NodeOppositeRefOneToMany" xmi:id="_m5FOMJtsEeGMQeoeefOsHA" name="C"/>
+ <containmentRef1 xsi:type="nodes:NodeOppositeRefOneToMany" xmi:id="_njLUEJtsEeGMQeoeefOsHA" name="D"/>
+ <containmentRef1 xsi:type="nodes:NodeOppositeRefManyToMany" xmi:id="_xjrvsJtsEeGMQeoeefOsHA" name="E"/>
+ <containmentRef1 xsi:type="nodes:NodeOppositeRefManyToMany" xmi:id="_zbOgIJtsEeGMQeoeefOsHA" name="F"/>
+</nodes:Node>
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/useCases b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/useCases
new file mode 100644
index 000000000..e32370424
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/equi/data/useCases
@@ -0,0 +1,9 @@
+This will try and list all possible "dependence" cases that can happen in a model comparison. For each use case, we will consider
+two models, "left" and "right".
+
+a - 2-ways comparison
+ a1 - 1-1 relation
+ a2 - 1-n relation
+ a3 - n-1 relation
+ a4 - n-n relation
+
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 2af7311a7..81675f989 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
@@ -16,8 +16,9 @@ import junit.textui.TestRunner;
import org.eclipse.emf.compare.ComparePackage;
import org.eclipse.emf.compare.internal.spec.CompareFactorySpec;
-import org.eclipse.emf.compare.tests.conflict.ConflictDetectionTest;
-import org.eclipse.emf.compare.tests.diff.DiffEngineTest;
+import org.eclipse.emf.compare.tests.conflict.ConflictDetectionTest;
+import org.eclipse.emf.compare.tests.diff.DiffEngineTest;
+import org.eclipse.emf.compare.tests.equi.EquiComputingTest;
import org.eclipse.emf.compare.tests.fullcomparison.IdentifierComparisonTest;
import org.eclipse.emf.compare.tests.model.CompareModelTestSuite;
import org.eclipse.emf.compare.tests.nodes.NodesPackage;
@@ -38,8 +39,8 @@ import org.junit.runners.Suite.SuiteClasses;
* @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
*/
@RunWith(Suite.class)
-@SuiteClasses({CompareModelTestSuite.class, DefaultComparisonScopeTest.class, IdentifierComparisonTest.class,
- ConflictDetectionTest.class, ReqComputingTest.class, DiffEngineTest.class, })
+@SuiteClasses({CompareModelTestSuite.class, DefaultComparisonScopeTest.class, IdentifierComparisonTest.class,
+ ConflictDetectionTest.class, ReqComputingTest.class, EquiComputingTest.class, DiffEngineTest.class })
public class AllTests {
/**
* Standalone launcher for all of compare's tests.

Back to the top