Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9d3252c55ebb951096fbe0c7c57feb47df8fd58f (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*******************************************************************************
 * Copyright (c) 2016 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 org.eclipse.emf.compare.DifferenceKind.MOVE;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
import static org.junit.Assert.assertEquals;

import com.google.common.collect.Collections2;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.merge.IMerger;
import org.eclipse.emf.compare.tests.merge.data.bug485266.Bug485266InputData;
import org.eclipse.emf.ecore.resource.Resource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
 * This class assert that EMFCompare correctly handle conflicts between the suppression of an element
 * (packageA) on a side and the move of an other element (which is a child of packageA) on the other side.
 * 
 * @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a>
 */
@RunWith(Parameterized.class)
public class Bug485266_MoveDeleteConflict_Test extends AbstractMergerTest {

	/**
	 * Create the list of parameters for the parametrized test. The parameters for each test is an object:
	 * 
	 * <pre>
	 * Object[] {
	 * 			originResource, 
	 * 			leftResource, 
	 * 			rightResource, 
	 * 			boolean for the merge direction,
	 * 			the resource we expect after the merge}
	 * </pre>
	 * 
	 * @return the list of parameters for the tests
	 * @throws IOException
	 */
	@SuppressWarnings({"boxing" })
	@Parameters
	public static Collection<Object[]> params() throws IOException {
		Bug485266InputData inputData = new Bug485266InputData();

		/**
		 * <pre>
		 * The ancestor:
		 * - root
		 *   - packageA
		 *     - nodeB
		 * 
		 * The left model:
		 * - root
		 * 
		 * The right model:
		 * - root
		 *   - packageA
		 *   - nodeB
		 *   
		 * The correct result on the left side after a merge of the move of nodeB from right to left:
		 * - root
		 *   - nodeB
		 * </pre>
		 */
		Object[] test1RightToLeft = new Object[] {inputData.getData1AncestorResource(),
				inputData.getData1LeftResource(), inputData.getData1RightResource(), true,
				inputData.getData1ResultResource() };
		Object[] test1LeftToRight = new Object[] {inputData.getData1AncestorResource(),
				inputData.getData1RightResource(), inputData.getData1LeftResource(), false,
				inputData.getData1ResultResource() };

		/**
		 * <pre>
		 * The ancestor:
		 * - root
		 *   - packageA
		 *     - packageB
		 *       - packageC
		 *         - packageD
		 *           - packageE
		 * 
		 * The left model:
		 * - root
		 * 
		 * The right model:
		 * - root
		 *   - packageA
		 *   - packageB
		 *     - packageC
		 *   - packageD
		 *     - packageE
		 *   
		 * The correct result on the left side after a merge of the move of packageB and packageD from right to left:
		 * - root
		 *   - packageB
		 *   - packageD
		 * </pre>
		 */
		Object[] test2RightToLeft = new Object[] {inputData.getData2AncestorResource(),
				inputData.getData2LeftResource(), inputData.getData2RightResource(), true,
				inputData.getData2ResultResource() };
		Object[] test2LeftToRight = new Object[] {inputData.getData2AncestorResource(),
				inputData.getData2RightResource(), inputData.getData2LeftResource(), false,
				inputData.getData2ResultResource() };

		/**
		 * More complex models (supertypes, renaming)
		 */
		Object[] test3RightToLeft = new Object[] {inputData.getData3AncestorResource(),
				inputData.getData3LeftResource(), inputData.getData3RightResource(), true,
				inputData.getData3ResultResource() };
		Object[] test3LeftToRight = new Object[] {inputData.getData3AncestorResource(),
				inputData.getData3RightResource(), inputData.getData3LeftResource(), false,
				inputData.getData3ResultResource() };

		/**
		 * <pre>
		 * The ancestor:
		 * - root
		 *   - packageA
		 *     - packageB
		 *       - packageC
		 * 
		 * The left model:
		 * - root
		 * 
		 * The right model:
		 * - root
		 *   - packageC
		 *     - packageB
		 *   
		 * The correct result on the left side after a merge of the move of packageB and packageD from right to left:
		 * - root
		 *   - packageC
		 *     - packageB
		 * </pre>
		 * 
		 * The test is actually commented due to a bug in comparison process.
		 */
		Object[] test4RightToLeft = new Object[] {inputData.getData4AncestorResource(),
				inputData.getData4LeftResource(), inputData.getData4RightResource(), true,
				inputData.getData4ResultResource() };
		Object[] test4LeftToRight = new Object[] {inputData.getData4AncestorResource(),
				inputData.getData4RightResource(), inputData.getData4LeftResource(), false,
				inputData.getData4ResultResource() };

		/**
		 * <pre>
		 * The ancestor:
		 * - root
		 *   - packageA
		 *   - packageB
		 *   - packageC
		 * 
		 * The left model:
		 * - root
		 * 
		 * The right model:
		 * - root
		 *   - packageB
		 *     - packageA
		 *   - packageD
		 *   
		 * The correct result on the left side after a merge of the move of packageB and packageD from right to left:
		 * - root
		 *   - packageB
		 *     - packageA
		 * </pre>
		 */
		Object[] test5RightToLeft = new Object[] {inputData.getData5AncestorResource(),
				inputData.getData5LeftResource(), inputData.getData5RightResource(), true,
				inputData.getData5ResultResource() };
		Object[] test5LeftToRight = new Object[] {inputData.getData5AncestorResource(),
				inputData.getData5RightResource(), inputData.getData5LeftResource(), false,
				inputData.getData5ResultResource() };

		// test4 is not used for the moment since their is a bug in the comparison process with this models
		return Arrays.asList(test1RightToLeft, test1LeftToRight, test2RightToLeft, test2LeftToRight,
				test3RightToLeft, test3LeftToRight, test5RightToLeft, test5LeftToRight);
	}

	public Bug485266_MoveDeleteConflict_Test(final Resource origin, final Resource left, final Resource right,
			final boolean rightToLeft, final Resource expected) {
		super(origin, left, right, rightToLeft, expected, IMerger.RegistryImpl.createStandaloneInstance());
	}

	@Override
	protected List<Diff> getDiffsToMerge() {
		List<Diff> diffsToMerge = new ArrayList<Diff>();

		final EList<Conflict> conflicts = comparison.getConflicts();
		for (Conflict conflict : conflicts) {
			final EList<Diff> differences = conflict.getDifferences();

			final Collection<Diff> moveDiffs = Collections2.filter(differences, ofKind(MOVE));
			assertEquals(1, moveDiffs.size());

			final Diff move = moveDiffs.iterator().next();
			diffsToMerge.add(move);
		}
		return diffsToMerge;
	}
}

Back to the top