KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jaxr > scout > publish > JaxrSaveServiceBindingTestCase


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.jaxr.scout.publish;
23
24 import org.jboss.test.jaxr.scout.JaxrBaseTestCase;
25
26 import javax.xml.registry.BulkResponse JavaDoc;
27 import javax.xml.registry.JAXRException JavaDoc;
28 import javax.xml.registry.LifeCycleManager JavaDoc;
29 import javax.xml.registry.infomodel.Concept JavaDoc;
30 import javax.xml.registry.infomodel.Key JavaDoc;
31 import javax.xml.registry.infomodel.Organization JavaDoc;
32 import javax.xml.registry.infomodel.Service JavaDoc;
33 import javax.xml.registry.infomodel.ServiceBinding JavaDoc;
34 import javax.xml.registry.infomodel.SpecificationLink JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.Collection JavaDoc;
37 import java.util.Iterator JavaDoc;
38
39
40 /**
41  * Tests Saving ServiceBindings
42  *
43  * @author <mailto:Anil.Saldhana@jboss.org>Anil Saldhana
44  * @since Mar 8, 2005
45  */

46 public class JaxrSaveServiceBindingTestCase extends JaxrBaseTestCase
47 {
48     /**
49      * @throws JAXRException
50      */

51     public void testSaveServiceBinding() throws JAXRException JavaDoc
52     {
53         String JavaDoc serviceName = "jbosstestService";
54         String JavaDoc sbDescription = "jbosstest sb description";
55
56         String JavaDoc conceptName = "jbosstest concept";
57         Collection JavaDoc sbKeys = null;
58         Collection JavaDoc serviceKeys = null;
59         Collection JavaDoc orgKeys = null;
60         Collection JavaDoc conceptKeys = null;
61         Key JavaDoc conceptKey = null;
62         Key JavaDoc serviceKey = null;
63         Key JavaDoc orgKey = null;
64
65         String JavaDoc accessURI = "http://myhost/jaxrTest.jsp";
66         login();
67
68
69         try
70         {
71             getJAXREssentials();
72             String JavaDoc orgname = "Jaxr Org";
73             Organization JavaDoc org = blm.createOrganization(getIString(orgname));
74             Collection JavaDoc orgs = new ArrayList JavaDoc();
75             orgs.add(org);
76             BulkResponse JavaDoc br = blm.saveOrganizations(orgs);
77             if (br.getExceptions() != null)
78             {
79                 fail("Save Organizations failed ");
80             }
81             orgKeys = br.getCollection();
82             Iterator JavaDoc iter = orgKeys.iterator();
83             while (iter.hasNext())
84             {
85                 orgKey = (Key JavaDoc) iter.next();
86             }
87
88
89             org = (Organization JavaDoc) bqm.getRegistryObject(orgKey.getId(), LifeCycleManager.ORGANIZATION);
90
91             Service JavaDoc service = blm.createService(serviceName);
92             org.addService(service);
93             Collection JavaDoc services = new ArrayList JavaDoc();
94             services.add(service);
95             br = blm.saveServices(services);
96             if (br.getExceptions() != null)
97             {
98                 fail("Save Services failed ");
99             }
100             serviceKeys = br.getCollection();
101             iter = serviceKeys.iterator();
102             while (iter.hasNext())
103             {
104                 serviceKey = (Key JavaDoc) iter.next();
105             }
106
107             service = (Service JavaDoc) bqm.getRegistryObject(serviceKey.getId(), LifeCycleManager.SERVICE);
108
109             //Save some concepts
110
Concept JavaDoc testConcept = (Concept JavaDoc) blm.createObject(LifeCycleManager.CONCEPT);
111             testConcept.setName(blm.createInternationalString(conceptName));
112             Collection JavaDoc concepts = new ArrayList JavaDoc();
113             concepts.add(testConcept);
114             br = blm.saveConcepts(concepts);
115             if (br.getExceptions() != null)
116             {
117                 fail("Save Concepts failed ");
118             }
119             conceptKeys = br.getCollection();
120             iter = conceptKeys.iterator();
121             while (iter.hasNext())
122             {
123                 conceptKey = (Key JavaDoc) iter.next();
124             }
125
126             testConcept = (Concept JavaDoc) bqm.getRegistryObject(conceptKey.getId(), LifeCycleManager.CONCEPT);
127             SpecificationLink JavaDoc sl = blm.createSpecificationLink();
128             sl.setSpecificationObject(testConcept);
129             ServiceBinding JavaDoc sb = blm.createServiceBinding();
130             sb.setDescription(blm.createInternationalString(sbDescription));
131             sb.setAccessURI(accessURI);
132             sb.addSpecificationLink(sl);
133             service.addServiceBinding(sb);
134             Collection JavaDoc sbs = new ArrayList JavaDoc();
135             sbs.add(sb);
136             br = blm.saveServiceBindings(sbs);
137             if (br.getExceptions() != null)
138             {
139                 fail("Save ServiceBindings failed ");
140             }
141
142
143             Collection JavaDoc specifications = new ArrayList JavaDoc();
144             specifications.add(testConcept);
145
146             br = bqm.findServiceBindings(serviceKey, null, null, specifications);
147             sbs = br.getCollection();
148             iter = sbs.iterator();
149             while (iter.hasNext())
150             {
151                 sb = (ServiceBinding JavaDoc) iter.next();
152                 Service JavaDoc storedService = sb.getService();
153                 if (!(storedService.getName().getValue().equals(serviceName)))
154                 {
155                     fail("Error: service name");
156                 }
157                 Organization JavaDoc storedOrg = storedService.getProvidingOrganization();
158                 if (!(storedOrg.getName().getValue().equals(orgname)))
159                 {
160                     fail("Error: unexpected organization name \n");
161                 }
162                 if (!(sb.getDescription().getValue().equals(sbDescription)))
163                 {
164                     fail("Error: servicebinding description");
165                 }
166                 if (!(sb.getAccessURI().equals(accessURI)))
167                 {
168                     fail("Error: unexpected accessURI name");
169                 }
170             }
171
172             //Lets update the ServiceBinding
173
sbs = new ArrayList JavaDoc();
174             sb.setAccessURI("http://newURI");
175             sbs.add(sb);
176             br = blm.saveServiceBindings(sbs);
177             br = bqm.findServiceBindings(serviceKey, null, null, specifications);
178             sbs = br.getCollection();
179             iter = sbs.iterator();
180             while (iter.hasNext())
181             {
182                 sb = (ServiceBinding JavaDoc) iter.next();
183                 Service JavaDoc storedService = sb.getService();
184                 if (!(storedService.getName().getValue().equals(serviceName)))
185                 {
186                     fail("Error: service name");
187                 }
188                 Organization JavaDoc storedOrg = storedService.getProvidingOrganization();
189                 if (!(storedOrg.getName().getValue().equals(orgname)))
190                 {
191                     fail("Error: unexpected organization name \n");
192                 }
193                 if (!(sb.getDescription().getValue().equals(sbDescription)))
194                 {
195                     fail("Error: servicebinding description");
196                 }
197                 if (!(sb.getAccessURI().equals("http://newURI")))
198                 {
199                     fail("Error: unexpected accessURI name");
200                 }
201             }
202         } catch (Exception JavaDoc e)
203         {
204             e.printStackTrace();
205             fail("Test has failed due to an exception ");
206         } finally
207         {
208             try
209             {
210                 if (conceptKeys != null)
211                 {
212                     blm.deleteConcepts(conceptKeys);
213                 }
214                 if (sbKeys != null)
215                 {
216                     blm.deleteServiceBindings(sbKeys);
217                 }
218                 if (serviceKeys != null)
219                 {
220                     blm.deleteServices(serviceKeys);
221                 }
222                 if (orgKeys != null)
223                 {
224                     blm.deleteOrganizations(orgKeys);
225                 }
226
227             } catch (JAXRException JavaDoc je)
228             {
229                 fail("Cleanup of JAXR objects failed");
230             }
231         }
232     } //end method
233
}
234
Popular Tags