Skip to main content
summaryrefslogtreecommitdiffstats
blob: c376aca2bf602125db6928d885d19adf5f8281d2 (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
/*******************************************************************************
 * Copyright (c) 2013 Boeing.
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.client.integration.tests.integration.skynet.core;

import static org.eclipse.osee.client.demo.DemoChoice.OSEE_CLIENT_DEMO;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.client.demo.DemoBranches;
import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule;
import org.eclipse.osee.client.test.framework.OseeLogMonitorRule;
import org.eclipse.osee.framework.core.client.ClientSessionManager;
import org.eclipse.osee.framework.core.data.IArtifactToken;
import org.eclipse.osee.framework.core.data.TokenFactory;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.MergeBranch;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.artifact.PurgeArtifacts;
import org.eclipse.osee.framework.skynet.core.artifact.operation.FinishUpdateBranchOperation;
import org.eclipse.osee.framework.skynet.core.artifact.operation.UpdateBranchOperation;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.skynet.core.artifact.update.ConflictResolverOperation;
import org.eclipse.osee.framework.skynet.core.conflict.ConflictManagerExternal;
import org.eclipse.osee.framework.ui.skynet.commandHandlers.branch.commit.CommitHandler;
import org.eclipse.osee.framework.ui.skynet.util.MergeInProgressHandler;
import org.eclipse.osee.framework.ui.skynet.util.RebaselineInProgressHandler;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.MockitoAnnotations;

/**
 * @author Angel Avila
 */
public class MergeManagerTest {

   @Rule
   public OseeClientIntegrationRule integration = new OseeClientIntegrationRule(OSEE_CLIENT_DEMO);

   @Rule
   public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule();

   private Branch workingBranch;
   private static Artifact newArt;
   public static IArtifactToken NewArtifactToken = TokenFactory.createArtifactToken("AAABER+3yR4A8O7WYQ+Xaw",
      "ART_NAME", CoreArtifactTypes.SoftwareRequirement);

   private static final int DELETE_MERGE = 2;

   @Before
   public void setUp() throws Exception {
      MockitoAnnotations.initMocks(this);

      if (newArt == null) {
         assertFalse("This test can not be run on Production", ClientSessionManager.isProductionDataStore());
         newArt = ArtifactTypeManager.addArtifact(NewArtifactToken, DemoBranches.SAW_Bld_1);
         newArt.addAttribute(CoreAttributeTypes.WordTemplateContent, "Base Edit");
         newArt.persist("Base Edit");
         //wait for creation of artifact and persist to go through
         Thread.sleep(5000);
      }

      workingBranch = BranchManager.createWorkingBranch(DemoBranches.SAW_Bld_1, "Working Branch");
      // wait for branch creation
      Thread.sleep(3000);
      Artifact artOnWorking = ArtifactQuery.getArtifactFromToken(NewArtifactToken, workingBranch);
      artOnWorking.setSoleAttributeValue(CoreAttributeTypes.WordTemplateContent, "Working Edit");
      artOnWorking.persist("Working Edit");

      // Create conflict by editing on Parent as well
      newArt.setSoleAttributeValue(CoreAttributeTypes.WordTemplateContent, "Parent Edit");
      newArt.persist("Parent Edit");
      // wait for persists
      Thread.sleep(1000);
   }

   @After
   public void tearDown() throws OseeCoreException, InterruptedException {
      List<MergeBranch> mergeBranches = BranchManager.getMergeBranches(workingBranch);
      for (MergeBranch mergeBranch : mergeBranches) {
         BranchManager.purgeBranch(mergeBranch);
      }

      Artifact artOnWorking = ArtifactQuery.getArtifactFromToken(NewArtifactToken, workingBranch);
      Operations.executeWorkAndCheckStatus(new PurgeArtifacts(Collections.singleton(artOnWorking)));

      BranchManager.purgeBranch(workingBranch);
      Thread.sleep(1000);
   }

   @Test
   public void testRebaselineWithConflictsAbandon() throws Exception {

      ConflictResolverOperation resolverOperation =
         new ConflictResolverOperation("Test Resolver", MergeManagerTest.class.getCanonicalName()) {

            @Override
            protected void doWork(IProgressMonitor monitor) throws Exception {
               assertTrue("This code should have been executed since there should be conflicts.", wasExecuted());
            }
         };
      UpdateBranchOperation update = new UpdateBranchOperation(workingBranch, resolverOperation);
      Operations.executeAsJob(update, true);
      // wait on operation
      Thread.sleep(1000);
      assertTrue("No Merge Branch was created", BranchManager.getMergeBranches(workingBranch).size() == 1);
      assertTrue("Branch is not in Rebaseline In Progress", workingBranch.getBranchState().isRebaselineInProgress());

      // Shouldn't be allowed to commit
      boolean committed =
         CommitHandler.commitBranch(new ConflictManagerExternal(DemoBranches.SAW_Bld_2, workingBranch), false, true);
      assertTrue("Branch Committed while in Rebaseline In Progress", !committed);
      assertTrue("An additional Merge Branch was created", BranchManager.getMergeBranches(workingBranch).size() == 1);

      // Abandon 
      RebaselineInProgressHandler.cancelCurrentUpdate(workingBranch, true);
      // wait on operation
      Thread.sleep(1000);
      BranchManager.persist(workingBranch);

      // Now we can commit
      committed =
         CommitHandler.commitBranch(new ConflictManagerExternal(DemoBranches.SAW_Bld_2, workingBranch), false, true);
      assertTrue("Branch should have been comitted", committed);

      // make sure we can't rebase now since we've done a commit
      update = new UpdateBranchOperation(workingBranch, resolverOperation);
      Operations.executeAsJob(update, true);
      assertTrue(
         "Branch should not be updating",
         !workingBranch.getBranchState().isRebaselineInProgress() && !workingBranch.getBranchState().isRebaselineInProgress());

      // Purge art from SAW 2 since we did a commit
      Artifact artOnSaw2 = ArtifactQuery.getArtifactFromToken(NewArtifactToken, DemoBranches.SAW_Bld_2);
      Operations.executeWorkAndCheckStatus(new PurgeArtifacts(Collections.singleton(artOnSaw2)));
      // wait on operation
      Thread.sleep(1000);

   }

   @Test
   public void testMultipleRebaselineRequests() throws Exception {
      ConflictResolverOperation resolverOperation =
         new ConflictResolverOperation("Test Resolver", MergeManagerTest.class.getCanonicalName()) {

            @Override
            protected void doWork(IProgressMonitor monitor) throws Exception {
               assertTrue("This code should have been executed since there should be conflicts.", wasExecuted());
            }
         };

      UpdateBranchOperation update = new UpdateBranchOperation(workingBranch, resolverOperation);
      Operations.executeAsJob(update, true);
      // wait on operation
      Thread.sleep(1000);
      List<MergeBranch> mergeBranches = BranchManager.getMergeBranches(workingBranch);
      Branch branchForUpdate = mergeBranches.get(0).getDestinationBranch();
      assertTrue("No Merge Branch was created", mergeBranches.size() == 1);
      assertTrue("Branch is not in Rebaseline In Progress", workingBranch.getBranchState().isRebaselineInProgress());

      // Try doing another Rebaseline, no addtional branches should be created
      UpdateBranchOperation update2 = new UpdateBranchOperation(workingBranch, resolverOperation);
      Operations.executeAsJob(update2, true);
      // wait on operation
      Thread.sleep(1000);
      List<MergeBranch> mergeBranchesSecondAttempt = BranchManager.getMergeBranches(workingBranch);
      Branch branchForUpdateSecondAttempt = mergeBranchesSecondAttempt.get(0).getDestinationBranch();
      assertTrue("Branch is not in Rebaseline In Progress", workingBranch.getBranchState().isRebaselineInProgress());
      assertTrue("Addional Merge Branch was created during second rebaseline attempt", mergeBranches.size() == 1);
      assertTrue("Addional Branch for Update was created during second rebaseline attempt",
         branchForUpdate.equals(branchForUpdateSecondAttempt));

      // Clean up this test, mainly the update branch
      RebaselineInProgressHandler.cancelCurrentUpdate(workingBranch, true);
   }

   @Test
   public void testRebaselineWithConflictsFinish() throws Exception {
      ConflictResolverOperation resolverOperation =
         new ConflictResolverOperation("Test Resolver", MergeManagerTest.class.getCanonicalName()) {

            @Override
            protected void doWork(IProgressMonitor monitor) throws Exception {
               assertTrue("This code should have been executed since there should be conflicts.", wasExecuted());
            }
         };

      UpdateBranchOperation update = new UpdateBranchOperation(workingBranch, resolverOperation);
      Operations.executeAsJob(update, true);
      // wait on operation
      Thread.sleep(1000);
      Branch branchForUpdate = BranchManager.getFirstMergeBranch(workingBranch).getDestinationBranch(); // this will be future working branch

      // Shouldn't be allowed to commit working branch
      boolean committed =
         CommitHandler.commitBranch(new ConflictManagerExternal(DemoBranches.SAW_Bld_2, workingBranch), false, true);
      assertTrue("Branch Committed while in Rebaseline In Progress", !committed);

      // Finish Rebaseline
      FinishUpdateBranchOperation finishUpdateOperation =
         new FinishUpdateBranchOperation(resolverOperation.getConflictManager(), true, true);
      Operations.executeAsJob(finishUpdateOperation, true);
      // wait on operation
      Thread.sleep(1000);

      // Make sure the state is now Rebaselined
      assertTrue("Branch is not in Rebaselined", workingBranch.getBranchState().isRebaselined());

      // Shouldn't be allowed to commit original working branch
      committed =
         CommitHandler.commitBranch(new ConflictManagerExternal(DemoBranches.SAW_Bld_2, workingBranch), false, true);
      assertTrue("Branch Committed after in Rebaseline was finished", !committed);

      // Should be allowed to commit to new working branch
      committed =
         CommitHandler.commitBranch(new ConflictManagerExternal(DemoBranches.SAW_Bld_2, branchForUpdate), false, true);
      assertTrue("Branch was not committed into new, rebaselined working branch", committed);

      // Clean up this test
      // Purge art from new Updated Branch
      Artifact artOnSaw2 = ArtifactQuery.getArtifactFromToken(NewArtifactToken, DemoBranches.SAW_Bld_2);
      Artifact artOnUpdateBranch = ArtifactQuery.getArtifactFromToken(NewArtifactToken, branchForUpdate);
      Operations.executeWorkAndCheckStatus(new PurgeArtifacts(Arrays.asList(artOnSaw2, artOnUpdateBranch)));
      // wait on operation
      Thread.sleep(1000);
      BranchManager.purgeBranch(branchForUpdate);

   }

   @Test
   public void testCommitWithMergeAbandon() throws Exception {
      ConflictResolverOperation resolverOperation =
         new ConflictResolverOperation("Test Resolver", MergeManagerTest.class.getCanonicalName()) {

            @Override
            protected void doWork(IProgressMonitor monitor) throws Exception {
               assertTrue("This code should have been executed since there should be conflicts.", wasExecuted());
            }
         };

      // Can't commit since there are conflicts
      boolean committed =
         CommitHandler.commitBranch(new ConflictManagerExternal(DemoBranches.SAW_Bld_1, workingBranch), false, true);
      assertTrue("Branch Committed with unresolved conflicts", !committed);

      List<MergeBranch> mergeBranches = BranchManager.getMergeBranches(workingBranch);
      assertTrue("Exactly one Merge Branch was not found", mergeBranches.size() == 1);

      MergeBranch mergeBranchFromFirstCommit = mergeBranches.get(0);
      assertTrue("Merge Branch is not for working branch",
         mergeBranchFromFirstCommit.getSourceBranch().equals(workingBranch));

      // Try Doing commit again, no new Merge Branches should be created
      boolean committed2 =
         CommitHandler.commitBranch(new ConflictManagerExternal(DemoBranches.SAW_Bld_1, workingBranch), false, true);
      assertTrue("Branch Committed with unresolved conflicts", !committed2);

      List<MergeBranch> mergeBranches2 = BranchManager.getMergeBranches(workingBranch);
      assertTrue("Exactly one Merge Branch was not found", mergeBranches2.size() == 1);

      MergeBranch mergeBranchFromSecondCommit = mergeBranches2.get(0);
      assertTrue("Merge Branches are not equal", mergeBranchFromSecondCommit.equals(mergeBranchFromFirstCommit));

      // Shouldn't not be able to update from parent since we are in the process of handling a Merge from a Commit
      UpdateBranchOperation update = new UpdateBranchOperation(workingBranch, resolverOperation);
      Operations.executeAsJob(update, true);
      // wait on operation
      assertTrue(
         "Branch should not be updating",
         !workingBranch.getBranchState().isRebaselineInProgress() && !workingBranch.getBranchState().isRebaselineInProgress());

      // Abandon 
      MergeInProgressHandler.handleCommitInProgressPostPrompt(new ConflictManagerExternal(DemoBranches.SAW_Bld_1,
         workingBranch), DELETE_MERGE, true);
      assertTrue("Merge Branch still present", !BranchManager.hasMergeBranches(workingBranch));

      // Now we should be to do an update
      UpdateBranchOperation update2 = new UpdateBranchOperation(workingBranch, resolverOperation);
      Operations.executeAsJob(update2, true);
      // wait on operation
      Thread.sleep(1000);
      assertTrue("Branch is not updating", workingBranch.getBranchState().isRebaselineInProgress());

      Branch branchForUpdate = BranchManager.getFirstMergeBranch(workingBranch);

      FinishUpdateBranchOperation finishUpdateOperation =
         new FinishUpdateBranchOperation(resolverOperation.getConflictManager(), true, true);
      Operations.executeAsJob(finishUpdateOperation, true);
      // wait on operation
      Thread.sleep(1000);
      // Make sure the state is now Rebaselined
      assertTrue("Branch is not in Rebaselined", workingBranch.getBranchState().isRebaselined());

      // Clean up this test
      // Purge art from new Updated Branch
      Artifact artOnUpdateBranch = ArtifactQuery.getArtifactFromToken(NewArtifactToken, branchForUpdate);
      Operations.executeWorkAndCheckStatus(new PurgeArtifacts(Arrays.asList(artOnUpdateBranch)));
      // wait on operation
      Thread.sleep(1000);
      BranchManager.purgeBranch(branchForUpdate);
   }

   @Test
   public void testCommitWithMergeFinish() throws Exception {
      ConflictResolverOperation resolverOperation =
         new ConflictResolverOperation("Test Resolver", MergeManagerTest.class.getCanonicalName()) {

            @Override
            protected void doWork(IProgressMonitor monitor) throws Exception {
               assertTrue("This code should have been executed since there should be conflicts.", wasExecuted());
            }
         };

      // Try committing into SAW BLD 1
      boolean committed =
         CommitHandler.commitBranch(new ConflictManagerExternal(DemoBranches.SAW_Bld_1, workingBranch), false, true);
      assertTrue("Branch Committed with unresolved conflicts", !committed);

      // Shouldn't be able to rebase
      UpdateBranchOperation update = new UpdateBranchOperation(workingBranch, resolverOperation);
      Operations.executeAsJob(update, true);
      // wait on operation
      Thread.sleep(1000);
      assertTrue(
         "Branch should not be updating",
         !workingBranch.getBranchState().isRebaselineInProgress() && !workingBranch.getBranchState().isRebaselineInProgress());

      // Commit into another branch other than SAW_BLD_1 so there are no conflicts
      committed =
         CommitHandler.commitBranch(new ConflictManagerExternal(DemoBranches.SAW_Bld_2, workingBranch), false, true);
      assertTrue("Branch was not committed", committed);

      // Even if I abandon first Merge, still shouldn't be able to rebase since I already completed on Commit
      MergeInProgressHandler.handleCommitInProgressPostPrompt(new ConflictManagerExternal(DemoBranches.SAW_Bld_1,
         workingBranch), DELETE_MERGE, true);

      update = new UpdateBranchOperation(workingBranch, resolverOperation);
      Operations.executeAsJob(update, true);
      // wait on operation
      Thread.sleep(1000);
      assertTrue(
         "Branch should not be updating",
         !workingBranch.getBranchState().isRebaselineInProgress() && !workingBranch.getBranchState().isRebaselineInProgress());

      // Clean up this test
      Artifact artOnSaw2 = ArtifactQuery.getArtifactFromToken(NewArtifactToken, DemoBranches.SAW_Bld_2);
      Operations.executeWorkAndCheckStatus(new PurgeArtifacts(Arrays.asList(artOnSaw2)));
      // wait on operation
      Thread.sleep(1000);
   }
}

Back to the top