Skip to main content
summaryrefslogtreecommitdiffstats
blob: d61b7b9aa40063212eb937348a5ef7d281f7a716 (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
/*******************************************************************************
 * 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.orcs.api;

import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON_ID;
import static org.eclipse.osee.framework.core.enums.DemoBranches.SAW_Bld_1;
import static org.eclipse.osee.orcs.OrcsIntegrationRule.integrationRule;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.db.mock.OsgiService;
import org.eclipse.osee.orcs.search.QueryBuilder;
import org.eclipse.osee.orcs.search.QueryFactory;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;

/**
 * @author Jeff C. Phillips
 */
public class OrcsAttributeLoadingTest {

   @Rule
   public TestRule osgi = integrationRule(this);

   @OsgiService
   private OrcsApi orcsApi;

   private QueryFactory query;

   @Before
   public void setUp() throws Exception {
      query = orcsApi.getQueryFactory();
   }

   @Test
   public void testAttributeLoading() throws Exception {
      QueryBuilder builder = query.fromBranch(COMMON_ID).andUuids(Arrays.asList(6L, 7L, 8L));
      ResultSet<ArtifactReadable> resultSet = builder.getResults();

      assertEquals(3, resultSet.size());
      assertEquals(3, builder.getCount());

      Map<Integer, ArtifactReadable> lookup = createLookup(resultSet);
      lookup.get(6);
      ArtifactReadable art7 = lookup.get(7);
      ArtifactReadable art8 = lookup.get(8);

      //Test loading name attributes
      assertEquals(art7.getSoleAttributeAsString(CoreAttributeTypes.Name), "User Groups");
      assertEquals(art8.getSoleAttributeAsString(CoreAttributeTypes.Name), "Everyone");

      //Test boolean attributes
      assertEquals(art8.getSoleAttributeAsString(CoreAttributeTypes.DefaultGroup), "true");
   }

   @Test
   public void testLoadWordTemplateContentAttributes() throws OseeCoreException {
      QueryBuilder builder = query.fromBranch(SAW_Bld_1).and(CoreAttributeTypes.Name, "Haptic Constraints");

      ResultSet<ArtifactReadable> resultSet = builder.getResults();

      ArtifactReadable artifact = resultSet.iterator().next();
      assertTrue(artifact.getSoleAttributeAsString(CoreAttributeTypes.WordTemplateContent).length() > 2);

      assertFalse(resultSet.isEmpty());
      assertEquals(resultSet.size(), builder.getCount());
   }

   private Map<Integer, ArtifactReadable> createLookup(Iterable<ArtifactReadable> arts) {
      Map<Integer, ArtifactReadable> lookup = new HashMap<>();
      for (ArtifactReadable artifact : arts) {
         lookup.put(artifact.getLocalId(), artifact);
      }
      return lookup;
   }
}

Back to the top