Skip to main content
summaryrefslogtreecommitdiffstats
blob: accc4607ff420e3c3342002c33829a38af83e6ac (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
/*******************************************************************************
 * Copyright (c) 2014 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.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Collection;
import org.eclipse.core.runtime.NullProgressMonitor;
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.data.IOseeBranch;
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.model.Branch;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.skynet.core.OseeSystemArtifacts;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.skynet.core.conflict.Conflict;
import org.eclipse.osee.framework.skynet.core.conflict.ConflictManagerExternal;
import org.eclipse.osee.framework.skynet.core.revision.ConflictManagerInternal;
import org.eclipse.osee.framework.ui.skynet.update.InterArtifactExplorerDropHandlerOperation;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;

/**
 * @author Megumi Telles
 */
public class ConflictIntroduceTest {

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

   @Rule
   public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule();

   private static IOseeBranch sourceBranch;
   private static IOseeBranch destinationBranch;
   private static IOseeBranch updateBranch;

   private static Artifact artifactToDelete;

   private static String TESTNAME = "ConflictIntroduceTest";

   @BeforeClass
   public static void setUp() throws Exception {
      sourceBranch = createBranchToken("Source");
      destinationBranch = createBranchToken("Destination");
      updateBranch = createBranchToken("Update");

      // set up destination branch
      BranchManager.createWorkingBranch(DemoBranches.SAW_Bld_1, destinationBranch);
      artifactToDelete =
         ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.SoftwareRequirement, "Read-only Robots",
            DemoBranches.SAW_Bld_1);

      // Delete artifact and commit to destination branch
      BranchManager.createWorkingBranch(destinationBranch, updateBranch);
      Artifact art = ArtifactQuery.getArtifactFromId(artifactToDelete.getArtId(), updateBranch);
      art.deleteAndPersist();

      ConflictManagerExternal conflictManager = new ConflictManagerExternal(destinationBranch, updateBranch);
      BranchManager.commitBranch(null, conflictManager, false, false);

      // create source branch
      BranchManager.createWorkingBranch(destinationBranch, sourceBranch);

   }

   @Test
   public void testIntroduceNoConflict() {
      // Introduce the artifact
      InterArtifactExplorerDropHandlerOperation dropHandler =
         new InterArtifactExplorerDropHandlerOperation(
            OseeSystemArtifacts.getDefaultHierarchyRootArtifact(sourceBranch), new Artifact[] {artifactToDelete}, false);
      Operations.executeWork(dropHandler);
      // Acquire the introduced artifact
      Artifact destArtifact = ArtifactQuery.getArtifactFromId(artifactToDelete.getArtId(), sourceBranch);
      Assert.assertNotNull(destArtifact);

      // check for conflicts....there should be no conflict in this case.
      Collection<Conflict> conflicts = null;
      Branch sBranch = BranchManager.getBranch(sourceBranch);
      Branch dBranch = BranchManager.getBranch(destinationBranch);
      try {
         conflicts =
            ConflictManagerInternal.getConflictsPerBranch(sBranch, dBranch, BranchManager.getBaseTransaction(sBranch),
               new NullProgressMonitor());
      } catch (Exception ex) {
         fail(Lib.exceptionToString(ex));
      }
      assertTrue("Unexpected conflict found", conflicts.size() == 0);
   }

   @Test
   public void testModifiedButDeletedConflict() {

      Artifact artifactToModify =
         ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.Component, "Cognitive_Decision_Aiding",
            destinationBranch);
      assertNotNull(artifactToModify);
      artifactToModify.setSoleAttributeFromString(CoreAttributeTypes.Name, "Cognitive_Decision_Aiding2");
      artifactToModify.persist(TESTNAME);

      Artifact dArtifact =
         ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.Component, "Cognitive_Decision_Aiding",
            sourceBranch);
      assertNotNull(dArtifact);
      dArtifact.deleteAndPersist();

      // check for conflict....this should be a conflict
      Collection<Conflict> conflicts = null;
      Branch sBranch = BranchManager.getBranch(sourceBranch);
      Branch dBranch = BranchManager.getBranch(destinationBranch);
      try {
         conflicts =
            ConflictManagerInternal.getConflictsPerBranch(sBranch, dBranch, BranchManager.getBaseTransaction(sBranch),
               new NullProgressMonitor());
      } catch (Exception ex) {
         fail(Lib.exceptionToString(ex));
      }
      assertTrue("Expected conflict not found", conflicts.size() == 2);
   }

   @Test
   public void testDeletedButModifiedConflict() {
      Artifact dArtifact =
         ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.Component, "Chassis", sourceBranch);
      assertNotNull(dArtifact);
      dArtifact.deleteAndPersist();

      Artifact artifactToModify =
         ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.Component, "Chassis", destinationBranch);
      assertNotNull(artifactToModify);
      artifactToModify.setSoleAttributeFromString(CoreAttributeTypes.Name, "Chassis2");
      artifactToModify.persist(TESTNAME);

      // check for conflict....this should be a conflict
      Collection<Conflict> conflicts = null;
      Branch sBranch = BranchManager.getBranch(sourceBranch);
      Branch dBranch = BranchManager.getBranch(destinationBranch);
      try {
         conflicts =
            ConflictManagerInternal.getConflictsPerBranch(sBranch, dBranch, BranchManager.getBaseTransaction(sBranch),
               new NullProgressMonitor());
      } catch (Exception ex) {
         fail(Lib.exceptionToString(ex));
      }
      assertTrue("Expected conflict not found", conflicts.size() == 1);
   }

   @AfterClass
   public static void tearDown() throws Exception {
      BranchManager.refreshBranches();
      Branch mBranch = null;
      if (sourceBranch != null && destinationBranch != null) {
         mBranch = BranchManager.getMergeBranch(sourceBranch, destinationBranch);
      }

      BranchManager.purgeBranch(mBranch);
      Thread.sleep(10000);
      BranchManager.purgeBranch(updateBranch);
      Thread.sleep(10000);
      BranchManager.purgeBranch(sourceBranch);
      Thread.sleep(10000);
      BranchManager.purgeBranch(destinationBranch);
   }

   private static IOseeBranch createBranchToken(String name) {
      String branchName = String.format("%s__%s", TESTNAME, name);
      return TokenFactory.createBranch(branchName);
   }

}

Back to the top