Skip to main content
summaryrefslogtreecommitdiffstats
blob: 10e067810a15c07a9e0813044496adaff68b8fb9 (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
/*******************************************************************************
 * 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.skynet.core;

import static org.eclipse.osee.client.demo.DemoChoice.OSEE_CLIENT_DEMO;
import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule;
import org.eclipse.osee.client.test.framework.OseeHousekeepingRule;
import org.eclipse.osee.client.test.framework.OseeLogMonitorRule;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
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.PurgeArtifacts;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.MethodRule;

/**
 * @author Andrew M. Finkbeiner
 */
public class RelationDeletionTest {

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

   @Rule
   public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule();

   @Rule
   public MethodRule oseeHousekeepingRule = new OseeHousekeepingRule();

   private List<Artifact> artifacts;

   @Before
   public void setup() {
      artifacts = new ArrayList<>();
   }

   @After
   public void cleanUp() throws OseeCoreException {
      Operations.executeWorkAndCheckStatus(new PurgeArtifacts(artifacts));
   }

   @Test
   public void testDeleteRelationPersistsBothSides() throws Exception {
      Artifact parent = createArtifact(CoreArtifactTypes.Folder, COMMON);
      Artifact child1 = createArtifact(CoreArtifactTypes.Folder, COMMON);
      Artifact child2 = createArtifact(CoreArtifactTypes.Folder, COMMON);
      Artifact child3 = createArtifact(CoreArtifactTypes.Folder, COMMON);
      parent.addRelation(CoreRelationTypes.Default_Hierarchical__Child, child1);
      parent.addRelation(CoreRelationTypes.Default_Hierarchical__Child, child2);
      parent.addRelation(CoreRelationTypes.Default_Hierarchical__Child, child3);
      parent.persist(getClass().getSimpleName());

      assertTrue("Failed to add all three children",
         parent.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Child).size() == 3);

      child1.deleteRelation(CoreRelationTypes.Default_Hierarchical__Parent, parent);

      assertTrue("We removed a relation so it should still be dirty.", child1.isDirty());
      assertTrue("Parent artifact should be marked as dirty since it's relation has changed.", parent.isDirty());

      child1.persist(getClass().getSimpleName());

      assertFalse("Parent artifact should be clean now.", parent.isDirty());
      assertFalse("Child artifact should also be clean.", child1.isDirty());

      List<Artifact> children = parent.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Child);

      assertTrue("The deleted child was not successfully removed.", children.size() == 2);

      assertTrue("Child2 is not the first in the list and it should be.", children.get(0) == child2);
   }

   @Test
   public void testDeleteThenUnDeleteRelation() throws OseeCoreException {
      Artifact parent = createArtifact(CoreArtifactTypes.Folder, COMMON);
      Artifact child1 = createArtifact(CoreArtifactTypes.Folder, COMMON);

      parent.addRelation(CoreRelationTypes.Default_Hierarchical__Child, child1);
      parent.persist(getClass().getSimpleName());

      assertTrue("Failed to add child",
         parent.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Child).size() == 1);

      child1.deleteRelation(CoreRelationTypes.Default_Hierarchical__Parent, parent);

      assertTrue("We removed a relation so it should still be dirty.", child1.isDirty());
      assertTrue("Parent artifact should be marked as dirty since it's relation has changed.", parent.isDirty());

      child1.persist(getClass().getSimpleName());

      List<Artifact> children = parent.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Child);

      assertTrue("The deleted child was not successfully removed.", children.size() == 0);

      parent.addRelation(CoreRelationTypes.Default_Hierarchical__Child, child1);

      assertFalse("This previously deleted child still has modification type deleted", child1.isDeleted());
      parent.persist(getClass().getSimpleName());

      assertTrue("Failed to add child previously deleted child relation",
         parent.getRelatedArtifacts(CoreRelationTypes.Default_Hierarchical__Child).size() == 1);

   }

   private Artifact createArtifact(IArtifactType artifactType, IOseeBranch branch) throws OseeCoreException {
      Artifact newArtifact = ArtifactTypeManager.addArtifact(artifactType, branch);
      artifacts.add(newArtifact);
      return newArtifact;
   }
}

Back to the top