Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4bc641074ac5dd993ec1661a308755b6a3d612b0 (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
/*******************************************************************************
 * 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.framework.core.model.type;

import java.util.ArrayList;
import java.util.Collection;
import org.junit.Assert;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
 * Test Case for {@link ArtifactType}
 * 
 * @author Roberto E. Escobar
 */
@RunWith(Parameterized.class)
public class ArtifactTypeTest extends AbstractOseeTypeTest<ArtifactType> {

   private final boolean isAbstract;

   public ArtifactTypeTest(ArtifactType type, String guid, String name, boolean isAbstract) {
      super(type, guid, name);
      this.isAbstract = isAbstract;
   }

   @Test
   public void testSetGetIsAbstract() throws OseeCoreException {
      Assert.assertEquals(isAbstract, getType().isAbstract());
      getType().clearDirty();
      Assert.assertFalse(getType().isDirty());
      Assert.assertFalse(getType().areFieldsDirty(ArtifactType.ARTIFACT_IS_ABSTRACT_FIELD_KEY));

      // Check assigning the same value does not affect dirty
      getType().setAbstract(isAbstract);
      Assert.assertFalse(getType().isDirty());
      Assert.assertFalse(getType().areFieldsDirty(ArtifactType.ARTIFACT_IS_ABSTRACT_FIELD_KEY));

      getType().setAbstract(!isAbstract);
      Assert.assertEquals(!isAbstract, getType().isAbstract());
      Assert.assertTrue(getType().isDirty());
      Assert.assertTrue(getType().areFieldsDirty(ArtifactType.ARTIFACT_IS_ABSTRACT_FIELD_KEY));

      getType().setAbstract(isAbstract);
      getType().clearDirty();
   }

   @Ignore
   @Test
   public void test() {

      //      getType().compareTo(other);

      //      getType().getAttributeTypes(branch);
      //      getType().setAttributeTypes(attributeTypes, branch);

      //      getType().getFieldNames();

      //      getType().getFirstLevelDescendantTypes();
      //      getType().getAllDescendantTypes();

      //      getType().getLocalAttributeTypes();
      //      getType().getSuperArtifactTypes();

      //      getType().setSuperType(superType);
   }

   @Override
   public void testToString() {
      Assert.assertEquals(getExpectedName(), getType().toString());
   }

   @Parameters
   public static Collection<Object[]> getData() {
      Collection<Object[]> data = new ArrayList<Object[]>();
      boolean isAbstract = true;
      for (int index = 1; index <= 3; index++) {
         String guid = GUID.create();
         String name = "index: " + index;
         isAbstract ^= isAbstract;
         data.add(new Object[] {new ArtifactType(guid, name, isAbstract), guid, name, isAbstract});
      }
      return data;
   }

   //   @Override
   //   @Ignore
   //   @Test
   //   public void testPersist() throws OseeCoreException {
   //
   //      //      T item1 = data.get(0);
   //      //      T item2 = data.get(1);
   //      //
   //      //      cache.storeByGuid(guids);
   //      //      cache.storeItem(item);
   //      //      cache.storeItems(toStore);
   //      //      cache.storeItems(items);
   //      //      public void storeItem(AbstractOseeType item) throws OseeCoreException {
   //
   //      //      public void storeItems(T... items) throws OseeCoreException {
   //
   //      //      public void storeItems(Collection<T> toStore) throws OseeCoreException {
   //   }

   //   @org.junit.Test
   //   public void testArtifactInheritanceCycleDetect() throws OseeCoreException {
   //      ArtifactType baseType = artCache.getUniqueByName("BaseArtifactType");
   //      Assert.assertNotNull(baseType);
   //
   //      Set<ArtifactType> baseSuperType = new HashSet<ArtifactType>();
   //      baseSuperType.add(baseType);
   //
   //      try {
   //         artCache.cacheArtifactSuperType(baseType, baseSuperType);
   //         Assert.assertTrue(
   //               "This line should not be execute, an inheritance cycle should have been detected and an exception should have been thrown",
   //               false);
   //      } catch (OseeInvalidInheritanceException ex) {
   //         Assert.assertNotNull(ex);
   //      }
   //   }
   //
   //   @org.junit.Test
   //   public void testArtifactInheritance() throws OseeCoreException {
   //      OseeTypesUtil.checkInheritance(artCache, "000", "000");// inherits from returns true if comparing against itself
   //      OseeTypesUtil.checkInheritance(artCache, "111", "000");
   //      OseeTypesUtil.checkInheritance(artCache, "222", "000");
   //      OseeTypesUtil.checkInheritance(artCache, "333", "000", "222");
   //      OseeTypesUtil.checkInheritance(artCache, "444", "000", "222", "333");
   //      OseeTypesUtil.checkInheritance(artCache, "555", "000", "444", "333", "222");
   //      OseeTypesUtil.checkInheritance(artCache, "666", "000", "333", "222");
   //   }
   //
   //   @org.junit.Test
   //   public void testArtifactInheritanceDescendants() throws OseeCoreException {
   //      OseeTypesUtil.checkDescendants(artCache, "000", false, "111", "222");
   //      OseeTypesUtil.checkDescendants(artCache, "000", true, "111", "222", "333", "444", "555", "666");
   //
   //      OseeTypesUtil.checkDescendants(artCache, "111", false);
   //      OseeTypesUtil.checkDescendants(artCache, "111", true);
   //
   //      OseeTypesUtil.checkDescendants(artCache, "222", false, "333");
   //      OseeTypesUtil.checkDescendants(artCache, "222", true, "333", "444", "555", "666");
   //
   //      OseeTypesUtil.checkDescendants(artCache, "333", false, "333", "444");
   //      OseeTypesUtil.checkDescendants(artCache, "333", true, "444", "555", "666");
   //
   //      OseeTypesUtil.checkDescendants(artCache, "444", false, "555");
   //      OseeTypesUtil.checkDescendants(artCache, "444", true, "555");
   //   }
   //
   //   @org.junit.Test
   //   public void testNullArtifactInheritanceCheck() throws OseeCoreException {
   //      ArtifactType baseType = artCache.getUniqueByName("BaseArtifactType");
   //      // Check for null inheritance
   //      Assert.assertFalse(baseType.inheritsFrom((ArtifactType) null));
   //   }
   //
   //   @org.junit.Test
   //   public void testArtifactInheritanceByName() throws OseeCoreException {
   //      Assert.assertTrue(artCache.getByGuid("666").inheritsFrom("ArtifactType3")); // check inherits from using artifact name
   //   }
   //
   //   @org.junit.Test
   //   public void testAddArtifactSuperTypeMethod() throws OseeCoreException {
   //      ArtifactType artifactType = factory.createArtifactType(artCache, "myGUID", false, "TestMethodCreated");
   //      artCache.cache(artifactType);
   //
   //      ArtifactType baseType = artCache.getUniqueByName("BaseArtifactType");
   //      Assert.assertFalse(artifactType.inheritsFrom(baseType));
   //      Assert.assertEquals(0, artifactType.getSuperArtifactTypes().size());
   //
   //      artifactType.setSuperType(new HashSet<ArtifactType>(Arrays.asList(baseType)));
   //      Assert.assertEquals(1, artifactType.getSuperArtifactTypes().size());
   //      Assert.assertTrue(artifactType.inheritsFrom(baseType));
   //      artCache.decache(artifactType);
   //   }
   //
   //   @org.junit.Test
   //   public void testInheritedAttributeTypes() throws OseeCoreException {
   //      Branch branch1 = branchCache.getByGuid("ROOT");
   //      Branch branch2 = branchCache.getByGuid("TEST");
   //      Assert.assertNotNull(branch1);
   //      Assert.assertNotNull(branch2);
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "000", branch1, "AAA");
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "111", branch1, "AAA", "BBB");
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "222", branch1, "AAA", "CCC");
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "333", branch1, "AAA", "DDD", "CCC");
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "444", branch1, "AAA", "FFF", "CCC", "DDD");
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "555", branch1, "AAA", "GGG", "FFF", "CCC", "DDD");
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "666", branch1, "AAA", "HHH", "DDD", "CCC");
   //
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "000", branch2, "AAA");
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "111", branch2, "AAA", "BBB");
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "222", branch2, "AAA", "CCC");
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "333", branch2, "AAA", "DDD", "CCC", "EEE"); // EEE only visible on branch2
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "444", branch2, "AAA", "FFF", "CCC", "DDD", "EEE");
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "555", branch2, "AAA", "GGG", "FFF", "CCC", "DDD", "EEE");
   //      OseeTypesUtil.checkAttributes(artCache, attrCache, "666", branch2, "AAA", "HHH", "DDD", "CCC", "EEE");
   //   }
   //
   //   @Override
   //   public void testDirty() throws OseeCoreException {
   //   }
   //
   //   private final static class BranchDataAccessor extends MockOseeDataAccessor<Branch> {
   //
   //      @Override
   //      public void load(AbstractOseeCache<Branch> cache) throws OseeCoreException {
   //         super.load(cache);
   //         Branch branch1 =
   //               OseeTypesUtil.createBranch(cache, factory, "ROOT", "Root Branch", BranchType.SYSTEM_ROOT,
   //                     BranchState.CREATED, false);
   //         branch1.setId(999);
   //         cache.cache(branch1);
   //
   //         Branch branch2 =
   //               OseeTypesUtil.createBranch(cache, factory, "TEST", "Test Branch", BranchType.BASELINE,
   //                     BranchState.CREATED, false);
   //         branch2.setId(998);
   //         cache.cache(branch2);
   //
   //         ((BranchCache) cache).setBranchParent(branch1, branch2);
   //      }
   //
   //   }
   //
   //   private final static class AttributeDataAccessor extends MockOseeDataAccessor<AttributeType> {
   //
   //      private final List<AttributeType> attributeTypes;
   //
   //      public AttributeDataAccessor(List<AttributeType> attributeTypes) {
   //         super();
   //         this.attributeTypes = attributeTypes;
   //      }
   //
   //      private AttributeType createAttributeTypeHelper(AbstractOseeCache<AttributeType> cache, IOseeTypeFactory factory, String guid, String name) throws OseeCoreException {
   //         return factory.createAttributeType(cache, guid, name, "DummyBase", "DummyProvider", "none", "none", null, 1,
   //               1, "test data", null);
   //      }
   //
   //      @Override
   //      public void load(AbstractOseeCache<AttributeType> cache) throws OseeCoreException {
   //         super.load(cache);
   //         attributeTypes.add(createAttributeTypeHelper(cache, factory, "AAA", "Attribute1"));
   //         attributeTypes.add(createAttributeTypeHelper(cache, factory, "BBB", "Attribute2"));
   //         attributeTypes.add(createAttributeTypeHelper(cache, factory, "CCC", "Attribute3"));
   //         attributeTypes.add(createAttributeTypeHelper(cache, factory, "DDD", "Attribute4"));
   //         attributeTypes.add(createAttributeTypeHelper(cache, factory, "EEE", "Attribute5"));
   //         attributeTypes.add(createAttributeTypeHelper(cache, factory, "FFF", "Attribute6"));
   //         attributeTypes.add(createAttributeTypeHelper(cache, factory, "GGG", "Attribute7"));
   //         attributeTypes.add(createAttributeTypeHelper(cache, factory, "HHH", "Attribute8"));
   //         int typeId = 200;
   //         for (AttributeType type : attributeTypes) {
   //            type.setId(typeId++);
   //            cache.cache(type);
   //         }
   //      }
   //   }
   //

   //      private void setUpArtifactTypeInheritance(ArtifactTypeCache cache) throws OseeCoreException {
   //         ArtifactType baseType = cache.getUniqueByName("BaseArtifactType");
   //
   //         Set<ArtifactType> baseSuperType = new HashSet<ArtifactType>();
   //         baseSuperType.add(baseType);
   //         // 0<-1
   //         cache.cacheArtifactSuperType(cache.getByGuid("111"), baseSuperType);
   //         // 0<-2
   //         cache.cacheArtifactSuperType(cache.getByGuid("222"), baseSuperType);
   //         // 2<-3
   //         cache.cacheArtifactSuperType(cache.getByGuid("333"), Arrays.asList(cache.getByGuid("222")));
   //         // 3<-4
   //         cache.cacheArtifactSuperType(cache.getByGuid("444"), Arrays.asList(cache.getByGuid("333")));
   //         // 4<-5
   //         cache.cacheArtifactSuperType(cache.getByGuid("555"), Arrays.asList(cache.getByGuid("444")));
   //         // 3<-6
   //         cache.cacheArtifactSuperType(cache.getByGuid("666"), Arrays.asList(cache.getByGuid("333")));
   //      }
   //
   //      private void setUpTypeValidity(ArtifactTypeCache cache) throws OseeCoreException {
   //         Branch branch1 = branchCache.getByGuid("ROOT");
   //         Branch branch2 = branchCache.getByGuid("TEST");
   //         Assert.assertNotNull(branch1);
   //         Assert.assertNotNull(branch2);
   //         cache.cacheTypeValidity(cache.getByGuid("000"), attributeCache.getByGuid("AAA"), branch1);
   //         cache.cacheTypeValidity(cache.getByGuid("111"), attributeCache.getByGuid("BBB"), branch1);
   //         cache.cacheTypeValidity(cache.getByGuid("222"), attributeCache.getByGuid("CCC"), branch1);
   //         cache.cacheTypeValidity(cache.getByGuid("333"), attributeCache.getByGuid("DDD"), branch1);
   //         cache.cacheTypeValidity(cache.getByGuid("333"), attributeCache.getByGuid("EEE"), branch2);
   //         cache.cacheTypeValidity(cache.getByGuid("444"), attributeCache.getByGuid("FFF"), branch1);
   //         cache.cacheTypeValidity(cache.getByGuid("555"), attributeCache.getByGuid("GGG"), branch1);
   //         cache.cacheTypeValidity(cache.getByGuid("666"), attributeCache.getByGuid("HHH"), branch1);
   //      }
}

Back to the top