Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5ff372d716e61023da63031e469be7c2b0566154 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*******************************************************************************
 * Copyright (c) 2015 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.eclipse.emf.compare.utils.EMFComparePredicates.removedFromReference;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;

import java.io.IOException;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.merge.AbstractMerger;
import org.eclipse.emf.compare.merge.IMergeOptionAware;
import org.eclipse.emf.compare.merge.IMerger;
import org.eclipse.emf.compare.scope.DefaultComparisonScope;
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.compare.uml2.internal.merge.UMLMerger;
import org.eclipse.emf.compare.uml2.tests.AbstractUMLInputData;
import org.eclipse.emf.compare.uml2.tests.AbstractUMLTest;
import org.eclipse.emf.compare.uml2.tests.merge.data.DiffInvolvingRefineDiffInputData;
import org.eclipse.emf.ecore.resource.Resource;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

@SuppressWarnings("nls")
public class MergeDiffInvolvingRefineDiffTest extends AbstractUMLTest {

	private DiffInvolvingRefineDiffInputData input = new DiffInvolvingRefineDiffInputData();

	@BeforeClass
	public static void setupClass() {
		fillRegistries();
	}

	@AfterClass
	public static void teardownClass() {
		resetRegistries();
	}

	@Override
	protected AbstractUMLInputData getInput() {
		return input;
	}

	@Test
	public void testMergeRightToLeftWithSubDiffsAwareOption() throws IOException {
		final Resource left = input.getLeft();
		final Resource right = input.getRight();
		final IComparisonScope scope = new DefaultComparisonScope(left, right, null);
		final Comparison comparisonBefore = getCompare().compare(scope);
		EList<Diff> differences = comparisonBefore.getDifferences();
		final IMerger.Registry registry = IMerger.RegistryImpl.createStandaloneInstance();
		final IMerger umlMerger = new UMLMerger();
		umlMerger.setRanking(11);
		registry.add(umlMerger);

		assertEquals(6, differences.size());

		Predicate<? super Diff> removedFromReference = removedFromReference(
				"SysMLmodel.InternalBlock.Block1", "ownedConnector",
				"SysMLmodel.InternalBlock.Block1.Connector2");
		final Diff diff = Iterators.find(differences.iterator(), removedFromReference);

		IMerger merger = registry.getHighestRankingMerger(diff);
		if (merger instanceof IMergeOptionAware) {
			((IMergeOptionAware)merger).getMergeOptions().put(AbstractMerger.SUB_DIFF_AWARE_OPTION,
					Boolean.TRUE);
		}
		merger.copyRightToLeft(diff, null);

		final Comparison comparisonAfter = getCompare().compare(scope);
		// The subdiffs are merged with the selected diff (and the dependencies of these subdiffs)
		assertTrue("Comparison#getDifferences() must be empty after copyRightToLeft", comparisonAfter
				.getDifferences().isEmpty());
	}

	@Test
	public void testMergeRightToLeftWithoutSubDiffsAwareOption() throws IOException {
		final Resource left = input.getLeft();
		final Resource right = input.getRight();
		final IComparisonScope scope = new DefaultComparisonScope(left, right, null);
		final Comparison comparisonBefore = getCompare().compare(scope);
		EList<Diff> differences = comparisonBefore.getDifferences();
		final IMerger.Registry registry = IMerger.RegistryImpl.createStandaloneInstance();
		final IMerger umlMerger = new UMLMerger();
		umlMerger.setRanking(11);
		registry.add(umlMerger);

		assertEquals(6, differences.size());

		Predicate<? super Diff> removedFromReference = removedFromReference(
				"SysMLmodel.InternalBlock.Block1", "ownedConnector",
				"SysMLmodel.InternalBlock.Block1.Connector2");
		final Diff diff = Iterators.find(differences.iterator(), removedFromReference);

		IMerger merger = registry.getHighestRankingMerger(diff);
		if (merger instanceof IMergeOptionAware) {
			((IMergeOptionAware)merger).getMergeOptions().put(AbstractMerger.SUB_DIFF_AWARE_OPTION,
					Boolean.FALSE);
		}
		merger.copyRightToLeft(diff, null);

		final Comparison comparisonAfter = getCompare().compare(scope);
		// The subdiffs are not merge, only the selected diff
		assertEquals(5, comparisonAfter.getDifferences().size());
	}
}

Back to the top