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
|
/*******************************************************************************
* 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 java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.eclipse.osee.framework.core.data.ResultSet;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.cache.BranchCache;
import org.eclipse.osee.orcs.ApplicationContext;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.OrcsIntegrationRule;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.db.mock.OseeDatabase;
import org.eclipse.osee.orcs.db.mock.OsgiService;
import org.eclipse.osee.orcs.search.Operator;
import org.eclipse.osee.orcs.search.QueryBuilder;
import org.eclipse.osee.orcs.search.QueryFactory;
import org.junit.Rule;
/**
* @author Jeff C. Phillips
*/
public class OrcsAttributeLoadingTest {
@Rule
public OrcsIntegrationRule osgi = new OrcsIntegrationRule(this);
@Rule
public OseeDatabase db = new OseeDatabase("osee.demo.h2");
@OsgiService
OrcsApi orcsApi;
@org.junit.Test
public void testAttributeLoading() throws Exception {
ApplicationContext context = null; // TODO use real application context
QueryFactory queryFactory = orcsApi.getQueryFactory(context);
QueryBuilder builder = queryFactory.fromBranch(CoreBranches.COMMON).andLocalIds(Arrays.asList(7, 8, 9));
ResultSet<ArtifactReadable> resultSet = builder.getResults();
List<ArtifactReadable> moreArts = resultSet.getList();
Assert.assertEquals(3, moreArts.size());
Assert.assertEquals(3, builder.getCount());
Map<Integer, ArtifactReadable> lookup = creatLookup(moreArts);
ArtifactReadable art7 = lookup.get(7);
ArtifactReadable art8 = lookup.get(8);
ArtifactReadable art9 = lookup.get(9);
//Test loading name attributes
Assert.assertEquals(art7.getSoleAttributeAsString(CoreAttributeTypes.Name),
"org.eclipse.osee.ats.config.demo.OseeTypes_Demo");
Assert.assertEquals(art8.getSoleAttributeAsString(CoreAttributeTypes.Name), "User Groups");
Assert.assertEquals(art9.getSoleAttributeAsString(CoreAttributeTypes.Name), "Everyone");
//Test boolean attributes
Assert.assertEquals(art9.getSoleAttributeAsString(CoreAttributeTypes.DefaultGroup), "true");
//Load WTC attributes
loadWordTemplateContentAttributes(queryFactory, orcsApi.getBranchCache());
}
private void loadWordTemplateContentAttributes(QueryFactory queryFactory, BranchCache branchCache) throws OseeCoreException {
QueryBuilder builder =
queryFactory.fromBranch(branchCache.getByName("SAW_Bld_1").iterator().next()).and(CoreAttributeTypes.Name,
Operator.EQUAL, "Haptic Constraints");
ResultSet<ArtifactReadable> resultSet = builder.getResults();
List<ArtifactReadable> moreArts = resultSet.getList();
Assert.assertFalse(moreArts.isEmpty());
Assert.assertTrue(builder.getCount() > 0);
ArtifactReadable artifact = moreArts.iterator().next();
Assert.assertTrue(artifact.getSoleAttributeAsString(CoreAttributeTypes.WordTemplateContent).length() > 2);
}
Map<Integer, ArtifactReadable> creatLookup(List<ArtifactReadable> arts) {
Map<Integer, ArtifactReadable> lookup = new HashMap<Integer, ArtifactReadable>();
for (ArtifactReadable artifact : arts) {
lookup.put(artifact.getLocalId(), artifact);
}
return lookup;
}
}
|