/******************************************************************************* * Copyright (c) 2012, 2014 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.dependency; import static com.google.common.base.Predicates.and; import static com.google.common.base.Predicates.instanceOf; import static org.eclipse.emf.compare.utils.EMFComparePredicates.addedToReference; import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind; import static org.eclipse.emf.compare.utils.EMFComparePredicates.removedFromReference; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; 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.DifferenceKind; import org.eclipse.emf.compare.uml2.internal.DirectedRelationshipChange; import org.eclipse.emf.compare.uml2.tests.AbstractUMLInputData; import org.eclipse.emf.compare.uml2.tests.AbstractUMLTest; import org.eclipse.emf.compare.uml2.tests.dependency.data.DependencyInputData; import org.eclipse.emf.ecore.resource.Resource; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @SuppressWarnings("nls") public class ChangeDependencyTest extends AbstractUMLTest { private DependencyInputData input = new DependencyInputData(); @BeforeClass public static void setupClass() { fillRegistries(); } @AfterClass public static void teardownClass() { resetRegistries(); } @Test public void testA30UseCase() throws IOException { final Resource left = input.getA3Left(); final Resource right = input.getA3Right(); final Comparison comparison = compare(left, right); testAB1(TestKind.ADD, comparison); testMergeLeftToRight(left, right, null); testMergeRightToLeft(left, right, null); } @Test public void testA31UseCase() throws IOException { final Resource left = input.getA3Left(); final Resource right = input.getA3Right(); final Comparison comparison = compare(right, left); testAB1(TestKind.DELETE, comparison); testMergeLeftToRight(right, left, null); testMergeRightToLeft(right, left, null); } @Test public void testA30UseCase3way() throws IOException { final Resource left = input.getA3Left(); final Resource right = input.getA3Right(); final Comparison comparison = compare(left, right, right); testAB1(TestKind.ADD, comparison); testMergeLeftToRight(left, right, right); testMergeRightToLeft(left, right, right); } @Test public void testA31UseCase3way() throws IOException { final Resource left = input.getA3Left(); final Resource right = input.getA3Right(); final Comparison comparison = compare(left, right, left); testAB1(TestKind.DELETE, comparison); testMergeLeftToRight(left, right, left); testMergeRightToLeft(left, right, left); } private void testAB1(TestKind kind, final Comparison comparison) { final List<Diff> differences = comparison.getDifferences(); // We should have no less and no more than 1 differences assertEquals(1, differences.size()); Predicate<? super Diff> addSupplierInDependencyDescription = null; if (kind.equals(TestKind.DELETE)) { addSupplierInDependencyDescription = removedFromReference("model.Dependency0", "supplier", "model.Class2"); } else { addSupplierInDependencyDescription = addedToReference("model.Dependency0", "supplier", "model.Class2"); } final Diff addSupplierInDependency = Iterators.find(differences.iterator(), addSupplierInDependencyDescription); assertNotNull(addSupplierInDependency); // CHECK EXTENSION // No extension anymore assertEquals(0, count(differences, instanceOf(DirectedRelationshipChange.class))); Diff changeUMLDependency = Iterators.find(differences.iterator(), and(instanceOf(DirectedRelationshipChange.class), ofKind(DifferenceKind.CHANGE)), null); assertNull(changeUMLDependency); // assertNotNull(changeUMLDependency); // assertEquals(1, changeUMLDependency.getRefinedBy().size()); // assertTrue(changeUMLDependency.getRefinedBy().contains(addSupplierInDependency)); // CHECK REQUIREMENT assertEquals(0, addSupplierInDependency.getRequires().size()); // CHECK EQUIVALENCE assertEquals(0, comparison.getEquivalences().size()); testIntersections(comparison); } @Override protected AbstractUMLInputData getInput() { return input; } }