This project has retired. For details please refer to its
Attic page.
JAXR040ServiceTest xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ws.scout.registry.qa;
18
19 import static org.junit.Assert.fail;
20
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Iterator;
24
25 import javax.xml.registry.BulkResponse;
26 import javax.xml.registry.BusinessQueryManager;
27 import javax.xml.registry.FindQualifier;
28 import javax.xml.registry.JAXRException;
29 import javax.xml.registry.JAXRResponse;
30 import javax.xml.registry.RegistryService;
31 import javax.xml.registry.infomodel.InternationalString;
32 import javax.xml.registry.infomodel.Key;
33 import javax.xml.registry.infomodel.Organization;
34 import javax.xml.registry.infomodel.Service;
35
36 import junit.framework.JUnit4TestAdapter;
37
38 import org.apache.ws.scout.BaseTestCase;
39 import org.junit.After;
40 import org.junit.Before;
41 import org.junit.Test;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 public class JAXR040ServiceTest extends BaseTestCase
59 {
60 private BusinessQueryManager bqm = null;
61
62 String serviceName = "Apache JAXR Service -- APACHE SCOUT TEST";
63 String tempOrgName = "Apache JAXR Service Org -- APACHE SCOUT TEST";
64
65 @Before
66 public void setUp()
67 {
68 super.setUp();
69 }
70
71 @After
72 public void tearDown()
73 {
74 super.tearDown();
75 }
76
77
78
79
80
81
82
83
84
85 @Test
86 public void testPublishFindAndDeleteService()
87 {
88 login();
89 try
90 {
91 RegistryService rs = connection.getRegistryService();
92 bqm = rs.getBusinessQueryManager();
93 blm = rs.getBusinessLifeCycleManager();
94
95 System.out.println("\nCreating temporary organization...\n");
96 Organization org = createTempOrg();
97
98 System.out.println("\nCreating service...\n");
99 createService(org);
100
101
102
103 findAndDeleteService(org.getKey());
104 deleteTempOrg(org.getKey());
105
106 } catch (JAXRException e)
107 {
108 e.printStackTrace();
109 fail(e.getMessage());
110 }
111 }
112
113
114 private void createService(Organization org) throws JAXRException {
115 Service service = blm.createService(getIString(serviceName));
116 service.setDescription(getIString("Services in UDDI Registry"));
117 service.setProvidingOrganization(org);
118
119 ArrayList<Service> services = new ArrayList<Service>();
120 services.add(service);
121
122 BulkResponse br = blm.saveServices(services);
123 if (br.getStatus() == JAXRResponse.STATUS_SUCCESS)
124 {
125 System.out.println("Service Saved");
126 Collection coll = br.getCollection();
127 Iterator iter = coll.iterator();
128 while (iter.hasNext())
129 {
130 Key key = (Key) iter.next();
131 System.out.println("Saved Key=" + key.getId());
132 }
133 } else
134 {
135 System.err.println("JAXRExceptions " +
136 "occurred during save:");
137 Collection exceptions = br.getExceptions();
138 Iterator iter = exceptions.iterator();
139 while (iter.hasNext())
140 {
141 Exception e = (Exception) iter.next();
142 System.err.println(e.toString());
143 fail(e.toString());
144 }
145 }
146 }
147
148 private void findAndDeleteService(Key orgKey) throws JAXRException {
149 Collection<String> findQualifiers = new ArrayList<String>();
150 findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
151 Collection<String> namePatterns = new ArrayList<String>();
152 namePatterns.add("%" + serviceName + "%");
153
154 BulkResponse br = bqm.findServices(orgKey, findQualifiers, namePatterns, null, null);
155 Collection services = br.getCollection();
156
157 if (services == null)
158 {
159 System.out.println("\n-- Matched 0 orgs");
160
161 } else
162 {
163 System.out.println("\n-- Matched " + services.size() + " services --\n");
164
165
166 for (Iterator conceptIter = services.iterator(); conceptIter.hasNext();)
167 {
168 Service s = (Service) conceptIter.next();
169
170 System.out.println("Id: " + s.getKey().getId());
171 System.out.println("Name: " + s.getName().getValue());
172
173
174 System.out.println(" --- ");
175
176 deleteService(s.getKey());
177
178 System.out.println("\n ============================== \n");
179 }
180 }
181 }
182
183 private void deleteService(Key key) throws JAXRException {
184
185 String id = key.getId();
186
187 System.out.println("\nDeleting service with id " + id + "\n");
188
189 Collection<Key> keys = new ArrayList<Key>();
190 keys.add(key);
191 BulkResponse response = blm.deleteServices(keys);
192
193 Collection exceptions = response.getExceptions();
194 if (exceptions == null) {
195 Collection retKeys = response.getCollection();
196 Iterator keyIter = retKeys.iterator();
197 javax.xml.registry.infomodel.Key orgKey = null;
198 if (keyIter.hasNext()) {
199 orgKey =
200 (javax.xml.registry.infomodel.Key) keyIter.next();
201 id = orgKey.getId();
202 System.out.println("Service with ID=" + id + " was deleted");
203 }
204 }
205 }
206
207 private Organization createTempOrg() throws JAXRException {
208
209 Key orgKey = null;
210 Organization org = blm.createOrganization(getIString(tempOrgName));
211 org.setDescription(getIString("Temporary organization to test saveService()"));
212
213 Collection<Organization> orgs = new ArrayList<Organization>();
214 orgs.add(org);
215 BulkResponse br = blm.saveOrganizations(orgs);
216
217 if (br.getStatus() == JAXRResponse.STATUS_SUCCESS)
218 {
219 orgKey = (Key) br.getCollection().iterator().next();
220 System.out.println("Temporary Organization Created with id=" + orgKey.getId());
221 org.setKey(orgKey);
222 } else
223 {
224 System.err.println("JAXRExceptions " +
225 "occurred during creation of temporary organization:");
226
227 Iterator iter = br.getCollection().iterator();
228
229 while (iter.hasNext()) {
230 Exception e = (Exception) iter.next();
231 System.err.println(e.toString());
232 }
233
234 fail();
235 }
236
237 return org;
238 }
239
240 private void deleteTempOrg(Key orgKey) throws JAXRException {
241
242 String id = orgKey.getId();
243
244 System.out.println("\nDeleting temporary organization with id " + id + "\n");
245
246 Collection<Key> keys = new ArrayList<Key>();
247 keys.add(orgKey);
248 BulkResponse response = blm.deleteOrganizations(keys);
249
250 Collection exceptions = response.getExceptions();
251 if (exceptions == null) {
252 Collection retKeys = response.getCollection();
253 Iterator keyIter = retKeys.iterator();
254 orgKey = null;
255 if (keyIter.hasNext()) {
256 orgKey =
257 (javax.xml.registry.infomodel.Key) keyIter.next();
258 id = orgKey.getId();
259 System.out.println("Organization with ID=" + id + " was deleted");
260 }
261 }
262 }
263
264 private InternationalString getIString(String str)
265 throws JAXRException
266 {
267 return blm.createInternationalString(str);
268 }
269
270 public static junit.framework.Test suite() {
271 return new JUnit4TestAdapter(JAXR040ServiceTest.class);
272 }
273 }