Skip to main content
summaryrefslogtreecommitdiffstats
blob: ebc18cdba46891dc5e0e2777c433b6c7ebd0586d (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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
/*******************************************************************************
 * Copyright (c) 2016 EclipseSource Muenchen 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:
 *     Alexandra Buzila - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.compare.uml2.tests.multiplicitychanges;

import static com.google.common.base.Predicates.and;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.size;
import static org.eclipse.emf.compare.DifferenceSource.LEFT;
import static org.eclipse.emf.compare.DifferenceSource.RIGHT;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

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

import java.io.IOException;
import java.util.ArrayList;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.compare.AttributeChange;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.ConflictKind;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.ReferenceChange;
import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
import org.eclipse.emf.compare.ide.ui.tests.framework.RuntimeTestRunner;
import org.eclipse.emf.compare.ide.ui.tests.framework.annotations.Compare;
import org.eclipse.emf.compare.ide.ui.tests.framework.annotations.ResolutionStrategies;
import org.eclipse.emf.compare.uml2.internal.MultiplicityElementChange;
import org.eclipse.emf.compare.utils.MatchUtil;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.uml2.uml.LiteralInteger;
import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
import org.eclipse.uml2.uml.UMLPackage;
import org.junit.runner.RunWith;

@RunWith(RuntimeTestRunner.class)
@ResolutionStrategies(ResolutionStrategyID.PROJECT)
public class MultiplicityElementChangesTest {

	private static final Predicate<Diff> IS_MULTIPLICITY_CHANGE = new Predicate<Diff>() {
		public boolean apply(Diff diff) {
			return diff instanceof MultiplicityElementChange;
		}
	};

	private static final Predicate<Diff> IS_LOWER_VALUE_REFERENCE_CHANGE = new Predicate<Diff>() {
		public boolean apply(Diff diff) {
			if (!(diff instanceof ReferenceChange)) {
				return false;
			}
			ReferenceChange refChange = (ReferenceChange)diff;
			return refChange.getReference() == UMLPackage.eINSTANCE.getMultiplicityElement_LowerValue();
		}
	};

	private static final Predicate<Diff> IS_LOWER_VALUE_ATTRIBUTE_CHANGE = new Predicate<Diff>() {
		public boolean apply(Diff diff) {
			if (!(diff instanceof AttributeChange)) {
				return false;
			}
			EObject container = MatchUtil.getContainer(diff.getMatch().getComparison(), diff);
			if (container instanceof LiteralInteger || container instanceof LiteralUnlimitedNatural) {
				EStructuralFeature eContainingFeature = container.eContainingFeature();
				return eContainingFeature == UMLPackage.eINSTANCE.getMultiplicityElement_LowerValue();
			}
			return false;
		}
	};

	private static final Predicate<Diff> IS_UPPER_VALUE_REFERENCE_CHANGE = new Predicate<Diff>() {
		public boolean apply(Diff diff) {
			if (!(diff instanceof ReferenceChange)) {
				return false;
			}
			ReferenceChange refChange = (ReferenceChange)diff;
			return refChange.getReference() == UMLPackage.eINSTANCE.getMultiplicityElement_UpperValue();
		}
	};

	private static final Predicate<Diff> IS_UPPER_VALUE_ATTRIBUTE_CHANGE = new Predicate<Diff>() {
		public boolean apply(Diff diff) {
			if (!(diff instanceof AttributeChange)) {
				return false;
			}
			EObject container = MatchUtil.getContainer(diff.getMatch().getComparison(), diff);
			if (container instanceof LiteralInteger || container instanceof LiteralUnlimitedNatural) {
				EStructuralFeature eContainingFeature = container.eContainingFeature();
				return eContainingFeature == UMLPackage.eINSTANCE.getMultiplicityElement_UpperValue();
			}
			return false;
		}
	};

	private static final Predicate<Diff> IS_UPPER_VALUE_CHANGE = new Predicate<Diff>() {
		public boolean apply(Diff diff) {
			return IS_UPPER_VALUE_REFERENCE_CHANGE.apply(diff) || IS_UPPER_VALUE_ATTRIBUTE_CHANGE.apply(diff);
		}
	};

	private static final Predicate<Diff> IS_LOWER_VALUE_CHANGE = new Predicate<Diff>() {
		public boolean apply(Diff diff) {
			return IS_LOWER_VALUE_REFERENCE_CHANGE.apply(diff) || IS_LOWER_VALUE_ATTRIBUTE_CHANGE.apply(diff);
		}
	};

	/**
	 * <b>origin:</b> an activity with an input pin <br>
	 * <b>left:</b> multiplicity lower value is added to the input pin <br>
	 * <b>right:</b> multiplicity upper value is added to the input pin
	 */
	@Compare(left = "a1/left.uml", right = "a1/right.uml", ancestor = "a1/origin.uml")
	public void testNonConflictingAddition(Comparison comparison) throws IOException {
		EList<Diff> diffs = comparison.getDifferences();
		Iterable<Diff> leftChanges = filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(LEFT)));
		Iterable<Diff> rightChanges = filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(RIGHT)));

		assertEquals(1, size(leftChanges));
		assertEquals(1, size(rightChanges));

		MultiplicityElementChange leftChange = (MultiplicityElementChange)leftChanges.iterator().next();
		assertEquals(1, leftChange.getRefinedBy().size());
		assertTrue(leftChange.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, leftChange.getKind());

		MultiplicityElementChange rightChange = (MultiplicityElementChange)rightChanges.iterator().next();
		assertEquals(1, rightChange.getRefinedBy().size());
		assertTrue(rightChange.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, rightChange.getKind());

		assertEquals(0, comparison.getConflicts().size());
	}

	/**
	 * <b>origin:</b> an activity with an input pin <br>
	 * <b>left:</b> multiplicity lower value is added to the input pin <br>
	 * <b>right:</b> multiplicity lower and upper values are added to the input pin, but the lower value is
	 * the same value as in the left change
	 */
	@Compare(left = "a2/left.uml", right = "a2/right.uml", ancestor = "a2/origin.uml")
	public void testAdditionsWithPseudoconflict(Comparison comparison) throws IOException {
		EList<Diff> diffs = comparison.getDifferences();
		ArrayList<Diff> leftChanges = Lists
				.newArrayList(filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(LEFT))));
		ArrayList<Diff> rightChanges = Lists
				.newArrayList(filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(RIGHT))));

		assertEquals(1, size(leftChanges));
		assertEquals(2, size(rightChanges));

		MultiplicityElementChange leftChange = (MultiplicityElementChange)leftChanges.get(0);
		assertEquals(1, leftChange.getRefinedBy().size());
		assertTrue(leftChange.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, leftChange.getKind());

		MultiplicityElementChange rightChange1 = (MultiplicityElementChange)rightChanges.get(0);
		assertEquals(1, rightChange1.getRefinedBy().size());
		assertTrue(rightChange1.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, rightChange1.getKind());

		MultiplicityElementChange rightChange2 = (MultiplicityElementChange)rightChanges.get(1);
		assertEquals(1, rightChange2.getRefinedBy().size());
		assertTrue(rightChange2.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, rightChange2.getKind());

		assertEquals(1, comparison.getConflicts().size());
		Conflict conflict = comparison.getConflicts().get(0);
		assertEquals(ConflictKind.PSEUDO, conflict.getKind());
		assertTrue(conflict.getDifferences().contains(leftChange));

		if (isLowerValueChange(rightChange1)) {
			assertEquals(conflict, rightChange1.getConflict());
		} else {
			assertTrue(isLowerValueChange(rightChange2));
			assertEquals(conflict, rightChange2.getConflict());
		}
	}

	/**
	 * <b>origin:</b> an activity with an input pin <br>
	 * <b>left:</b> multiplicity lower value is added to the input pin <br>
	 * <b>right:</b> multiplicity lower and upper values are added to the input pin, but the lower value is
	 * different than the one in the left change
	 */
	@Compare(left = "a3/left.uml", right = "a3/right.uml", ancestor = "a3/origin.uml")
	public void testAdditionsWithConflict(Comparison comparison) throws IOException {
		EList<Diff> diffs = comparison.getDifferences();
		ArrayList<Diff> leftChanges = Lists
				.newArrayList(filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(LEFT))));
		ArrayList<Diff> rightChanges = Lists
				.newArrayList(filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(RIGHT))));

		assertEquals(1, size(leftChanges));
		assertEquals(2, size(rightChanges));

		MultiplicityElementChange leftChange = (MultiplicityElementChange)leftChanges.get(0);
		assertEquals(1, leftChange.getRefinedBy().size());
		assertTrue(leftChange.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, leftChange.getKind());

		MultiplicityElementChange rightChange1 = (MultiplicityElementChange)rightChanges.get(0);
		assertEquals(1, rightChange1.getRefinedBy().size());
		assertTrue(rightChange1.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, rightChange1.getKind());

		MultiplicityElementChange rightChange2 = (MultiplicityElementChange)rightChanges.get(1);
		assertEquals(1, rightChange2.getRefinedBy().size());
		assertTrue(rightChange2.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, rightChange2.getKind());

		assertEquals(1, comparison.getConflicts().size());
		Conflict conflict = comparison.getConflicts().get(0);
		assertEquals(ConflictKind.REAL, conflict.getKind());

		if (isLowerValueChange(rightChange1)) {
			assertEquals(conflict, rightChange1.getConflict());
		} else {
			assertTrue(isLowerValueChange(rightChange2));
			assertEquals(conflict, rightChange2.getConflict());
		}
	}

	/**
	 * <b>origin:</b> an activity with an input pin, with a lower and upper value <br>
	 * <b>left:</b> multiplicity lower value is changed to 1 <br>
	 * <b>right:</b> multiplicity lower value is changed to 2 <br>
	 * A real conflict should be produced.
	 */
	@Compare(left = "a4/left.uml", right = "a4/right.uml", ancestor = "a4/origin.uml")
	public void testChangesWithConflict(Comparison comparison) throws IOException {
		EList<Diff> diffs = comparison.getDifferences();
		Iterable<Diff> leftChanges = filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(LEFT)));
		Iterable<Diff> rightChanges = filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(RIGHT)));

		assertEquals(1, size(leftChanges));
		MultiplicityElementChange leftChange = (MultiplicityElementChange)leftChanges.iterator().next();
		assertEquals(1, leftChange.getRefinedBy().size());
		assertTrue(leftChange.getRefinedBy().get(0) instanceof AttributeChange);
		assertEquals(DifferenceKind.CHANGE, leftChange.getKind());

		assertEquals(1, size(rightChanges));
		MultiplicityElementChange rightChange = (MultiplicityElementChange)rightChanges.iterator().next();
		assertEquals(1, rightChange.getRefinedBy().size());
		assertTrue(rightChange.getRefinedBy().get(0) instanceof AttributeChange);
		assertEquals(DifferenceKind.CHANGE, rightChange.getKind());

		assertEquals(1, comparison.getConflicts().size());
		Conflict conflict = comparison.getConflicts().get(0);
		assertEquals(ConflictKind.REAL, conflict.getKind());
		assertEquals(conflict, rightChange.getConflict());
	}

	/**
	 * <b>origin:</b> an activity with an input pin, with a lower and upper value <br>
	 * <b>left:</b> multiplicity lower value is changed to 1 <br>
	 * <b>right:</b> multiplicity lower value is changed to 1 <br>
	 * A pseudo conflict should be produced.
	 */
	@Compare(left = "a5/left.uml", right = "a5/right.uml", ancestor = "a5/origin.uml")
	public void testChangesWithPseudoconflict(Comparison comparison) throws IOException {
		EList<Diff> diffs = comparison.getDifferences();
		Iterable<Diff> leftChanges = filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(LEFT)));
		Iterable<Diff> rightChanges = filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(RIGHT)));

		assertEquals(1, size(leftChanges));
		Diff leftChange = leftChanges.iterator().next();
		assertEquals(1, leftChange.getRefinedBy().size());
		assertTrue(leftChange.getRefinedBy().get(0) instanceof AttributeChange);
		assertEquals(DifferenceKind.CHANGE, leftChange.getKind());

		assertEquals(1, size(rightChanges));
		Diff rightChange = rightChanges.iterator().next();
		assertEquals(1, rightChange.getRefinedBy().size());
		assertTrue(rightChange.getRefinedBy().get(0) instanceof AttributeChange);
		assertEquals(DifferenceKind.CHANGE, rightChange.getKind());

		assertEquals(1, comparison.getConflicts().size());
		Conflict conflict = comparison.getConflicts().get(0);
		assertEquals(ConflictKind.PSEUDO, conflict.getKind());
		assertEquals(conflict, rightChange.getConflict());

	}

	/**
	 * <b>origin:</b> an activity with an input pin, with a lower and upper value <br>
	 * <b>left:</b> multiplicity lower value is changed to 1 <br>
	 * <b>right:</b> multiplicity lower and upper values are removed <br>
	 */
	@Compare(left = "a6/left.uml", right = "a6/right.uml", ancestor = "a6/origin.uml")
	public void testRemoveConflict(Comparison comparison) throws IOException {
		EList<Diff> diffs = comparison.getDifferences();
		ArrayList<Diff> leftChanges = Lists
				.newArrayList(filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(LEFT))));
		ArrayList<Diff> rightChanges = Lists
				.newArrayList(filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(RIGHT))));

		assertEquals(1, size(leftChanges));
		MultiplicityElementChange leftChange = (MultiplicityElementChange)leftChanges.iterator().next();
		assertEquals(1, leftChange.getRefinedBy().size());
		assertTrue(leftChange.getRefinedBy().get(0) instanceof AttributeChange);
		assertEquals(DifferenceKind.CHANGE, leftChange.getKind());

		assertEquals(2, size(rightChanges));

		MultiplicityElementChange rightChange1 = (MultiplicityElementChange)rightChanges.get(0);
		assertEquals(1, rightChange1.getRefinedBy().size());
		assertTrue(rightChange1.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.DELETE, rightChange1.getKind());

		MultiplicityElementChange rightChange2 = (MultiplicityElementChange)rightChanges.get(1);
		assertEquals(1, rightChange2.getRefinedBy().size());
		assertTrue(rightChange2.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.DELETE, rightChange2.getKind());

		assertEquals(1, comparison.getConflicts().size());
		Conflict conflict = comparison.getConflicts().get(0);
		assertEquals(ConflictKind.REAL, conflict.getKind());

		if (isLowerValueChange(rightChange1)) {
			assertTrue(isUpperValueChange(rightChange2));
			assertEquals(conflict, rightChange1.getConflict());
		} else {
			assertTrue(isUpperValueChange(rightChange1));
			assertTrue(isLowerValueChange(rightChange2));
			assertEquals(conflict, rightChange2.getConflict());
		}
	}

	/**
	 * <b>origin:</b> an activity with an input pin, with a lower and upper value <br>
	 * <b>left:</b> multiplicity upper value is removed <br>
	 * <b>right:</b> multiplicity lower value is changed to 1 <br>
	 */
	@Compare(left = "a7/left.uml", right = "a7/right.uml", ancestor = "a7/origin.uml")
	public void testRemoveNoConflict(Comparison comparison) throws IOException {
		EList<Diff> diffs = comparison.getDifferences();
		Iterable<Diff> leftChanges = filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(LEFT)));
		Iterable<Diff> rightChanges = filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(RIGHT)));

		assertEquals(1, size(leftChanges));
		MultiplicityElementChange leftChange = (MultiplicityElementChange)leftChanges.iterator().next();
		assertEquals(1, leftChange.getRefinedBy().size());
		assertTrue(leftChange.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.DELETE, leftChange.getKind());

		assertEquals(1, size(rightChanges));
		MultiplicityElementChange rightChange = (MultiplicityElementChange)rightChanges.iterator().next();
		assertEquals(1, rightChange.getRefinedBy().size());
		assertTrue(rightChange.getRefinedBy().get(0) instanceof AttributeChange);
		assertEquals(DifferenceKind.CHANGE, rightChange.getKind());

		assertEquals(0, comparison.getConflicts().size());

	}

	/**
	 * <b>origin:</b> an activity with an input pin, with a lower and upper value <br>
	 * <b>left:</b> multiplicity upper value is removed <br>
	 * <b>right:</b> multiplicity upper value is removed <br>
	 */
	@Compare(left = "a8/left.uml", right = "a8/right.uml", ancestor = "a8/origin.uml")
	public void testRemovePseudoConflict(Comparison comparison) throws IOException {
		EList<Diff> diffs = comparison.getDifferences();
		Iterable<Diff> leftChanges = filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(LEFT)));
		Iterable<Diff> rightChanges = filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(RIGHT)));

		assertEquals(1, size(leftChanges));
		assertEquals(1, size(rightChanges));

		MultiplicityElementChange leftChange = (MultiplicityElementChange)leftChanges.iterator().next();
		assertEquals(1, leftChange.getRefinedBy().size());
		assertTrue(leftChange.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.DELETE, leftChange.getKind());

		MultiplicityElementChange rightChange = (MultiplicityElementChange)rightChanges.iterator().next();
		assertEquals(1, rightChange.getRefinedBy().size());
		assertTrue(rightChange.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.DELETE, rightChange.getKind());

		assertEquals(1, comparison.getConflicts().size());
		Conflict conflict = comparison.getConflicts().get(0);
		assertEquals(ConflictKind.PSEUDO, conflict.getKind());

	}

	/**
	 * <b>origin:</b> an activity with an input pin, with an upper value <br>
	 * <b>left:</b> multiplicity upper value is removed <br>
	 * <b>right:</b> multiplicity lower value is added <br>
	 */
	@Compare(left = "a9/left.uml", right = "a9/right.uml", ancestor = "a9/origin.uml")
	public void testRemoveAndAddNoConflict(Comparison comparison) throws IOException {
		EList<Diff> diffs = comparison.getDifferences();
		Iterable<Diff> leftChanges = filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(LEFT)));
		Iterable<Diff> rightChanges = filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(RIGHT)));

		assertEquals(1, size(leftChanges));
		assertEquals(1, size(rightChanges));

		MultiplicityElementChange leftChange = (MultiplicityElementChange)leftChanges.iterator().next();
		assertEquals(1, leftChange.getRefinedBy().size());
		assertTrue(leftChange.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.DELETE, leftChange.getKind());

		MultiplicityElementChange rightChange = (MultiplicityElementChange)rightChanges.iterator().next();
		assertEquals(1, rightChange.getRefinedBy().size());
		assertTrue(rightChange.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, rightChange.getKind());

		assertEquals(0, comparison.getConflicts().size());
	}

	/**
	 * <b>origin:</b> an activity with an input pin, with an upper value <br>
	 * <b>left:</b> multiplicity upper (0) and lower (1) value are added<br>
	 * <b>right:</b> multiplicity upper (1) and lower (1) value are added<br>
	 * These changes should produce a real and a pseudo conflict for the same multiplicity change
	 */
	@Compare(left = "a10/left.uml", right = "a10/right.uml", ancestor = "a10/origin.uml")
	public void testRealAndPseudoConflict(Comparison comparison) throws IOException {
		EList<Diff> diffs = comparison.getDifferences();
		ArrayList<Diff> leftChanges = Lists
				.newArrayList(filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(LEFT))));
		ArrayList<Diff> rightChanges = Lists
				.newArrayList(filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(RIGHT))));

		assertEquals(2, size(leftChanges));
		assertEquals(2, size(rightChanges));

		MultiplicityElementChange leftChange1 = (MultiplicityElementChange)leftChanges.get(0);
		assertEquals(1, leftChange1.getRefinedBy().size());
		assertTrue(leftChange1.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, leftChange1.getKind());

		MultiplicityElementChange leftChange2 = (MultiplicityElementChange)leftChanges.get(1);
		assertEquals(1, leftChange2.getRefinedBy().size());
		assertTrue(leftChange2.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, leftChange2.getKind());

		MultiplicityElementChange rightChange1 = (MultiplicityElementChange)rightChanges.get(0);
		assertEquals(1, rightChange1.getRefinedBy().size());
		assertTrue(rightChange1.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, rightChange1.getKind());

		MultiplicityElementChange rightChange2 = (MultiplicityElementChange)rightChanges.get(1);
		assertEquals(1, rightChange2.getRefinedBy().size());
		assertTrue(rightChange2.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, rightChange2.getKind());

		assertEquals(2, comparison.getConflicts().size());
		Conflict conflict1 = comparison.getConflicts().get(0);
		Conflict conflict2 = comparison.getConflicts().get(1);

		if (conflict1.getKind() == ConflictKind.PSEUDO) {
			assertEquals(ConflictKind.REAL, conflict2.getKind());
		} else {
			assertEquals(ConflictKind.PSEUDO, conflict2.getKind());
		}

		if (isUpperValueChange(leftChange1)) {
			assertTrue(isLowerValueChange(leftChange2));
			assertNotNull(leftChange1.getConflict());
			assertEquals(ConflictKind.REAL, leftChange1.getConflict().getKind());
			assertNotNull(leftChange2.getConflict());
			assertEquals(ConflictKind.PSEUDO, leftChange2.getConflict().getKind());
		} else {
			assertTrue(isLowerValueChange(leftChange1));
			assertTrue(isUpperValueChange(leftChange2));
			assertNotNull(leftChange1.getConflict());
			assertEquals(ConflictKind.PSEUDO, leftChange1.getConflict().getKind());
			assertNotNull(leftChange2.getConflict());
			assertEquals(ConflictKind.REAL, leftChange2.getConflict().getKind());
		}

		if (isUpperValueChange(rightChange1)) {
			assertTrue(isLowerValueChange(rightChange2));
			assertNotNull(rightChange1.getConflict());
			assertEquals(ConflictKind.REAL, rightChange1.getConflict().getKind());
			assertNotNull(rightChange2.getConflict());
			assertEquals(ConflictKind.PSEUDO, rightChange2.getConflict().getKind());
		} else {
			assertTrue(isLowerValueChange(rightChange1));
			assertTrue(isUpperValueChange(rightChange2));
			assertNotNull(rightChange1.getConflict());
			assertEquals(ConflictKind.PSEUDO, rightChange1.getConflict().getKind());
			assertNotNull(rightChange2.getConflict());
			assertEquals(ConflictKind.REAL, rightChange2.getConflict().getKind());
		}

	}

	private boolean isLowerValueChange(MultiplicityElementChange multiplicityElementChange) {
		if (multiplicityElementChange.getRefinedBy().size() != 1) {
			return false;
		}
		return IS_LOWER_VALUE_CHANGE.apply(multiplicityElementChange.getRefinedBy().get(0));
	}

	private boolean isUpperValueChange(MultiplicityElementChange multiplicityElementChange) {
		if (multiplicityElementChange.getRefinedBy().size() != 1) {
			return false;
		}
		return IS_UPPER_VALUE_CHANGE.apply(multiplicityElementChange.getRefinedBy().get(0));
	}

	/**
	 * <b>origin:</b> an activity with an input pin, with a lower value <br>
	 * <b>left:</b> multiplicity lower value is deleted and upper value is added (0)<br>
	 * <b>right:</b> multiplicity upper value is added, with the same value as in the left change and the
	 * lower value is changed to a different value than the one in the left change<br>
	 * These changes should produce a real and a pseudo conflict for the same multiplicity change
	 */
	@Compare(left = "a11/left.uml", right = "a11/right.uml", ancestor = "a11/origin.uml")
	public void testRealAndPseudoConflictWithChangeAndDelete(Comparison comparison) throws IOException {
		EList<Diff> diffs = comparison.getDifferences();
		ArrayList<Diff> leftChanges = Lists
				.newArrayList(filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(LEFT))));
		ArrayList<Diff> rightChanges = Lists
				.newArrayList(filter(diffs, and(IS_MULTIPLICITY_CHANGE, fromSide(RIGHT))));

		assertEquals(2, size(leftChanges));
		assertEquals(2, size(rightChanges));

		MultiplicityElementChange leftAddChange;
		MultiplicityElementChange leftDeleteChange;

		if (leftChanges.get(0).getKind() == DifferenceKind.ADD) {
			leftAddChange = (MultiplicityElementChange)leftChanges.get(0);
			leftDeleteChange = (MultiplicityElementChange)leftChanges.get(1);
		} else {
			leftAddChange = (MultiplicityElementChange)leftChanges.get(1);
			leftDeleteChange = (MultiplicityElementChange)leftChanges.get(0);
		}

		assertEquals(1, leftAddChange.getRefinedBy().size());
		assertTrue(leftAddChange.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, leftAddChange.getKind());

		assertEquals(1, leftDeleteChange.getRefinedBy().size());
		assertTrue(leftDeleteChange.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.DELETE, leftDeleteChange.getKind());

		MultiplicityElementChange rightChange;
		MultiplicityElementChange rightAddChange;

		if (rightChanges.get(0).getKind() == DifferenceKind.ADD) {
			rightAddChange = (MultiplicityElementChange)rightChanges.get(0);
			rightChange = (MultiplicityElementChange)rightChanges.get(1);
		} else {
			rightAddChange = (MultiplicityElementChange)rightChanges.get(1);
			rightChange = (MultiplicityElementChange)rightChanges.get(0);
		}

		assertEquals(1, rightAddChange.getRefinedBy().size());
		assertTrue(rightAddChange.getRefinedBy().get(0) instanceof ReferenceChange);
		assertEquals(DifferenceKind.ADD, rightAddChange.getKind());

		assertEquals(1, rightChange.getRefinedBy().size());
		assertTrue(rightChange.getRefinedBy().get(0) instanceof AttributeChange);
		assertEquals(DifferenceKind.CHANGE, rightChange.getKind());

		assertEquals(2, comparison.getConflicts().size());
		Conflict conflict1 = comparison.getConflicts().get(0);
		Conflict conflict2 = comparison.getConflicts().get(1);

		if (conflict1.getKind() == ConflictKind.PSEUDO) {
			assertEquals(ConflictKind.REAL, conflict2.getKind());
		} else {
			assertEquals(ConflictKind.PSEUDO, conflict2.getKind());
		}
		assertEquals(ConflictKind.REAL, leftDeleteChange.getConflict().getKind());
		assertEquals(leftDeleteChange.getConflict(), rightChange.getConflict());
		assertEquals(ConflictKind.PSEUDO, leftAddChange.getConflict().getKind());
		assertEquals(leftAddChange.getConflict(), rightAddChange.getConflict());
	}

	// @Override
	// protected void registerPostProcessors(
	// org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor.Registry<String> postProcessorRegistry)
	// {
	// super.registerPostProcessors(postProcessorRegistry);
	// postProcessorRegistry.put(MultiplicityElementChangePostProcessor.class.getName(),
	// new TestPostProcessor.TestPostProcessorDescriptor(Pattern
	// .compile("http://www.eclipse.org/uml2/\\d\\.0\\.0/UML"), null, //$NON-NLS-1$
	// new MultiplicityElementChangePostProcessor(), 25));
	// }
}

Back to the top