From f31cf0e1f9a6a6a330374a705c0c5ffb32caae3a Mon Sep 17 00:00:00 2001 From: Martin Fleck Date: Thu, 12 May 2016 15:49:26 +0200 Subject: [PATCH] [493527] Correct conflict when concurrently unapplying UML stereotypes Test whether the reference change conflicting with the ResourceAttachmentChange refers to a deleted object to determine the correct conflict kind in the DefaultConflictDetector. Includes tests. Bug: 493527 Change-Id: Ib830f326554f2dfea590a3a3e282a56a581e24dd Signed-off-by: Martin Fleck --- .../META-INF/MANIFEST.MF | 3 +- ...oveStereotypeApplicationPseudoConflictTest.java | 71 ++++++++++++++++++++++ .../resourceattachment/stereotype/data/left.uml | 10 +++ .../resourceattachment/stereotype/data/origin.uml | 13 ++++ .../resourceattachment/stereotype/data/right.uml | 10 +++ .../emf/compare/uml2/tests/suite/AllTests.java | 12 ++-- .../compare/conflict/DefaultConflictDetector.java | 8 ++- 7 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/RemoveStereotypeApplicationPseudoConflictTest.java create mode 100644 plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/data/left.uml create mode 100644 plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/data/origin.uml create mode 100644 plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/data/right.uml diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.compare.uml2.tests/META-INF/MANIFEST.MF index 7921486f1..61b3200bf 100644 --- a/plugins/org.eclipse.emf.compare.uml2.tests/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.compare.uml2.tests/META-INF/MANIFEST.MF @@ -27,7 +27,8 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.uml2.uml.edit;bundle-version="5.0.0";visibility:=reexport, org.eclipse.uml2.common.edit;visibility:=reexport, org.eclipse.emf.compare.uml2.edit, - org.eclipse.emf.compare.edit + org.eclipse.emf.compare.edit, + org.eclipse.emf.compare.ide.ui.tests.framework Bundle-ActivationPolicy: lazy Import-Package: com.google.common.base;version="[11.0.0,16.0.0)", com.google.common.collect;version="[11.0.0,16.0.0)" diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/RemoveStereotypeApplicationPseudoConflictTest.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/RemoveStereotypeApplicationPseudoConflictTest.java new file mode 100644 index 000000000..1714b0561 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/RemoveStereotypeApplicationPseudoConflictTest.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2016 EclipseSource Services GmbH 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Fleck - initial API and implementation + *******************************************************************************/ +package org.eclipse.emf.compare.uml2.tests.resourceattachment.stereotype; + +import static com.google.common.collect.Iterables.tryFind; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import com.google.common.base.Optional; +import com.google.common.base.Predicate; + +import java.io.IOException; +import java.util.Arrays; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.compare.Comparison; +import org.eclipse.emf.compare.Conflict; +import org.eclipse.emf.compare.ConflictKind; +import org.eclipse.emf.compare.ide.ui.tests.framework.RuntimeTestRunner; +import org.eclipse.emf.compare.ide.ui.tests.framework.annotations.Compare; +import org.junit.runner.RunWith; + +/** + * This test makes sure that bug 493527 is fixed. The bug reports that when we use the default conflict + * detector a stereotype application is removed on both sides, a REAL conflict is produced instead of PSEUDO + * conflicts. The bug does not occur with the scalable conflict detector (MatchBasedConflictDetector). + * + * @author Martin Fleck + */ +@RunWith(RuntimeTestRunner.class) +public class RemoveStereotypeApplicationPseudoConflictTest { + + private static Predicate hasConflict(final ConflictKind... kinds) { + return new Predicate() { + public boolean apply(Conflict input) { + return input != null && Arrays.asList(kinds).contains(input.getKind()); + } + }; + } + + /** + * Checks whether no REAL conflicts are created when the same stereotype application is removed on both + * sides. In the origin model the UML compare testing profile is used and a stereotype is applied on a + * single class. In the left model and the right model the stereotype application is removed but the + * profile application remains intact. With no further changes, the left and right model are equal and the + * comparison yields the same set of differences when comparing the models to the origin: ReferenceChange + * for the stereotype application base class (unset), ResourceAttachment deletion for the applied + * stereotype and a StereotypeApplicationChange deletion refined by the previous two differences. + * Therefore, any conflicts that are detected between the left and right model should only be PSEUDO + * conflicts. + * + * @throws IOException + * Thrown if we could not access or find the input data. + */ + @Compare(left = "data/left.uml", right = "data/right.uml", ancestor = "data/origin.uml") + public void testPseudoConflictForStereotypeRemoval(Comparison comparison) throws IOException { + final EList conflicts = comparison.getConflicts(); + final Optional realConflict = tryFind(conflicts, hasConflict(ConflictKind.REAL)); + + assertEquals(2, conflicts.size()); + assertFalse(realConflict.isPresent()); + } +} diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/data/left.uml b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/data/left.uml new file mode 100644 index 000000000..616c58061 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/data/left.uml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/data/origin.uml b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/data/origin.uml new file mode 100644 index 000000000..b5ccb1f7b --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/data/origin.uml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/data/right.uml b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/data/right.uml new file mode 100644 index 000000000..616c58061 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/resourceattachment/stereotype/data/right.uml @@ -0,0 +1,10 @@ + + + + + + + + + + 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 d20020be0..0b92adb86 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 @@ -9,13 +9,10 @@ * Obeo - initial API and implementation * Philip Langer - addition of OpaqueTest * Stefan Dirix - addition of PseudoConflictTest + * Martin Fleck - addition of RemoveStereotypeApplicationPseudoConflictTest *******************************************************************************/ package org.eclipse.emf.compare.uml2.tests.suite; -import junit.framework.JUnit4TestAdapter; -import junit.framework.Test; -import junit.textui.TestRunner; - import org.eclipse.emf.compare.uml2.tests.association.AddAssociation2Test; import org.eclipse.emf.compare.uml2.tests.association.AddAssociation3Test; import org.eclipse.emf.compare.uml2.tests.association.AddAssociationTest; @@ -47,6 +44,7 @@ import org.eclipse.emf.compare.uml2.tests.opaque.OpaqueElementBodyChangeDiffTest import org.eclipse.emf.compare.uml2.tests.opaque.OpaqueElementBodyChangeMergeTest; import org.eclipse.emf.compare.uml2.tests.profiles.DynamicProfileTest; import org.eclipse.emf.compare.uml2.tests.profiles.StaticProfileTest; +import org.eclipse.emf.compare.uml2.tests.resourceattachment.stereotype.RemoveStereotypeApplicationPseudoConflictTest; import org.eclipse.emf.compare.uml2.tests.stereotypes.DanglingStereotypeApplicationTest; import org.eclipse.emf.compare.uml2.tests.stereotypes.DynamicStereotypeTest; import org.eclipse.emf.compare.uml2.tests.stereotypes.DynamicStereotypedElementChangeTests; @@ -57,6 +55,10 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; +import junit.framework.JUnit4TestAdapter; +import junit.framework.Test; +import junit.textui.TestRunner; + /** * This test suite allows us to launch all tests for EMF Compare at once. * @@ -77,7 +79,7 @@ import org.junit.runners.Suite.SuiteClasses; StaticStereotypedElementItemProviderTest.class, DynamicStereotypedElementItemProviderTest.class, OpaqueElementBodyChangeDiffTest.class, OpaqueElementBodyChangeMergeTest.class, DanglingStereotypeApplicationTest.class, MergeDiffInvolvingRefineDiffTest.class, - TestNonRegPseudoConflict_484576.class }) + TestNonRegPseudoConflict_484576.class, RemoveStereotypeApplicationPseudoConflictTest.class }) public class AllTests { /** diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/conflict/DefaultConflictDetector.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/conflict/DefaultConflictDetector.java index 3a1e5a133..93ae28528 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/conflict/DefaultConflictDetector.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/conflict/DefaultConflictDetector.java @@ -8,6 +8,7 @@ * Contributors: * Obeo - initial API and implementation * Philip Langer - bugs 446947, 479449 + * Martin Fleck - bug 493527 *******************************************************************************/ package org.eclipse.emf.compare.conflict; @@ -924,8 +925,11 @@ public class DefaultConflictDetector implements IConflictDetector { if (diff.getKind() == DifferenceKind.DELETE && match == candidate.getMatch() && getRelatedModelElement(diff) == null) { if (candidate.getKind() != DifferenceKind.DELETE) { - // The EObject that owns the changed EReference has been deleted on the other side - conflictOn(comparison, diff, candidate, ConflictKind.REAL); + if (!ComparisonUtil.isDeleteOrUnsetDiff(candidate)) { + // The EObject that owns the changed EReference has been deleted on the other side + // [493527] deleted or unset references do not conflict with deleted element + conflictOn(comparison, diff, candidate, ConflictKind.REAL); + } } } else { // Any ReferenceChange that references the affected root is a possible conflict -- 2.11.4.GIT