Skip to main content
summaryrefslogtreecommitdiffstats
blob: a9675ecea05a020d116c345b9f8b03ba8693e95c (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
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
/*******************************************************************************
 * Copyright (c) 2012 Ericsson Research Canada
 * 
 * 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
 * 
 * Description:
 * 
 * This class implements a JUnit Test Case for the anomaly store on the 
 * latest Review commit 
 * 
 * Contributors:
 *   Jacques Bouthillier - Created for Mylyn Review R4E project
 *   
 ******************************************************************************/

package org.eclipse.mylyn.reviews.r4e.ui.tests.feature;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;

import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.mylyn.reviews.r4e.core.model.R4ECommentType;
import org.eclipse.mylyn.reviews.r4e.core.model.R4EFileVersion;
import org.eclipse.mylyn.reviews.r4e.core.model.R4ETextContent;
import org.eclipse.mylyn.reviews.r4e.core.model.R4ETextPosition;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.IR4EUIModelElement;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIAnomalyBasic;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIContent;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIFileContext;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIModelController;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIReviewBasic;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIReviewGroup;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIReviewItem;
import org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUITextPosition;
import org.eclipse.mylyn.reviews.r4e.ui.internal.navigator.ReviewNavigatorActionGroup;
import org.eclipse.mylyn.reviews.r4e.ui.tests.R4ETestSetup;
import org.eclipse.mylyn.reviews.r4e.ui.tests.proxy.R4EUITestMain;
import org.eclipse.mylyn.reviews.r4e.ui.tests.utils.TestConstants;
import org.eclipse.mylyn.reviews.r4e.ui.tests.utils.TestUtils;
import org.junit.After;
import org.junit.Before;

/**
 * @author Jacques Bouthillier
 * @version $Revision: 1.0 $
 */
@SuppressWarnings("restriction")
public class DuplicateAnomalyTests extends TestCase {

	// ------------------------------------------------------------------------
	// Constant
	// ------------------------------------------------------------------------

	private final static String FSECOND_COMMIT = "second Java Commit";

	private final static String FTHIRD_COMMIT = "third Java Commit";

	// ------------------------------------------------------------------------
	// Member variables
	// ------------------------------------------------------------------------

	private R4EUITestMain fProxy = null;

	private R4EUIReviewGroup fGroup = null;

	private String fGroupName = null;

	private R4EUIReviewBasic fReview = null;

	private R4EUIReviewItem fItem = null;

	private R4EUIReviewItem fItem2 = null;

	private R4EUIReviewItem fItem3 = null;

	private R4EUIReviewItem fItem4 = null;

	private R4EUIAnomalyBasic fLinkedAnomaly1 = null;

	private R4EUIAnomalyBasic fLinkedAnomaly2 = null;

	private final R4EUIAnomalyBasic fLinkedAnomaly3 = null;

	private R4EUIAnomalyBasic fExternalAnomaly = null;

	// ------------------------------------------------------------------------
	// Methods
	// ------------------------------------------------------------------------

	/**
	 * Method suite - Sets up the global test environment, if not already done at the suite level.
	 * 
	 * @return Test
	 */
	public static Test suite() {
		TestSuite suite = new TestSuite();
		suite.addTestSuite(DuplicateAnomalyTests.class);
		return new R4ETestSetup(suite);
	}

	/**
	 * Method setUp - Sets up the fixture, for example, open a network connection. This method is called before a test
	 * is executed.
	 * 
	 * @throws java.lang.Exception
	 */
	@Override
	@Before
	public void setUp() throws Exception {
		fProxy = R4EUITestMain.getInstance();
		createReviewGroups();
		if (((ReviewNavigatorActionGroup) R4EUIModelController.getNavigatorView().getActionSet()).isHideDeltasFilterSet()) {
			fProxy.getCommandProxy().toggleHideDeltasFilter();
		}
		createReviews();
	}

	/**
	 * Method tearDown
	 * 
	 * @throws java.lang.Exception
	 */
	@Override
	@After
	public void tearDown() throws Exception {
		fProxy = null;
	}

	/**
	 * Method testDuplicationAnomalyInAReviews
	 * 
	 * @throws CoreException
	 */
	public void testDuplicationAnomalyInAReviews() throws CoreException {
		TestUtils.waitForJobs();
		createReviewItems();
		createLinkedAnomalies();
		createExternalAnomalies();
		verifyAnomaly();
	}

	/**
	 * Method createReviewGroups
	 */
	private void createReviewGroups() {

		fGroup = null;

		//Create Review Group
		for (R4EUIReviewGroup group : R4EUIModelController.getRootElement().getGroups()) {
			if (group.getReviewGroup().getName().equals(TestConstants.REVIEW_GROUP_TEST_NAME)) {
				fGroup = group;
				fGroupName = group.getName();
				break;
			}
		}
		if (null == fGroup) {
			fGroup = fProxy.getReviewGroupProxy().createReviewGroup(
					TestUtils.FSharedFolder + File.separator + TestConstants.REVIEW_GROUP_TEST_NAME,
					TestConstants.REVIEW_GROUP_TEST_NAME, TestConstants.REVIEW_GROUP_TEST_DESCRIPTION,
					TestConstants.REVIEW_GROUP_TEST_ENTRY_CRITERIA, TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS,
					TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS, new String[0]);
			Assert.assertNotNull(fGroup);
			Assert.assertEquals(TestConstants.REVIEW_GROUP_TEST_NAME, fGroup.getReviewGroup().getName());
			Assert.assertEquals(new Path(TestUtils.FSharedFolder).toPortableString() + "/"
					+ TestConstants.REVIEW_GROUP_TEST_NAME, fGroup.getReviewGroup().getFolder());
			Assert.assertEquals(TestConstants.REVIEW_GROUP_TEST_DESCRIPTION, fGroup.getReviewGroup().getDescription());
			Assert.assertEquals(TestConstants.REVIEW_GROUP_TEST_ENTRY_CRITERIA, fGroup.getReviewGroup()
					.getDefaultEntryCriteria());
			for (int i = 0; i < TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS.length; i++) {
				Assert.assertEquals(TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS[i], fGroup.getReviewGroup()
						.getAvailableProjects()
						.get(i));
			}
			for (int i = 0; i < TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS.length; i++) {
				Assert.assertEquals(TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS[i], fGroup.getReviewGroup()
						.getAvailableComponents()
						.get(i));
			}
			fGroupName = fGroup.getName();
		}
	}

	/**
	 * Method createReviews
	 */
	private void createReviews() {

		if (!fGroup.isOpen()) {
			fProxy.getCommandProxy().openElement(fGroup);
		}
		Assert.assertTrue(fGroup.isOpen());

		fReview = fProxy.getReviewProxy().createReview(fGroup, TestConstants.REVIEW_TEST_TYPE_INFORMAL,
				TestConstants.REVIEW_DUPLICATE_NAME_INF, TestConstants.REVIEW_TEST_DESCRIPTION,
				TestConstants.REVIEW_TEST_DUE_DATE, TestConstants.REVIEW_TEST_PROJECT,
				TestConstants.REVIEW_TEST_COMPONENTS, TestConstants.REVIEW_TEST_ENTRY_CRITERIA,
				TestConstants.REVIEW_TEST_OBJECTIVES, TestConstants.REVIEW_TEST_REFERENCE_MATERIALS);
		Assert.assertNotNull(fReview);
		Assert.assertNotNull(fReview.getParticipantContainer());
		Assert.assertNotNull(fReview.getAnomalyContainer());
		Assert.assertEquals(TestConstants.REVIEW_TEST_TYPE_INFORMAL, fReview.getReview().getType());
		Assert.assertEquals(TestConstants.REVIEW_DUPLICATE_NAME_INF, fReview.getReview().getName());
		Assert.assertEquals(TestConstants.REVIEW_TEST_DESCRIPTION, fReview.getReview().getExtraNotes());
		Assert.assertEquals(TestConstants.REVIEW_TEST_PROJECT, fReview.getReview().getProject());
		for (int i = 0; i < TestConstants.REVIEW_TEST_COMPONENTS.length; i++) {
			Assert.assertEquals(TestConstants.REVIEW_TEST_COMPONENTS[i], fReview.getReview().getComponents().get(i));
		}
		Assert.assertEquals(TestConstants.REVIEW_TEST_ENTRY_CRITERIA, fReview.getReview().getEntryCriteria());
		Assert.assertEquals(TestConstants.REVIEW_TEST_OBJECTIVES, fReview.getReview().getObjectives());
		Assert.assertEquals(TestConstants.REVIEW_TEST_REFERENCE_MATERIALS, fReview.getReview().getReferenceMaterial());
		Assert.assertTrue(fReview.isOpen());
	}

	/**
	 * Method createReviewItems
	 */
	private void createReviewItems() throws CoreException {
		fItem = fProxy.getItemProxy().createCommitItem(TestUtils.FJavaIProject, 0);
		//close and re-open, so the validation takes de-serialized information
		String itemName = fItem.getName();
		fProxy.getCommandProxy().closeElement(fReview);
		fProxy.getCommandProxy().openElement(fReview);
		for (IR4EUIModelElement elem : fReview.getChildren()) {
			if (elem.getName().equals(itemName)) {
				fItem = (R4EUIReviewItem) elem;
			}
		}

		//Now validate
		Assert.assertNotNull(fItem);
		Assert.assertTrue(fItem.isOpen());
		Assert.assertEquals(R4EUIModelController.getReviewer(), fItem.getItem().getAddedById());
		Assert.assertEquals("The.committer@some.com", fItem.getItem().getAuthorRep());
		Assert.assertEquals(FSECOND_COMMIT, fItem.getItem().getDescription());
		Assert.assertEquals(4, fItem.getChildren().length);
		for (int i = 0; i < fItem.getChildren().length; i++) {
			if (((R4EUIFileContext) fItem.getChildren()[i]).getName().equals(TestUtils.JAVA_FILE1_PROJ_NAME)) {
				Assert.assertEquals(TestUtils.JAVA_FILE1_PROJ_NAME, fItem.getItem()
						.getFileContextList()
						.get(i)
						.getBase()
						.getName());
				Assert.assertEquals(TestUtils.JAVA_FILE1_PROJ_NAME, fItem.getItem()
						.getFileContextList()
						.get(i)
						.getTarget()
						.getName());
				Assert.assertEquals(606, ((R4ETextPosition) fItem.getItem()
						.getFileContextList()
						.get(i)
						.getDeltas()
						.get(0)
						.getTarget()
						.getLocation()).getStartPosition());
				Assert.assertEquals(25,
						((R4ETextPosition) fItem.getItem()
								.getFileContextList()
								.get(i)
								.getDeltas()
								.get(0)
								.getTarget()
								.getLocation()).getLength());
				Assert.assertEquals(665, ((R4ETextPosition) fItem.getItem()
						.getFileContextList()
						.get(i)
						.getDeltas()
						.get(1)
						.getTarget()
						.getLocation()).getStartPosition());
				Assert.assertEquals(63,
						((R4ETextPosition) fItem.getItem()
								.getFileContextList()
								.get(i)
								.getDeltas()
								.get(1)
								.getTarget()
								.getLocation()).getLength());
				Assert.assertEquals(733, ((R4ETextPosition) fItem.getItem()
						.getFileContextList()
						.get(i)
						.getDeltas()
						.get(2)
						.getTarget()
						.getLocation()).getStartPosition());
				Assert.assertEquals(61,
						((R4ETextPosition) fItem.getItem()
								.getFileContextList()
								.get(i)
								.getDeltas()
								.get(2)
								.getTarget()
								.getLocation()).getLength());
			} else if (((R4EUIFileContext) fItem.getChildren()[i]).getName().equals(TestUtils.JAVA_FILE4_PROJ_NAME)) {
				Assert.assertNull(fItem.getItem().getFileContextList().get(i).getBase());
				Assert.assertEquals(TestUtils.JAVA_FILE4_PROJ_NAME, fItem.getItem()
						.getFileContextList()
						.get(i)
						.getTarget()
						.getName());
			} else if (((R4EUIFileContext) fItem.getChildren()[i]).getName().equals(TestUtils.JAVA_FILE3_PROJ_NAME)) {
				Assert.assertNull(fItem.getItem().getFileContextList().get(i).getBase());
				Assert.assertEquals(TestUtils.JAVA_FILE3_PROJ_NAME, fItem.getItem()
						.getFileContextList()
						.get(i)
						.getTarget()
						.getName());
			} else if (((R4EUIFileContext) fItem.getChildren()[i]).getName().equals(TestUtils.JAVA_FILE2_PROJ_NAME)) {
				Assert.assertEquals(TestUtils.JAVA_FILE2_PROJ_NAME, fItem.getItem()
						.getFileContextList()
						.get(i)
						.getBase()
						.getName());
				Assert.assertNull(fItem.getItem().getFileContextList().get(i).getTarget());
			}
		}

		fItem2 = fProxy.getItemProxy().createManualTreeItem(TestUtils.FJavaFile3);
		Assert.assertNotNull(fItem2);
		Assert.assertEquals(R4EUIModelController.getReviewer(), fItem2.getItem().getAddedById());
		Assert.assertEquals(TestUtils.JAVA_FILE3_PROJ_NAME, fItem2.getItem()
				.getFileContextList()
				.get(0)
				.getBase()
				.getName());
		Assert.assertEquals(TestUtils.JAVA_FILE3_PROJ_NAME, fItem2.getItem()
				.getFileContextList()
				.get(0)
				.getTarget()
				.getName());
		Assert.assertEquals(0, ((R4ETextPosition) fItem2.getItem()
				.getFileContextList()
				.get(0)
				.getDeltas()
				.get(0)
				.getTarget()
				.getLocation()).getStartPosition());
		Assert.assertEquals(755, ((R4ETextPosition) fItem2.getItem()
				.getFileContextList()
				.get(0)
				.getDeltas()
				.get(0)
				.getTarget()
				.getLocation()).getLength());

		fItem3 = fProxy.getItemProxy().createManualTextItem(TestUtils.FJavaFile4, 50, 20);
		Assert.assertNotNull(fItem3);
		Assert.assertEquals(R4EUIModelController.getReviewer(), fItem3.getItem().getAddedById());
		Assert.assertEquals(TestUtils.JAVA_FILE4_PROJ_NAME, fItem3.getItem()
				.getFileContextList()
				.get(0)
				.getBase()
				.getName());
		Assert.assertEquals(TestUtils.JAVA_FILE4_PROJ_NAME, fItem3.getItem()
				.getFileContextList()
				.get(0)
				.getTarget()
				.getName());
		Assert.assertEquals(50, ((R4ETextPosition) fItem3.getItem()
				.getFileContextList()
				.get(0)
				.getDeltas()
				.get(0)
				.getTarget()
				.getLocation()).getStartPosition());
		Assert.assertEquals(20, ((R4ETextPosition) fItem3.getItem()
				.getFileContextList()
				.get(0)
				.getDeltas()
				.get(0)
				.getTarget()
				.getLocation()).getLength());

		try {
			amendInitialCommit();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}
		fItem4 = fProxy.getItemProxy().createCommitItem(TestUtils.FJavaIProject, 0);

		//Validate the last Commit
		/************************************************************** */
		/*                                                              */
		/* This commit is an amended from the other commit              */
		/*   JAVA_FILE1_PROJ_NAME = same file                           */
		/*   JAVA_FILE2_PROJ_NAME = same deleted file test base id      */
		/*   JAVA_FILE3_PROJ_NAME = different file                      */
		/*   JAVA_FILE4_PROJ_NAME = same file                           */
		/*                                                              */
		/************************************************************** */
		Assert.assertNotNull(fItem4);
		Assert.assertTrue(fItem4.isOpen());
		Assert.assertEquals(R4EUIModelController.getReviewer(), fItem4.getItem().getAddedById());
		Assert.assertEquals("The.committer@some.com", fItem4.getItem().getAuthorRep());
		Assert.assertEquals(FTHIRD_COMMIT, fItem4.getItem().getDescription());
		Assert.assertEquals(4, fItem4.getChildren().length);
		for (int i = 0; i < fItem4.getChildren().length; i++) {
			if (((R4EUIFileContext) fItem4.getChildren()[i]).getName().equals(TestUtils.JAVA_FILE1_PROJ_NAME)) {
				String testfileVersion = null;
				R4EFileVersion origFileVersion = null;
				for (int j = 0; j < fItem.getChildren().length; j++) {
					if (((R4EUIFileContext) fItem.getChildren()[j]).getName().equals(TestUtils.JAVA_FILE1_PROJ_NAME)) {
						origFileVersion = fItem.getItem().getFileContextList().get(j).getTarget();
						if (origFileVersion != null) {
							testfileVersion = origFileVersion.getLocalVersionID();
							break;
						}
					}

				}
				R4EFileVersion item4FileVersion = fItem4.getItem().getFileContextList().get(i).getTarget();
				if (item4FileVersion != null) {
					Assert.assertEquals(testfileVersion, item4FileVersion.getLocalVersionID());
				}

				Assert.assertEquals(TestUtils.JAVA_FILE1_PROJ_NAME, fItem4.getItem()
						.getFileContextList()
						.get(i)
						.getBase()
						.getName());
				Assert.assertEquals(606, ((R4ETextPosition) fItem4.getItem()
						.getFileContextList()
						.get(i)
						.getDeltas()
						.get(0)
						.getTarget()
						.getLocation()).getStartPosition());
				Assert.assertEquals(25, ((R4ETextPosition) fItem4.getItem()
						.getFileContextList()
						.get(i)
						.getDeltas()
						.get(0)
						.getTarget()
						.getLocation()).getLength());
				Assert.assertEquals(665, ((R4ETextPosition) fItem4.getItem()
						.getFileContextList()
						.get(i)
						.getDeltas()
						.get(1)
						.getTarget()
						.getLocation()).getStartPosition());
				Assert.assertEquals(63, ((R4ETextPosition) fItem4.getItem()
						.getFileContextList()
						.get(i)
						.getDeltas()
						.get(1)
						.getTarget()
						.getLocation()).getLength());
				Assert.assertEquals(733, ((R4ETextPosition) fItem4.getItem()
						.getFileContextList()
						.get(i)
						.getDeltas()
						.get(2)
						.getTarget()
						.getLocation()).getStartPosition());
				Assert.assertEquals(61, ((R4ETextPosition) fItem4.getItem()
						.getFileContextList()
						.get(i)
						.getDeltas()
						.get(2)
						.getTarget()
						.getLocation()).getLength());
			} else if (((R4EUIFileContext) fItem4.getChildren()[i]).getName().equals(TestUtils.JAVA_FILE4_PROJ_NAME)) {
				Assert.assertNull(fItem4.getItem().getFileContextList().get(i).getBase());
				String testfileVersion = null;
				R4EFileVersion origFileVersion = null;
				for (int j = 0; j < fItem.getChildren().length; j++) {
					if (((R4EUIFileContext) fItem.getChildren()[j]).getName().equals(TestUtils.JAVA_FILE4_PROJ_NAME)) {
						origFileVersion = fItem.getItem().getFileContextList().get(j).getTarget();
						if (origFileVersion != null) {
							testfileVersion = origFileVersion.getLocalVersionID();
							break;
						}
					}

				}
				R4EFileVersion item4FileVersion = fItem4.getItem().getFileContextList().get(i).getTarget();
				if (item4FileVersion != null) {
					Assert.assertEquals(testfileVersion, item4FileVersion.getLocalVersionID());
				}

				Assert.assertEquals(TestUtils.JAVA_FILE4_PROJ_NAME, fItem4.getItem()
						.getFileContextList()
						.get(i)
						.getTarget()
						.getName());
			} else if (((R4EUIFileContext) fItem4.getChildren()[i]).getName().equals(TestUtils.JAVA_FILE3_PROJ_NAME)) {

				String testfileVersion = null;
				R4EFileVersion origFileVersion = null;
				for (int j = 0; j < fItem.getChildren().length; j++) {
					if (((R4EUIFileContext) fItem.getChildren()[j]).getName().equals(TestUtils.JAVA_FILE3_PROJ_NAME)) {
						origFileVersion = fItem.getItem().getFileContextList().get(j).getTarget();
						if (origFileVersion != null) {
							testfileVersion = origFileVersion.getLocalVersionID();
							break;
						}
					}

				}
				R4EFileVersion item4FileVersion = fItem4.getItem().getFileContextList().get(i).getTarget();
				if (item4FileVersion != null) {
					Assert.assertNotSame(testfileVersion, item4FileVersion.getLocalVersionID());
				}

				Assert.assertNull(fItem4.getItem().getFileContextList().get(i).getBase());
				Assert.assertEquals(TestUtils.JAVA_FILE3_PROJ_NAME, fItem4.getItem()
						.getFileContextList()
						.get(i)
						.getTarget()
						.getName());
			} else if (((R4EUIFileContext) fItem4.getChildren()[i]).getName().equals(TestUtils.JAVA_FILE2_PROJ_NAME)) {
				String testfileVersion = null;
				R4EFileVersion origFileVersion = null;
				//This JAVA_FILE2_PROJ_NAME is deleted, so no target, we just verify the base instead
				for (int j = 0; j < fItem.getChildren().length; j++) {
					if (((R4EUIFileContext) fItem.getChildren()[j]).getName().equals(TestUtils.JAVA_FILE2_PROJ_NAME)) {
						origFileVersion = fItem.getItem().getFileContextList().get(j).getBase();
						if (origFileVersion != null) {
							testfileVersion = origFileVersion.getLocalVersionID();
							break;
						}
					}

				}
				R4EFileVersion item4FileVersion = fItem4.getItem().getFileContextList().get(i).getBase();
				if (item4FileVersion != null) {
					Assert.assertEquals(testfileVersion, item4FileVersion.getLocalVersionID());
				}

				Assert.assertEquals(TestUtils.JAVA_FILE2_PROJ_NAME, fItem4.getItem()
						.getFileContextList()
						.get(i)
						.getBase()
						.getName());
				Assert.assertNull(fItem4.getItem().getFileContextList().get(i).getTarget());
			}
		}
	}

	/**
	 * Method createLinkedAnomalies
	 */
	private void createLinkedAnomalies() {

		int sizeItem = fItem.getChildren().length;
		R4EUIContent content = null;
		for (int i = 0; i < sizeItem; i++) {
			if (((R4EUIFileContext) fItem.getChildren()[i]).getName().equals(TestUtils.JAVA_FILE1_PROJ_NAME)) {
				//Create an anomaly for JAVA_FILE1_PROJ_NAME 
				//Same file, so the anomaly should only show in the last commit
				content = fItem.getFileContexts().get(i).getContentsContainerElement().getContentsList().get(0);
				fLinkedAnomaly1 = fProxy.getAnomalyProxy().createLinkedAnomaly(content,
						TestConstants.LINKED_ANOMALY_TEST_TITLE, TestConstants.LINKED_ANOMALY_TEST_DESCRIPTION,
						TestConstants.ANOMALY_TEST_CLASS_IMPROVEMENT, TestConstants.ANOMALY_TEST_RANK_MAJOR,
						TestConstants.ANOMALY_TEST_DUE_DATE, TestConstants.PARTICIPANT_ASSIGN_TO, null);
				Assert.assertNotNull(fLinkedAnomaly1);
				Assert.assertEquals(TestConstants.LINKED_ANOMALY_TEST_TITLE, fLinkedAnomaly1.getAnomaly().getTitle());
				Assert.assertEquals(TestConstants.LINKED_ANOMALY_TEST_DESCRIPTION, fLinkedAnomaly1.getAnomaly()
						.getDescription());
				Assert.assertEquals(TestConstants.ANOMALY_TEST_CLASS_IMPROVEMENT,
						((R4ECommentType) fLinkedAnomaly1.getAnomaly().getType()).getType());
				Assert.assertEquals(TestConstants.ANOMALY_TEST_RANK_MAJOR, fLinkedAnomaly1.getAnomaly().getRank());
				Assert.assertEquals(TestConstants.ANOMALY_TEST_DUE_DATE, fLinkedAnomaly1.getAnomaly().getDueDate());
				Assert.assertEquals(
						((R4EUITextPosition) content.getPosition()).getOffset(),
						((R4ETextPosition) ((R4ETextContent) fLinkedAnomaly1.getAnomaly().getLocation().get(0)).getLocation()).getStartPosition());
				Assert.assertEquals(
						((R4EUITextPosition) content.getPosition()).getLength(),
						((R4ETextPosition) ((R4ETextContent) fLinkedAnomaly1.getAnomaly().getLocation().get(0)).getLocation()).getLength());
				Assert.assertEquals(TestConstants.PARTICIPANT_ASSIGN_TO, fLinkedAnomaly1.getAnomaly()
						.getAssignedTo()
						.get(0));
				//Add a second anomaly
				if (fItem.getFileContexts().get(i).getContentsContainerElement().getContentsList().size() >= 3) {
					content = fItem.getFileContexts().get(i).getContentsContainerElement().getContentsList().get(2);
					fLinkedAnomaly2 = fProxy.getAnomalyProxy().createLinkedAnomaly(content,
							TestConstants.LINKED_ANOMALY_TEST_TITLE, TestConstants.LINKED_ANOMALY_TEST_DESCRIPTION,
							TestConstants.ANOMALY_TEST_CLASS_IMPROVEMENT, TestConstants.ANOMALY_TEST_RANK_MAJOR,
							TestConstants.ANOMALY_TEST_DUE_DATE, TestConstants.PARTICIPANT_ASSIGN_TO, null);
					Assert.assertNotNull(fLinkedAnomaly2);
					Assert.assertEquals(TestConstants.LINKED_ANOMALY_TEST_TITLE, fLinkedAnomaly2.getAnomaly()
							.getTitle());
					Assert.assertEquals(TestConstants.LINKED_ANOMALY_TEST_DESCRIPTION, fLinkedAnomaly2.getAnomaly()
							.getDescription());
					Assert.assertEquals(TestConstants.ANOMALY_TEST_CLASS_IMPROVEMENT,
							((R4ECommentType) fLinkedAnomaly2.getAnomaly().getType()).getType());
					Assert.assertEquals(TestConstants.ANOMALY_TEST_RANK_MAJOR, fLinkedAnomaly2.getAnomaly().getRank());
					Assert.assertEquals(TestConstants.ANOMALY_TEST_DUE_DATE, fLinkedAnomaly2.getAnomaly().getDueDate());
					Assert.assertEquals(
							((R4EUITextPosition) content.getPosition()).getOffset(),
							((R4ETextPosition) ((R4ETextContent) fLinkedAnomaly2.getAnomaly().getLocation().get(0)).getLocation()).getStartPosition());
					Assert.assertEquals(
							((R4EUITextPosition) content.getPosition()).getLength(),
							((R4ETextPosition) ((R4ETextContent) fLinkedAnomaly2.getAnomaly().getLocation().get(0)).getLocation()).getLength());
					Assert.assertEquals(TestConstants.PARTICIPANT_ASSIGN_TO, fLinkedAnomaly2.getAnomaly()
							.getAssignedTo()
							.get(0));

				}
			}

			//Add anomaly on the modified file now
			//Create an anomaly with the file in the first commit and at the end verify the count

//			if (((R4EUIFileContext) fItem.getChildren()[i]).getName().equals(TestUtils.JAVA_FILE3_PROJ_NAME)) {
//				//Create an anomaly for JAVA_FILE3_PROJ_NAME 
//				//Different file, so the anomaly should only show in the initial commit
//	//Crash contenmt null 			content = fItem.getFileContexts().get(i).getContentsContainerElement().getContentsList().get(0);
//				fLinkedAnomaly3 = fProxy.getAnomalyProxy().createLinkedAnomaly(content,
//						TestConstants.LINKED_ANOMALY_TEST_TITLE, TestConstants.LINKED_ANOMALY_TEST_DESCRIPTION,
//						TestConstants.ANOMALY_TEST_CLASS_IMPROVEMENT, TestConstants.ANOMALY_TEST_RANK_MAJOR,
//						TestConstants.ANOMALY_TEST_DUE_DATE, TestConstants.PARTICIPANT_ASSIGN_TO, null);
//				Assert.assertNotNull(fLinkedAnomaly3);
//				Assert.assertEquals(TestConstants.LINKED_ANOMALY_TEST_TITLE, fLinkedAnomaly3.getAnomaly().getTitle());
//				Assert.assertEquals(TestConstants.LINKED_ANOMALY_TEST_DESCRIPTION, fLinkedAnomaly3.getAnomaly()
//						.getDescription());
//				Assert.assertEquals(TestConstants.ANOMALY_TEST_CLASS_IMPROVEMENT,
//						((R4ECommentType) fLinkedAnomaly3.getAnomaly().getType()).getType());
//				Assert.assertEquals(TestConstants.ANOMALY_TEST_RANK_MAJOR, fLinkedAnomaly3.getAnomaly().getRank());
//				Assert.assertEquals(TestConstants.ANOMALY_TEST_DUE_DATE, fLinkedAnomaly3.getAnomaly().getDueDate());
//				Assert.assertEquals(
//						((R4EUITextPosition) content.getPosition()).getOffset(),
//						((R4ETextPosition) ((R4ETextContent) fLinkedAnomaly3.getAnomaly().getLocation().get(0)).getLocation()).getStartPosition());
//				Assert.assertEquals(
//						((R4EUITextPosition) content.getPosition()).getLength(),
//						((R4ETextPosition) ((R4ETextContent) fLinkedAnomaly3.getAnomaly().getLocation().get(0)).getLocation()).getLength());
//				Assert.assertEquals(TestConstants.PARTICIPANT_ASSIGN_TO, fLinkedAnomaly3.getAnomaly()
//						.getAssignedTo()
//						.get(0));
//			}

		}
//		fProxy.getCommandProxy().closeElement(fReview);
//		fProxy.getCommandProxy().openElement(fReview);
//		int test = 0;

	}

	/**
	 * Method createExternalAnomalies
	 */
	private void createExternalAnomalies() {

		//Create an external  from the last commit
		fExternalAnomaly = fProxy.getAnomalyProxy().createExternalAnomaly(TestUtils.FJavaFile3,
				TestConstants.EXTERNAL_ANOMALY_TEST_TITLE, TestConstants.EXTERNAL_ANOMALY_TEST_DESCRIPTION,
				TestConstants.ANOMALY_TEST_CLASS_QUESTION, TestConstants.ANOMALY_TEST_RANK_MINOR,
				TestConstants.ANOMALY_TEST_DUE_DATE, TestConstants.PARTICIPANT_ASSIGN_TO, null);
		Assert.assertNotNull(fExternalAnomaly);
		Assert.assertEquals(TestConstants.EXTERNAL_ANOMALY_TEST_TITLE, fExternalAnomaly.getAnomaly().getTitle());
		Assert.assertEquals(TestConstants.EXTERNAL_ANOMALY_TEST_DESCRIPTION, fExternalAnomaly.getAnomaly()
				.getDescription());
		Assert.assertEquals(TestConstants.ANOMALY_TEST_CLASS_QUESTION, ((R4ECommentType) fExternalAnomaly.getAnomaly()
				.getType()).getType());
		Assert.assertEquals(TestConstants.ANOMALY_TEST_RANK_MINOR, fExternalAnomaly.getAnomaly().getRank());
		Assert.assertEquals(TestConstants.ANOMALY_TEST_DUE_DATE, fExternalAnomaly.getAnomaly().getDueDate());
		Assert.assertEquals(
				0,
				((R4ETextPosition) ((R4ETextContent) fExternalAnomaly.getAnomaly().getLocation().get(0)).getLocation()).getStartPosition());
		Assert.assertEquals(764, ((R4ETextPosition) ((R4ETextContent) fExternalAnomaly.getAnomaly()
				.getLocation()
				.get(0)).getLocation()).getLength());

	}

	/**
	 * Look where the anomaly are stored now after re-opening the review
	 */
	private void verifyAnomaly() {

		String comit1 = fItem.getName();
		String commit2 = fItem4.getName();
		fProxy.getCommandProxy().closeElement(fReview);
		fProxy.getCommandProxy().openElement(fReview);
		for (IR4EUIModelElement elem : fReview.getChildren()) {
			if (elem.getName().equals(comit1)) {
				fItem = (R4EUIReviewItem) elem;
			} else if (elem.getName().equals(commit2)) {
				fItem4 = (R4EUIReviewItem) elem;
			}

		}

		int sizeItem = fItem.getChildren().length;
		int anomalyCount1 = 0;
		for (int i = 0; i < sizeItem; i++) {

			if (((R4EUIFileContext) fItem.getChildren()[i]).getName().equals(TestUtils.JAVA_FILE1_PROJ_NAME)) {
				anomalyCount1 = fItem.getFileContexts().get(i).getNumAnomalies();
			}
		}

		int anomalyCount4 = 0;
		for (int i = 0; i < fItem4.getChildren().length; i++) {
			if (((R4EUIFileContext) fItem4.getChildren()[i]).getName().equals(TestUtils.JAVA_FILE1_PROJ_NAME)) {
				anomalyCount4 = fItem4.getFileContexts().get(i).getNumAnomalies();
			}
		}
		//Verify the anomaly count under the appropriate file
		Assert.assertEquals(0, anomalyCount1);
		Assert.assertEquals(2, anomalyCount4);

	}

	/**
	 * Adjust the modified file from the last commit
	 * 
	 * @throws CoreException
	 * @throws IOException
	 * @throws URISyntaxException
	 */
	private static void amendInitialCommit() throws CoreException, IOException, URISyntaxException {

		//Update files ( Modify File 3 since last commit)
		TestUtils.FJavaFile3 = TestUtils.changeContentOfFile(TestUtils.FJavaFile3, TestUtils.JAVA_FILE3_EXT_MOD_PATH);

		//Commit modifications
		Collection<String> commitFileList = new ArrayList<String>();
		commitFileList.add(TestUtils.FJavaFile3.getProjectRelativePath().toOSString());

		TestUtils.commitAmendFiles(TestUtils.FJavaIProject, TestUtils.FJavaRepository, FTHIRD_COMMIT, commitFileList);
	}

}

Back to the top