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

import static org.eclipse.osee.framework.core.enums.DeletionFlag.EXCLUDE_DELETED;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.jdk.core.util.Collections;
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.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.support.test.util.DemoSawBuilds;
import org.junit.AfterClass;
import org.junit.BeforeClass;

/**
 * @author Donald G. Dunne
 */
public class ArtifactSetAttributeValuesTest {

   private static List<String> firstSet = Arrays.asList("First", "Second", "Third");
   private static List<String> addOneSet = Arrays.asList("First", "Second", "Third", "Fourth");
   private static List<String> addOneRemoveOneSet = Arrays.asList("Second", "Third", "Fourth", "Fifth");
   private static List<String> addDuplicates_set = Arrays.asList("Second", "Second", "Third", "Fourth", "Fifth",
      "Fourth");
   private static List<String> addDuplicates_result = Arrays.asList("Second", "Third", "Fifth", "Fourth");
   private static List<String> emptySet = Arrays.asList();

   @BeforeClass
   public static void testCleanupPre() throws Exception {
      cleanup();
   }

   @org.junit.Test
   public void testSetAttributeValues() throws Exception {
      Artifact artifact =
         ArtifactTypeManager.addArtifact(CoreArtifactTypes.GeneralDocument, DemoSawBuilds.SAW_Bld_1,
            getClass().getSimpleName());
      artifact.setAttributeValues(CoreAttributeTypes.StaticId, firstSet);
      artifact.persist(getClass().getSimpleName());

      assertTrue(Collections.isEqual(firstSet, artifact.getAttributesToStringList(CoreAttributeTypes.StaticId)));
   }

   @org.junit.Test
   public void testSetAttributeValuesAddOne() throws Exception {
      Artifact artifact = getArtifact();
      artifact.setAttributeValues(CoreAttributeTypes.StaticId, addOneSet);
      artifact.persist(getClass().getSimpleName());

      assertTrue(Collections.isEqual(addOneSet, artifact.getAttributesToStringList(CoreAttributeTypes.StaticId)));
   }

   @org.junit.Test
   public void testSetAttributeValuesAddOneRemoveOne() throws Exception {
      Artifact artifact = getArtifact();
      artifact.setAttributeValues(CoreAttributeTypes.StaticId, addOneRemoveOneSet);
      artifact.persist(getClass().getSimpleName());

      assertTrue(Collections.isEqual(addOneRemoveOneSet,
         artifact.getAttributesToStringList(CoreAttributeTypes.StaticId)));
   }

   @org.junit.Test
   public void testSetAttributeValuesRemoveAll() throws Exception {
      Artifact artifact = getArtifact();
      artifact.setAttributeValues(CoreAttributeTypes.StaticId, emptySet);
      artifact.persist(getClass().getSimpleName());

      assertTrue(artifact.getAttributesToStringList(CoreAttributeTypes.StaticId).isEmpty());
   }

   @org.junit.Test
   public void testSetAttributeValuesWithDuplicates() throws Exception {
      Artifact artifact = getArtifact();
      artifact.setAttributeValues(CoreAttributeTypes.StaticId, addDuplicates_set);
      artifact.persist(getClass().getSimpleName());

      assertTrue(Collections.isEqual(addDuplicates_result,
         artifact.getAttributesToStringList(CoreAttributeTypes.StaticId)));
   }

   @AfterClass
   public static void testCleanupPost() throws Exception {
      cleanup();
   }

   private Artifact getArtifact() throws Exception {
      return ArtifactQuery.getArtifactListFromName(getClass().getSimpleName(), DemoSawBuilds.SAW_Bld_1, EXCLUDE_DELETED).iterator().next();
   }

   private static void cleanup() throws Exception {
      Collection<Artifact> arts =
         ArtifactQuery.getArtifactListFromName(ArtifactSetAttributeValuesTest.class.getSimpleName(),
            DemoSawBuilds.SAW_Bld_1, EXCLUDE_DELETED);
      Operations.executeWorkAndCheckStatus(new PurgeArtifacts(arts));
   }
}

Back to the top