Skip to main content
summaryrefslogtreecommitdiffstats
blob: 120d9f4953f4ef328dee5efdaa57af35adb6efd5 (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.ui.skynet;

import static org.eclipse.osee.client.demo.DemoChoice.OSEE_CLIENT_DEMO;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule;
import org.eclipse.osee.client.test.framework.OseeLogMonitorRule;
import org.eclipse.osee.client.test.framework.TestInfo;
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.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.enums.DeletionFlag;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
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.ArtifactTypeManager;
import org.eclipse.osee.framework.skynet.core.artifact.Attribute;
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.relation.RelationLink;
import org.eclipse.osee.framework.ui.skynet.update.InterArtifactExplorerDropHandlerOperation;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

/**
 * Tests cross branch drag and drop.
 * 
 * @author Jeff C. Phillips
 * @author Megumi Telles
 */
public class InterArtifactDropTest {

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

   @Rule
   public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule();

   @Rule
   public TestInfo method = new TestInfo();

   private static Artifact sourceArtifact1;
   private static Artifact sourceArtifact2;
   private static Artifact sourceArtifact3;
   private static Artifact sourceChildArtifact1;
   private static Artifact sourceDeleteArtifact1;

   private static IOseeBranch sourceBranch;
   private static IOseeBranch destinationBranch;
   private static IOseeBranch updateTestBranch1;
   private static IOseeBranch updateTestBranch2;
   private static IOseeBranch updateTestBranch3;

   private static boolean wasInitialized = false;

   @Before
   public void setUp() throws Exception {
      // Initialization must run after the integration rule
      // Can't use before class here
      if (!wasInitialized) {
         wasInitialized = true;
         initializeBranches();
         addArtifactsToBranches();
      }
   }

   @AfterClass
   public static void tearDown() throws OseeCoreException {
      if (wasInitialized) {
         purgeBranches();
      }
   }

   @Test
   public void testIntroduceCrossBranch() throws Exception {
      // source artifact newly introduced to destination branch
      InterArtifactExplorerDropHandlerOperation dropHandler = new InterArtifactExplorerDropHandlerOperation(
         OseeSystemArtifacts.getDefaultHierarchyRootArtifact(destinationBranch), new Artifact[] {sourceArtifact1},
         false);
      Operations.executeWork(dropHandler);
      // Acquire the introduced artifact
      Artifact destArtifact = ArtifactQuery.getArtifactFromId(sourceArtifact1.getArtId(), destinationBranch);

      assertTrue(sourceArtifact1.getName().equals(destArtifact.getName()));
      assertTrue(sourceArtifact1.getGammaId() == destArtifact.getGammaId());
      assertTrue(sourceArtifact1.getModType() == destArtifact.getModType());
   }

   @Test
   public void testUpdateBranch() throws Exception {
      // source artifact updated and introduced to existing destination
      // artifact
      Artifact updateTestArtifact = ArtifactQuery.getArtifactFromId(sourceArtifact1.getArtId(), updateTestBranch2);
      Attribute<Object> testAttr = updateTestArtifact.getSoleAttribute(CoreAttributeTypes.Name);
      testAttr.setFromString("I am an update branch test");
      Artifact root = OseeSystemArtifacts.getDefaultHierarchyRootArtifact(updateTestBranch2);
      root.addChild(updateTestArtifact);
      updateTestArtifact.persist(getClass().getSimpleName());

      InterArtifactExplorerDropHandlerOperation dropHandler =
         new InterArtifactExplorerDropHandlerOperation(sourceArtifact1, new Artifact[] {updateTestArtifact}, false);
      Operations.executeWork(dropHandler);

      // Acquire the updated artifact
      Artifact destArtifact =
         ArtifactQuery.getArtifactFromId(updateTestArtifact.getArtId(), sourceArtifact1.getBranch());
      destArtifact.reloadAttributesAndRelations();
      assertTrue(updateTestArtifact.getName().equals(destArtifact.getName()));
      assertTrue(updateTestArtifact.getGammaId() == destArtifact.getGammaId());
      assertTrue(updateTestArtifact.getModType() == destArtifact.getModType());
   }

   @Test
   public void testDeleteAttributeFromArtifactBranch() throws Exception {
      // attribute deleted and introduced to existing attribute on
      // sourceBranch
      Artifact deleteTestArtifact = ArtifactQuery.getArtifactFromId(sourceArtifact2.getArtId(), updateTestBranch1);
      Attribute<Object> destAttribute = deleteTestArtifact.getSoleAttribute(CoreAttributeTypes.StaticId);
      deleteTestArtifact.deleteAttribute(destAttribute);
      deleteTestArtifact.persist(getClass().getSimpleName());

      InterArtifactExplorerDropHandlerOperation dropHandler =
         new InterArtifactExplorerDropHandlerOperation(sourceArtifact2, new Artifact[] {deleteTestArtifact}, false);
      Operations.executeWork(dropHandler);

      Artifact destArtifact =
         ArtifactQuery.getArtifactFromId(deleteTestArtifact.getArtId(), sourceArtifact2.getBranch());
      Attribute<?> destAttr = destArtifact.getAttributeById(destAttribute.getId(), true);
      assertTrue(destAttr.getModificationType().equals(ModificationType.DELETED));
   }

   @Test
   public void testDeleteRelationFromArtifactBranch() throws Exception {
      // relation deleted and introduced to existing relation on sourceBranch
      Artifact deleteTestArtifact = ArtifactQuery.getArtifactFromId(sourceArtifact2.getArtId(), updateTestBranch1);
      deleteTestArtifact.deleteRelation(CoreRelationTypes.Default_Hierarchical__Child, sourceChildArtifact1);
      deleteTestArtifact.persist(getClass().getSimpleName());

      InterArtifactExplorerDropHandlerOperation dropHandler =
         new InterArtifactExplorerDropHandlerOperation(sourceArtifact2, new Artifact[] {deleteTestArtifact}, false);
      Operations.executeWork(dropHandler);

      Artifact destArtifact =
         ArtifactQuery.getArtifactFromId(deleteTestArtifact.getArtId(), sourceArtifact2.getBranch());
      for (RelationLink relLink : destArtifact.getRelationsAll(DeletionFlag.INCLUDE_DELETED)) {
         if (relLink.getAArtifactId() == sourceArtifact2.getArtId() && relLink.getBArtifactId() == sourceChildArtifact1.getArtId()) {
            assertTrue(relLink.getModificationType().equals(ModificationType.DELETED));
         }
      }
   }

   @Test
   public void testDeleteArtifactBranch() throws Exception {
      // artifact deleted and introduced to existing destination sourceBranch
      Artifact deleteTestArtifact = ArtifactQuery.getArtifactFromId(sourceArtifact2.getArtId(), updateTestBranch1);
      Attribute<Object> destAttribute = deleteTestArtifact.getSoleAttribute(CoreAttributeTypes.Name);
      deleteTestArtifact.delete();
      deleteTestArtifact.persist(getClass().getSimpleName());

      InterArtifactExplorerDropHandlerOperation dropHandler =
         new InterArtifactExplorerDropHandlerOperation(sourceArtifact2, new Artifact[] {deleteTestArtifact}, false);
      Operations.executeWork(dropHandler);

      Artifact destArtifact = ArtifactQuery.getArtifactFromId(deleteTestArtifact.getArtId(),
         sourceArtifact2.getBranch(), DeletionFlag.INCLUDE_DELETED);
      assertTrue(destArtifact.getModType().equals(ModificationType.DELETED));
      Attribute<?> destAttr = destArtifact.getAttributeById(destAttribute.getId(), true);
      assertTrue(destAttr.getModificationType().equals(ModificationType.ARTIFACT_DELETED));
      for (RelationLink relLink : destArtifact.getRelationsAll(DeletionFlag.INCLUDE_DELETED)) {
         assertTrue(relLink.getModificationType().equals(ModificationType.DELETED));
      }
   }

   @Test
   public void testDestinationArtifactDoesNotExistAsDeletedBranch() throws Exception {
      // artifact deleted on source branch, does not exist on destination
      // branch
      // the deleted artifact will be introduced as deleted
      InterArtifactExplorerDropHandlerOperation dropHandler = new InterArtifactExplorerDropHandlerOperation(
         OseeSystemArtifacts.getDefaultHierarchyRootArtifact(destinationBranch), new Artifact[] {sourceDeleteArtifact1},
         false);
      Operations.executeWork(dropHandler);

      Artifact destArtifact = ArtifactQuery.getArtifactFromId(sourceDeleteArtifact1.getArtId(), destinationBranch,
         DeletionFlag.INCLUDE_DELETED);
      // artifact should be introduced
      assertNotNull(destArtifact);
      assertTrue(sourceDeleteArtifact1.getName().equals(destArtifact.getName()));
      assertTrue(sourceDeleteArtifact1.getGammaId() == destArtifact.getGammaId());
      assertTrue(sourceDeleteArtifact1.getModType() == destArtifact.getModType());
   }

   @Test
   public void testUndeleteArtifactOnBranch() throws Exception {
      // artifact deleted on updateBranch2 and introduced as non-deleted
      // artifact on updateTestBranch2
      Artifact testArtifact = ArtifactQuery.getArtifactFromId(sourceDeleteArtifact1.getArtId(), updateTestBranch3);

      InterArtifactExplorerDropHandlerOperation dropHandler = new InterArtifactExplorerDropHandlerOperation(
         OseeSystemArtifacts.getDefaultHierarchyRootArtifact(updateTestBranch2), new Artifact[] {testArtifact}, false);
      Operations.executeWork(dropHandler);

      Artifact destArtifact = ArtifactQuery.getArtifactFromId(sourceDeleteArtifact1.getArtId(), updateTestBranch2,
         DeletionFlag.EXCLUDE_DELETED);
      // artifact should be introduced
      assertNotNull(destArtifact);
      assertTrue(testArtifact.getName().equals(destArtifact.getName()));
      assertTrue(testArtifact.getGammaId() == destArtifact.getGammaId());
      assertTrue(testArtifact.getModType() == destArtifact.getModType());
   }

   private void addArtifactsToBranches() throws OseeCoreException {
      BranchManager.createWorkingBranch(CoreBranches.SYSTEM_ROOT, sourceBranch);
      BranchManager.createWorkingBranch(CoreBranches.SYSTEM_ROOT, destinationBranch);

      // Add artifacts to source
      sourceArtifact1 = ArtifactTypeManager.addArtifact(CoreArtifactTypes.SoftwareRequirement, sourceBranch);
      sourceArtifact1.persist(method.getQualifiedTestName());
      sourceChildArtifact1 = ArtifactTypeManager.addArtifact(CoreArtifactTypes.SoftwareRequirement, sourceBranch);
      sourceChildArtifact1.persist(method.getQualifiedTestName());
      // sourceArtifact2 has an additional attribute and a child artifact
      // associated to it
      sourceArtifact2 = ArtifactTypeManager.addArtifact(CoreArtifactTypes.SoftwareRequirement, sourceBranch);
      sourceArtifact2.addAttribute(CoreAttributeTypes.StaticId);
      sourceArtifact2.addChild(sourceChildArtifact1);
      sourceArtifact2.persist(method.getQualifiedTestName());

      // updateTestBranch has sourceArtifact1/2, sourceChildArtifact1 and
      // sourceDeleteArtifact
      BranchManager.createWorkingBranch(sourceBranch, updateTestBranch1);

      sourceArtifact3 = ArtifactTypeManager.addArtifact(CoreArtifactTypes.SoftwareRequirement, sourceBranch);
      sourceArtifact3.persist(method.getQualifiedTestName());
      sourceDeleteArtifact1 = ArtifactTypeManager.addArtifact(CoreArtifactTypes.SoftwareRequirement, sourceBranch);
      sourceDeleteArtifact1.persist(method.getQualifiedTestName());

      // updateTestBranch has sourceArtifact1/2/3, sourceChildArtifact1,
      // sourceDeleteArtifact1
      BranchManager.createWorkingBranch(sourceBranch, updateTestBranch3);

      sourceDeleteArtifact1.delete();
      sourceDeleteArtifact1.persist(method.getQualifiedTestName());

      // updateTestBranch has sourceArtifact1/2/3, sourceChildArtifact1,
      // sourceDeleteArtifact1 (deleted)
      BranchManager.createWorkingBranch(sourceBranch, updateTestBranch2);
   }

   private void initializeBranches() {
      sourceBranch = createBranchToken("Source");
      destinationBranch = createBranchToken("Destination");
      updateTestBranch1 = createBranchToken("updateTestBranch");
      updateTestBranch2 = createBranchToken("updateTestBranch");
      updateTestBranch3 = createBranchToken("updateTestBranch");
   }

   private static void purgeBranches() throws OseeCoreException {
      BranchManager.purgeBranch(destinationBranch);
      BranchManager.purgeBranch(updateTestBranch1);
      BranchManager.purgeBranch(updateTestBranch2);
      BranchManager.purgeBranch(updateTestBranch3);
      BranchManager.purgeBranch(sourceBranch);
   }

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

Back to the top