Skip to main content
summaryrefslogtreecommitdiffstats
blob: efd2f3906b3f055d72bf4e86af9971786863afe3 (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
/*******************************************************************************
 * 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.test.fields;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Assert;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeInvalidInheritanceException;
import org.eclipse.osee.framework.core.model.internal.fields.ArtifactSuperTypeField;
import org.eclipse.osee.framework.core.model.test.mocks.MockDataFactory;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Test Case For {@link ArtifactSuperTypeField}
 * 
 * @author Roberto E. Escobar
 */
public class ArtifactSuperTypeFieldTest {

   private static ArtifactType art1;
   private static ArtifactType art2;
   private static ArtifactType art3;
   private static ArtifactType base;
   private static ArtifactType containingArt;

   @BeforeClass
   public static void prepareTest() {
      containingArt = MockDataFactory.createArtifactType(999);
      art1 = MockDataFactory.createArtifactType(1);
      art2 = MockDataFactory.createArtifactType(2);
      art3 = MockDataFactory.createArtifactType(3);
      base = new ArtifactType(CoreArtifactTypes.Artifact.getGuid(), CoreArtifactTypes.Artifact.getName(), false);
   }

   @Test
   public void testSetGet() throws OseeCoreException {
      List<ArtifactType> input = new ArrayList<ArtifactType>();
      ArtifactSuperTypeField field = new ArtifactSuperTypeField(containingArt, input);
      Assert.assertEquals(false, field.isDirty());

      FieldTestUtil.assertSetGet(field, Arrays.asList(art1, art2, art3), Arrays.asList(art1, art2, art3), true);
      field.clearDirty();
      Assert.assertEquals(false, field.isDirty());

      // Add again in a different order
      FieldTestUtil.assertSetGet(field, Arrays.asList(art3, art1, art2), Arrays.asList(art1, art2, art3), false);

      // Remove
      FieldTestUtil.assertSetGet(field, Arrays.asList(art3), Arrays.asList(art3), true);
      field.clearDirty();
      Assert.assertEquals(false, field.isDirty());

      // Add
      FieldTestUtil.assertSetGet(field, Arrays.asList(art3, art2), Arrays.asList(art3, art2), true);
      field.clearDirty();
      Assert.assertEquals(false, field.isDirty());
   }

   @Test(expected = OseeInvalidInheritanceException.class)
   public void testBaseCircularity() throws OseeCoreException {
      List<ArtifactType> input = new ArrayList<ArtifactType>();
      ArtifactSuperTypeField field = new ArtifactSuperTypeField(containingArt, input);
      Assert.assertEquals(false, field.isDirty());

      field.set(Collections.singletonList(containingArt));
   }

   @Test(expected = OseeInvalidInheritanceException.class)
   public void testBaseArtifact() throws OseeCoreException {
      List<ArtifactType> input = new ArrayList<ArtifactType>();
      ArtifactSuperTypeField field = new ArtifactSuperTypeField(containingArt, input);
      Assert.assertEquals(false, field.isDirty());

      field.set(Collections.<ArtifactType> emptyList());
   }

   @Test
   public void testBaseArtifactNoSuperTypeRequired() throws OseeCoreException {
      List<ArtifactType> input = new ArrayList<ArtifactType>();
      ArtifactSuperTypeField field = new ArtifactSuperTypeField(base, input);
      Assert.assertEquals(false, field.isDirty());

      field.set(Collections.<ArtifactType> emptyList());
   }
}

Back to the top