Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9a4fef1592044ff30983a0a1b1e306bbb6e3d81c (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
/*******************************************************************************
 * Copyright (c) 2010 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.CoreArtifactTypes.GeneralData;
import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON;
import static org.eclipse.osee.framework.core.enums.CoreBranches.SYSTEM_ROOT;
import static org.eclipse.osee.framework.core.enums.DemoBranches.SAW_Bld_1;
import static org.eclipse.osee.framework.core.enums.DemoBranches.SAW_Bld_2;
import org.eclipse.osee.client.demo.DemoTypes;
import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule;
import org.eclipse.osee.client.test.framework.OseeLogMonitorRule;
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.model.event.DefaultBasicGuidArtifact;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.GUID;
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.search.ArtifactQuery;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

/**
 * @author Jeff C. Phillips
 */
public final class ArtifactTest {

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

   @Rule
   public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule();

   private Artifact artifactWithSpecialAttr;

   @Before
   public void setUp() throws Exception {
      artifactWithSpecialAttr = ArtifactTypeManager.addArtifact(DemoTypes.DemoTestRequirement, SAW_Bld_1);
   }

   @After
   public void tearDown() throws Exception {
      if (artifactWithSpecialAttr != null) {
         artifactWithSpecialAttr.deleteAndPersist();
      }
      for (Artifact art : ArtifactQuery.getArtifactListFromTypeAndName(GeneralData, ArtifactTest.class.getSimpleName(),
         COMMON)) {
         art.deleteAndPersist();
      }
   }

   @Test
   public void attributeCopyAcrossRelatedBranches() throws Exception {
      artifactWithSpecialAttr.setSoleAttributeValue(CoreAttributeTypes.Partition, "Navigation");
      artifactWithSpecialAttr.setName("ArtifactTest-artifactWithSpecialAttr");

      Artifact copiedArtifact = artifactWithSpecialAttr.duplicate(SAW_Bld_2);
      try {
         Assert.assertFalse(copiedArtifact.getAttributeCount(CoreAttributeTypes.Partition) == 0);
      } finally {
         if (copiedArtifact != null) {
            copiedArtifact.deleteAndPersist();
         }
      }
   }

   @Test
   public void attributeCopyAcrossUnrelatedBranches() throws Exception {
      artifactWithSpecialAttr.setSoleAttributeValue(CoreAttributeTypes.Partition, "Navigation");
      artifactWithSpecialAttr.setName("ArtifactTest-artifactWithSpecialAttr");

      Artifact copiedArtifact = artifactWithSpecialAttr.duplicate(CoreBranches.COMMON);
      try {
         Assert.assertTrue(copiedArtifact.getAttributeCount(CoreAttributeTypes.Partition) == 0);
      } finally {
         if (copiedArtifact != null) {
            copiedArtifact.deleteAndPersist();
         }
      }
   }

   @Test
   public void setSoleAttributeValueTest() throws Exception {
      artifactWithSpecialAttr.setName("ArtifactTest-artifactWithSpecialAttr");
      artifactWithSpecialAttr.setSoleAttributeValue(CoreAttributeTypes.Partition, "Navigation");
   }

   @Test
   public void testHashCode() throws OseeCoreException {
      Artifact art = ArtifactTypeManager.addArtifact(GeneralData, COMMON, ArtifactTest.class.getSimpleName());
      art.persist("test");

      DefaultBasicGuidArtifact equalGuid =
         new DefaultBasicGuidArtifact(SYSTEM_ROOT, CoreArtifactTypes.SoftwareDesign.getGuid(), art.getGuid());
      Assert.assertEquals(art.hashCode(), equalGuid.hashCode());

      DefaultBasicGuidArtifact equalGuidArtType =
         new DefaultBasicGuidArtifact(SYSTEM_ROOT, GeneralData.getGuid(), art.getGuid());
      Assert.assertEquals(art.hashCode(), equalGuidArtType.hashCode());

      DefaultBasicGuidArtifact equalGuidArtTypeBranchUuid =
         new DefaultBasicGuidArtifact(COMMON, GeneralData.getGuid(), art.getGuid());
      Assert.assertEquals(art.hashCode(), equalGuidArtTypeBranchUuid.hashCode());

      DefaultBasicGuidArtifact equalArtTypeBranchUuidNotGuid =
         new DefaultBasicGuidArtifact(COMMON, GeneralData.getGuid(), GUID.create());
      Assert.assertNotSame(art.hashCode(), equalArtTypeBranchUuidNotGuid.hashCode());
   }

   @Test
   public void testEquals() throws OseeCoreException {
      Artifact art = ArtifactTypeManager.addArtifact(GeneralData, COMMON, ArtifactTest.class.getSimpleName());
      art.persist("test");

      DefaultBasicGuidArtifact equalGuid =
         new DefaultBasicGuidArtifact(SYSTEM_ROOT, CoreArtifactTypes.SoftwareDesign.getGuid(), art.getGuid());
      Assert.assertNotSame(art, equalGuid);

      DefaultBasicGuidArtifact equalGuidArtType =
         new DefaultBasicGuidArtifact(SYSTEM_ROOT, GeneralData.getGuid(), art.getGuid());
      Assert.assertNotSame(art, equalGuidArtType);

      DefaultBasicGuidArtifact equalGuidArtTypeBranchUuid =
         new DefaultBasicGuidArtifact(COMMON, GeneralData.getGuid(), art.getGuid());
      Assert.assertEquals(art, equalGuidArtTypeBranchUuid);

      DefaultBasicGuidArtifact equalArtTypeBranchUuidNotGuid =
         new DefaultBasicGuidArtifact(COMMON, GeneralData.getGuid(), GUID.create());
      Assert.assertNotSame(art, equalArtTypeBranchUuidNotGuid);
   }

}

Back to the top