001: /**
002: *
003: * Copyright 2004 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.ws.scout.registry.qa;
017:
018: import static org.junit.Assert.fail;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Iterator;
023:
024: import javax.xml.registry.BulkResponse;
025: import javax.xml.registry.BusinessLifeCycleManager;
026: import javax.xml.registry.JAXRException;
027: import javax.xml.registry.JAXRResponse;
028: import javax.xml.registry.RegistryService;
029: import javax.xml.registry.infomodel.Concept;
030: import javax.xml.registry.infomodel.ExternalLink;
031: import javax.xml.registry.infomodel.InternationalString;
032: import javax.xml.registry.infomodel.Key;
033: import javax.xml.registry.infomodel.Organization;
034: import javax.xml.registry.infomodel.Service;
035: import javax.xml.registry.infomodel.ServiceBinding;
036: import javax.xml.registry.infomodel.SpecificationLink;
037:
038: import junit.framework.JUnit4TestAdapter;
039:
040: import org.apache.ws.scout.BaseTestCase;
041: import org.junit.After;
042: import org.junit.Before;
043: import org.junit.Test;
044:
045: /**
046: Tests Publish, Delete (and indirectly, find) for service bindings.
047: *
048: * You can comment out the deletion portion and use
049: * Open source UDDI Browser <http://www.uddibrowser.org>
050: * to check your intermediate results
051: *
052: * Based on query/publish tests written by
053: * <a href="mailto:anil@apache.org">Anil Saldhana</a>.
054: *
055: * @author <a href="mailto:dbhole@redhat.com">Deepak Bhole</a>
056: * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
057: *
058: * @since Sep 27, 2005
059: */
060: public class JAXR050ServiceBindingTest extends BaseTestCase {
061:
062: String serviceBindingName = "Apache JAXR Service Binding -- APACHE SCOUT TEST";
063: String serviceName = "Apache JAXR Service -- APACHE SCOUT TEST";
064: String tempOrgName = "Apache JAXR Service Org -- APACHE SCOUT TEST";
065:
066: @Before
067: public void setUp() {
068: super .setUp();
069: }
070:
071: @After
072: public void tearDown() {
073: super .tearDown();
074: }
075:
076: /**
077: * Tests publishing and deleting of service bindings.
078: *
079: * Do not break this into testPublish(), testDelete(), etc. Order is
080: * important, and not all jvms can guarantee order since the JUnit framework
081: * uses getMethods() to gather test methods, and getMethods() does not
082: * guarantee order.
083: */
084: @Test
085: public void testPublishFindAndDeleteServiceBinding() {
086: login();
087: try {
088: RegistryService rs = connection.getRegistryService();
089: blm = rs.getBusinessLifeCycleManager();
090:
091: System.out
092: .println("\nCreating temporary organization...\n");
093: Organization tmpOrg = createTempOrg();
094: Key tmpOrgKey = tmpOrg.getKey();
095:
096: System.out.println("\nCreating service...\n");
097: Service tmpSvc = createTempService(tmpOrg);
098: Key tmpSvcKey = tmpSvc.getKey();
099:
100: System.out.println("\nCreating service binding...\n");
101: Key sbKey = createServiceBinding(tmpSvc);
102:
103: // All created ... now try to delete.
104: deleteServiceBinding(sbKey);
105: deleteTempService(tmpSvcKey);
106: deleteTempOrg(tmpOrgKey);
107: // No find service binding.. search by name is not currently supported.
108:
109: deleteServiceBinding(sbKey);
110:
111: } catch (JAXRException e) {
112: e.printStackTrace();
113: fail(e.getMessage());
114: }
115: }
116:
117: private Key createServiceBinding(Service tmpSvc)
118: throws JAXRException {
119: Key key = null;
120: ServiceBinding serviceBinding = blm.createServiceBinding();
121: serviceBinding.setName(getIString(serviceBindingName));
122: serviceBinding
123: .setDescription(getIString("UDDI service binding"));
124: tmpSvc.addServiceBinding(serviceBinding);
125:
126: SpecificationLink specLink = blm.createSpecificationLink();
127: ExternalLink externalLink = blm.createExternalLink(
128: "http://localhost:8080/jmx-console", "Scout test");
129: Collection<ExternalLink> externalLinks = new ArrayList<ExternalLink>();
130: externalLinks.add(externalLink);
131: specLink.setExternalLinks(externalLinks);
132:
133: RegistryService rs = connection.getRegistryService();
134: bqm = rs.getBusinessQueryManager();
135: Concept concept = (Concept) bqm.getRegistryObject(
136: "uuid:AD61DE98-4DB8-31B2-A299-A2373DC97212",
137: BusinessLifeCycleManager.CONCEPT);
138: specLink.setSpecificationObject(concept);
139:
140: serviceBinding.addSpecificationLink(specLink);
141:
142: ArrayList<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
143: serviceBindings.add(serviceBinding);
144:
145: BulkResponse br = blm.saveServiceBindings(serviceBindings);
146: if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
147: System.out.println("Service Binding Saved");
148: key = (Key) br.getCollection().iterator().next();
149: System.out.println("Saved Key=" + key.getId());
150: } else {
151: System.err.println("JAXRExceptions "
152: + "occurred during save:");
153: Collection exceptions = br.getExceptions();
154: Iterator iter = exceptions.iterator();
155: while (iter.hasNext()) {
156: Exception e = (Exception) iter.next();
157: System.err.println(e.toString());
158: fail(e.toString());
159: }
160: }
161:
162: return key;
163: }
164:
165: private void deleteServiceBinding(Key key) throws JAXRException {
166:
167: String id = key.getId();
168:
169: System.out.println("\nDeleting service binding with id " + id
170: + "\n");
171:
172: Collection<Key> keys = new ArrayList<Key>();
173: keys.add(key);
174: BulkResponse response = blm.deleteServiceBindings(keys);
175:
176: Collection exceptions = response.getExceptions();
177: if (exceptions == null) {
178: Collection retKeys = response.getCollection();
179: Iterator keyIter = retKeys.iterator();
180: javax.xml.registry.infomodel.Key orgKey = null;
181: if (keyIter.hasNext()) {
182: orgKey = (javax.xml.registry.infomodel.Key) keyIter
183: .next();
184: id = orgKey.getId();
185: System.out.println("Service binding with ID=" + id
186: + " was deleted");
187: }
188: }
189: }
190:
191: private Service createTempService(Organization tmpOrg)
192: throws JAXRException {
193:
194: Service service = blm.createService(getIString(serviceName));
195: service.setDescription(getIString("Services in UDDI Registry"));
196: service.setProvidingOrganization(tmpOrg);
197:
198: ArrayList<Service> services = new ArrayList<Service>();
199: services.add(service);
200:
201: BulkResponse br = blm.saveServices(services);
202: if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
203: System.out.println("Service Saved");
204: Key key = (Key) br.getCollection().iterator().next();
205: System.out.println("Saved Key=" + key.getId());
206: service.setKey(key);
207: } else {
208: System.err.println("JAXRExceptions "
209: + "occurred during save:");
210: Collection exceptions = br.getExceptions();
211: Iterator iter = exceptions.iterator();
212: while (iter.hasNext()) {
213: Exception e = (Exception) iter.next();
214: System.err.println(e.toString());
215: }
216: }
217:
218: return service;
219: }
220:
221: private void deleteTempService(Key key) throws JAXRException {
222:
223: String id = key.getId();
224:
225: System.out.println("\nDeleting service with id " + id + "\n");
226:
227: Collection<Key> keys = new ArrayList<Key>();
228: keys.add(key);
229: BulkResponse response = blm.deleteServices(keys);
230:
231: Collection exceptions = response.getExceptions();
232: if (exceptions == null) {
233: Collection retKeys = response.getCollection();
234: Iterator keyIter = retKeys.iterator();
235: javax.xml.registry.infomodel.Key orgKey = null;
236: if (keyIter.hasNext()) {
237: orgKey = (javax.xml.registry.infomodel.Key) keyIter
238: .next();
239: id = orgKey.getId();
240: System.out.println("Service with ID=" + id
241: + " was deleted");
242: }
243: }
244: }
245:
246: private Organization createTempOrg() throws JAXRException {
247:
248: Key orgKey = null;
249: Organization org = blm
250: .createOrganization(getIString(tempOrgName));
251: org
252: .setDescription(getIString("Temporary organization to test saveService()"));
253:
254: Collection<Organization> orgs = new ArrayList<Organization>();
255: orgs.add(org);
256: BulkResponse br = blm.saveOrganizations(orgs);
257:
258: if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
259: orgKey = (Key) br.getCollection().iterator().next();
260: System.out
261: .println("Temporary Organization Created with id="
262: + orgKey.getId());
263: org.setKey(orgKey);
264: } else {
265: System.err
266: .println("JAXRExceptions "
267: + "occurred during creation of temporary organization:");
268:
269: Iterator iter = br.getCollection().iterator();
270:
271: while (iter.hasNext()) {
272: Exception e = (Exception) iter.next();
273: System.err.println(e.toString());
274: }
275:
276: fail();
277: }
278:
279: return org;
280: }
281:
282: private void deleteTempOrg(Key key) throws JAXRException {
283:
284: if (key == null) {
285: return;
286: }
287:
288: String id = key.getId();
289:
290: System.out.println("\nDeleting temporary organization with id "
291: + id + "\n");
292:
293: Collection<Key> keys = new ArrayList<Key>();
294: keys.add(key);
295: BulkResponse response = blm.deleteOrganizations(keys);
296:
297: Collection exceptions = response.getExceptions();
298: if (exceptions == null) {
299: Collection retKeys = response.getCollection();
300: Iterator keyIter = retKeys.iterator();
301: Key orgKey = null;
302: if (keyIter.hasNext()) {
303: orgKey = (javax.xml.registry.infomodel.Key) keyIter
304: .next();
305: id = orgKey.getId();
306: System.out.println("Organization with ID=" + id
307: + " was deleted");
308: }
309: }
310: }
311:
312: private InternationalString getIString(String str)
313: throws JAXRException {
314: return blm.createInternationalString(str);
315: }
316:
317: public static junit.framework.Test suite() {
318: return new JUnit4TestAdapter(JAXR050ServiceBindingTest.class);
319: }
320: }
|