This project has retired. For details please refer to its
Attic page.
BusinessQueryManager2Test xref
1 package org.apache.ws.scout.registry;
2
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.fail;
5
6 import java.util.ArrayList;
7 import java.util.Collection;
8 import java.util.Iterator;
9
10 import javax.xml.registry.BulkResponse;
11 import javax.xml.registry.BusinessLifeCycleManager;
12 import javax.xml.registry.BusinessQueryManager;
13 import javax.xml.registry.JAXRException;
14 import javax.xml.registry.LifeCycleManager;
15 import javax.xml.registry.RegistryService;
16 import javax.xml.registry.infomodel.Association;
17 import javax.xml.registry.infomodel.ClassificationScheme;
18 import javax.xml.registry.infomodel.Concept;
19 import javax.xml.registry.infomodel.Key;
20 import javax.xml.registry.infomodel.Organization;
21
22
23 import org.apache.ws.scout.BaseTestCase;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27
28
29
30
31
32
33 public class BusinessQueryManager2Test extends BaseTestCase {
34 RegistryService rs, rs2;
35 private BusinessQueryManager bqm, bqm2;
36 private BusinessLifeCycleManager blm, blm2;
37 Collection associationKeys = null;
38
39 @Before
40 public void setUp() {
41 super.setUp();
42 login();
43 loginSecondUser();
44 try {
45 rs = connection.getRegistryService();
46 bqm = rs.getBusinessQueryManager();
47 blm = rs.getBusinessLifeCycleManager();
48
49 rs2 = connection2.getRegistryService();
50 blm2 = rs2.getBusinessLifeCycleManager();
51 bqm2 = rs2.getBusinessQueryManager();
52
53 } catch (JAXRException e) {
54 fail(e.getMessage());
55 }
56 }
57
58 @After
59 public void tearDown() {
60 super.tearDown();
61 }
62
63 @Test
64 public void testGetRegistryObjects() {
65 login();
66 try {
67 RegistryService rs = connection.getRegistryService();
68
69 BusinessQueryManager bqm = rs.getBusinessQueryManager();
70 @SuppressWarnings("unused")
71 BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
72 @SuppressWarnings("unused")
73 BulkResponse br = bqm.getRegistryObjects();
74 } catch (JAXRException e) {
75 e.printStackTrace();
76 }
77 }
78
79 @Test
80 public void testFindCallerAssociations() {
81 BulkResponse br = null;
82 try {
83
84 try {
85 br = bqm.findCallerAssociations(null,
86 new Boolean(true),
87 new Boolean(true),
88 null);
89 if (br.getCollection().size() != 0) {
90 fail("Should not reach here - no associations created yet.");
91 }
92 } catch (Exception e) {
93 }
94
95 String orgOne = "Organization One";
96 String orgTwo = "Organization Two";
97 Organization source = blm.createOrganization(blm.createInternationalString(orgOne));
98 Organization target = blm2.createOrganization(blm2.createInternationalString(orgTwo));
99
100 Collection orgs = new ArrayList();
101 orgs.add(source);
102 br = blm.saveOrganizations(orgs);
103 if (br.getExceptions() != null)
104 {
105 fail("Save Organization failed");
106 }
107
108 Collection sourceKeys = br.getCollection();
109 Iterator iter = sourceKeys.iterator();
110 Key savekey = null;
111 while (iter.hasNext())
112 {
113 savekey = (Key) iter.next();
114 }
115 String sourceid = savekey.getId();
116 Organization queried = (Organization) bqm.getRegistryObject(sourceid, LifeCycleManager.ORGANIZATION);
117 assertNotNull("Source Org", queried.getName().getValue());
118
119 Collection orgstwo = new ArrayList();
120 orgstwo.add(target);
121 br = blm2.saveOrganizations(orgstwo);
122 if (br.getExceptions() != null)
123 {
124 fail("Save Organizations failed");
125 }
126 Collection targetKeys = br.getCollection();
127 iter = targetKeys.iterator();
128 while (iter.hasNext())
129 {
130 savekey = (Key) iter.next();
131 }
132
133 String targetid = savekey.getId();
134 Organization targetOrg = (Organization) bqm2.getRegistryObject(targetid, LifeCycleManager.ORGANIZATION);
135 assertNotNull("Target Org", targetOrg.getName().getValue());
136
137 Concept associationType = null;
138 ClassificationScheme associationTypes =
139 bqm.findClassificationSchemeByName(null, "AssociationType");
140 Collection types = associationTypes.getChildrenConcepts();
141 iter = types.iterator();
142 Concept concept = null;
143 while (iter.hasNext())
144 {
145 concept = (Concept) iter.next();
146 if (concept.getName().getValue().equals("Implements"))
147 {
148 associationType = concept;
149 }
150 }
151
152 Association a = blm.createAssociation(targetOrg, associationType);
153 a.setSourceObject(queried);
154 blm2.confirmAssociation(a);
155
156
157 Collection associations = new ArrayList();
158 associations.add(a);
159 br = blm2.saveAssociations(associations, false);
160
161 if (br.getExceptions() != null)
162 {
163 fail("Save association failed");
164 }
165
166 associationKeys = br.getCollection();
167 iter = associationKeys.iterator();
168
169 Collection aTypes = new ArrayList();
170 aTypes.add(associationType);
171
172 br = bqm.findCallerAssociations(null,
173 new Boolean(true),
174 new Boolean(true),
175 aTypes);
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191 } catch (JAXRException e) {
192 fail(e.getMessage());
193 }
194 }
195
196 @Test (expected=JAXRException.class)
197 public void testFindRegistryPackages() throws JAXRException{
198 login();
199
200 RegistryService rs = connection.getRegistryService();
201
202 BusinessQueryManager bqm = rs.getBusinessQueryManager();
203 @SuppressWarnings("unused")
204 BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
205
206 Concept type = bqm.findConceptByPath("/AssociationType/RelatedTo");
207
208 ArrayList namePatterns = new ArrayList();
209 namePatterns.add("%foo%");
210
211 ArrayList classifications = new ArrayList();
212 classifications.add(type);
213
214 @SuppressWarnings("unused")
215 BulkResponse br = bqm.findRegistryPackages(null, namePatterns, classifications, null);
216 fail("findRegistryPackages is currently unsupported");
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234 }
235
236 }