001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.jaxr.scout.publish;
023:
024: import org.jboss.test.jaxr.scout.JaxrBaseTestCase;
025:
026: import javax.xml.registry.BulkResponse;
027: import javax.xml.registry.JAXRException;
028: import javax.xml.registry.LifeCycleManager;
029: import javax.xml.registry.infomodel.Concept;
030: import javax.xml.registry.infomodel.Key;
031: import javax.xml.registry.infomodel.Organization;
032: import javax.xml.registry.infomodel.Service;
033: import javax.xml.registry.infomodel.ServiceBinding;
034: import javax.xml.registry.infomodel.SpecificationLink;
035: import java.util.ArrayList;
036: import java.util.Collection;
037: import java.util.Iterator;
038:
039: /**
040: * Tests Saving ServiceBindings
041: *
042: * @author <mailto:Anil.Saldhana@jboss.org>Anil Saldhana
043: * @since Mar 8, 2005
044: */
045: public class JaxrSaveServiceBindingTestCase extends JaxrBaseTestCase {
046: /**
047: * @throws JAXRException
048: */
049: public void testSaveServiceBinding() throws JAXRException {
050: String serviceName = "jbosstestService";
051: String sbDescription = "jbosstest sb description";
052:
053: String conceptName = "jbosstest concept";
054: Collection sbKeys = null;
055: Collection serviceKeys = null;
056: Collection orgKeys = null;
057: Collection conceptKeys = null;
058: Key conceptKey = null;
059: Key serviceKey = null;
060: Key orgKey = null;
061:
062: String accessURI = "http://myhost/jaxrTest.jsp";
063: login();
064:
065: try {
066: getJAXREssentials();
067: String orgname = "Jaxr Org";
068: Organization org = blm
069: .createOrganization(getIString(orgname));
070: Collection orgs = new ArrayList();
071: orgs.add(org);
072: BulkResponse br = blm.saveOrganizations(orgs);
073: if (br.getExceptions() != null) {
074: fail("Save Organizations failed ");
075: }
076: orgKeys = br.getCollection();
077: Iterator iter = orgKeys.iterator();
078: while (iter.hasNext()) {
079: orgKey = (Key) iter.next();
080: }
081:
082: org = (Organization) bqm.getRegistryObject(orgKey.getId(),
083: LifeCycleManager.ORGANIZATION);
084:
085: Service service = blm.createService(serviceName);
086: org.addService(service);
087: Collection services = new ArrayList();
088: services.add(service);
089: br = blm.saveServices(services);
090: if (br.getExceptions() != null) {
091: fail("Save Services failed ");
092: }
093: serviceKeys = br.getCollection();
094: iter = serviceKeys.iterator();
095: while (iter.hasNext()) {
096: serviceKey = (Key) iter.next();
097: }
098:
099: service = (Service) bqm.getRegistryObject(serviceKey
100: .getId(), LifeCycleManager.SERVICE);
101:
102: //Save some concepts
103: Concept testConcept = (Concept) blm
104: .createObject(LifeCycleManager.CONCEPT);
105: testConcept.setName(blm
106: .createInternationalString(conceptName));
107: Collection concepts = new ArrayList();
108: concepts.add(testConcept);
109: br = blm.saveConcepts(concepts);
110: if (br.getExceptions() != null) {
111: fail("Save Concepts failed ");
112: }
113: conceptKeys = br.getCollection();
114: iter = conceptKeys.iterator();
115: while (iter.hasNext()) {
116: conceptKey = (Key) iter.next();
117: }
118:
119: testConcept = (Concept) bqm.getRegistryObject(conceptKey
120: .getId(), LifeCycleManager.CONCEPT);
121: SpecificationLink sl = blm.createSpecificationLink();
122: sl.setSpecificationObject(testConcept);
123: ServiceBinding sb = blm.createServiceBinding();
124: sb.setDescription(blm
125: .createInternationalString(sbDescription));
126: sb.setAccessURI(accessURI);
127: sb.addSpecificationLink(sl);
128: service.addServiceBinding(sb);
129: Collection sbs = new ArrayList();
130: sbs.add(sb);
131: br = blm.saveServiceBindings(sbs);
132: if (br.getExceptions() != null) {
133: fail("Save ServiceBindings failed ");
134: }
135:
136: Collection specifications = new ArrayList();
137: specifications.add(testConcept);
138:
139: br = bqm.findServiceBindings(serviceKey, null, null,
140: specifications);
141: sbs = br.getCollection();
142: iter = sbs.iterator();
143: while (iter.hasNext()) {
144: sb = (ServiceBinding) iter.next();
145: Service storedService = sb.getService();
146: if (!(storedService.getName().getValue()
147: .equals(serviceName))) {
148: fail("Error: service name");
149: }
150: Organization storedOrg = storedService
151: .getProvidingOrganization();
152: if (!(storedOrg.getName().getValue().equals(orgname))) {
153: fail("Error: unexpected organization name \n");
154: }
155: if (!(sb.getDescription().getValue()
156: .equals(sbDescription))) {
157: fail("Error: servicebinding description");
158: }
159: if (!(sb.getAccessURI().equals(accessURI))) {
160: fail("Error: unexpected accessURI name");
161: }
162: }
163:
164: //Lets update the ServiceBinding
165: sbs = new ArrayList();
166: sb.setAccessURI("http://newURI");
167: sbs.add(sb);
168: br = blm.saveServiceBindings(sbs);
169: br = bqm.findServiceBindings(serviceKey, null, null,
170: specifications);
171: sbs = br.getCollection();
172: iter = sbs.iterator();
173: while (iter.hasNext()) {
174: sb = (ServiceBinding) iter.next();
175: Service storedService = sb.getService();
176: if (!(storedService.getName().getValue()
177: .equals(serviceName))) {
178: fail("Error: service name");
179: }
180: Organization storedOrg = storedService
181: .getProvidingOrganization();
182: if (!(storedOrg.getName().getValue().equals(orgname))) {
183: fail("Error: unexpected organization name \n");
184: }
185: if (!(sb.getDescription().getValue()
186: .equals(sbDescription))) {
187: fail("Error: servicebinding description");
188: }
189: if (!(sb.getAccessURI().equals("http://newURI"))) {
190: fail("Error: unexpected accessURI name");
191: }
192: }
193: } catch (Exception e) {
194: e.printStackTrace();
195: fail("Test has failed due to an exception ");
196: } finally {
197: try {
198: if (conceptKeys != null) {
199: blm.deleteConcepts(conceptKeys);
200: }
201: if (sbKeys != null) {
202: blm.deleteServiceBindings(sbKeys);
203: }
204: if (serviceKeys != null) {
205: blm.deleteServices(serviceKeys);
206: }
207: if (orgKeys != null) {
208: blm.deleteOrganizations(orgKeys);
209: }
210:
211: } catch (JAXRException je) {
212: fail("Cleanup of JAXR objects failed");
213: }
214: }
215: } //end method
216: }
|