This project has retired. For details please refer to its Attic page.
JAXR060RegistryTest xref
View Javadoc
1   /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2006, 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.apache.ws.scout.registry.qa;
23  
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.assertTrue;
26  import static org.junit.Assert.fail;
27  
28  import java.util.ArrayList;
29  import java.util.Collection;
30  import java.util.Iterator;
31  
32  import javax.xml.registry.BulkResponse;
33  import javax.xml.registry.FindQualifier;
34  import javax.xml.registry.JAXRException;
35  import javax.xml.registry.JAXRResponse;
36  import javax.xml.registry.RegistryService;
37  import javax.xml.registry.infomodel.Classification;
38  import javax.xml.registry.infomodel.ClassificationScheme;
39  import javax.xml.registry.infomodel.Organization;
40  import javax.xml.registry.infomodel.Service;
41  import javax.xml.registry.infomodel.ServiceBinding;
42  import javax.xml.registry.infomodel.User;
43  
44  import junit.framework.JUnit4TestAdapter;
45  
46  import org.apache.ws.scout.BaseTestCase;
47  import org.apache.ws.scout.Creator;
48  import org.apache.ws.scout.Finder;
49  import org.apache.ws.scout.Remover;
50  import org.junit.After;
51  import org.junit.Before;
52  import org.junit.Test;
53  
54  /**
55   * Testing the registry.
56   *
57   * @author kstam
58   *
59   */
60  public class JAXR060RegistryTest extends BaseTestCase {
61  
62      @Before
63      public void setUp() {
64          super.setUp();
65          login();
66          try {
67              RegistryService rs = connection.getRegistryService();
68              bqm = rs.getBusinessQueryManager();
69              blm = rs.getBusinessLifeCycleManager();
70              ClassificationScheme cScheme = blm.createClassificationScheme("org.jboss.soa.esb.:testcategory", "JBossESB Classification Scheme");
71              ArrayList<ClassificationScheme> cSchemes = new ArrayList<ClassificationScheme>();
72              cSchemes.add(cScheme);
73              BulkResponse br = blm.saveClassificationSchemes(cSchemes);
74              assertEquals(JAXRResponse.STATUS_SUCCESS, br.getStatus());
75          } catch (Exception je) {
76              je.printStackTrace();
77              fail(je.getMessage());
78          }
79      }
80  
81      @After
82      public void tearDown() {
83          super.tearDown();
84          login();
85          try {
86              RegistryService rs = connection.getRegistryService();
87              bqm = rs.getBusinessQueryManager();
88              blm = rs.getBusinessLifeCycleManager();
89              Collection<String> findQualifiers = new ArrayList<String>();
90              findQualifiers.add(FindQualifier.AND_ALL_KEYS);
91              //findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
92              ClassificationScheme cScheme = bqm.findClassificationSchemeByName(findQualifiers, "org.jboss.soa.esb.:testcategory");
93              Removerver.html#Remover">Remover remover = new Remover(blm);
94              remover.removeClassificationScheme(cScheme);
95          } catch (Exception je) {
96              je.printStackTrace();
97              fail(je.getMessage());
98          }
99      }
100 
101     /**
102      * Tests the successful creation of the RED HAT/JBossESB Organization.
103      */
104     @SuppressWarnings("unchecked")
105     @Test
106     public void publishCheckAndDelete() {
107         login();
108         try {
109             RegistryService rs = connection.getRegistryService();
110             blm = rs.getBusinessLifeCycleManager();
111             Creatortor.html#Creator">Creator creator = new Creator(blm);
112 
113             Collection<Organization> organizations = new ArrayList<Organization>();
114             Organization organization = creator.createOrganization("Red Hat/JBossESB");
115             organizations.add(organization);
116             BulkResponse br = blm.saveOrganizations(organizations);
117             assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus());
118         } catch (JAXRException je) {
119             je.printStackTrace();
120             fail(je.getMessage());
121         }
122         //find organization
123         try {
124             RegistryService rs = connection.getRegistryService();
125             bqm = rs.getBusinessQueryManager();
126             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
127             Collection<Organization> orgs = finder.findOrganizationsByName("Red Hat/JBossESB");
128             Organization org = orgs.iterator().next();
129             assertEquals("Red Hat/JBossESB", org.getName().getValue());
130         } catch (JAXRException je) {
131             fail(je.getMessage());
132         }
133         try {
134             RegistryService rs = connection.getRegistryService();
135             bqm = rs.getBusinessQueryManager();
136             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
137             Collection<Organization> orgs = finder.findOrganizationsByName("Not Existing Org");
138             assertEquals(0, orgs.size());
139         } catch (JAXRException je) {
140             fail(je.getMessage());
141         }
142         //Publish a service
143         try {
144             RegistryService rs = connection.getRegistryService();
145             bqm = rs.getBusinessQueryManager();
146             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
147             Collection<Organization> orgs = finder.findOrganizationsByName("Red Hat/JBossESB");
148             Organization organization = orgs.iterator().next();
149 
150             blm = rs.getBusinessLifeCycleManager();
151             //Adding the category as prefix for the name
152             Service service = blm.createService(blm.createInternationalString("Registry Test ServiceName"));
153             service.setDescription(blm.createInternationalString("Registry Test Service Description"));
154             Collection<String> findQualifiers = new ArrayList<String>();
155             findQualifiers.add(FindQualifier.AND_ALL_KEYS);
156             //findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
157             ClassificationScheme cScheme = bqm.findClassificationSchemeByName(findQualifiers, "org.jboss.soa.esb.:testcategory");
158             Classification classification = blm.createClassification(cScheme, "category", "registry");
159             service.addClassification(classification);
160             organization.addService(service);
161             Collection<Service> services = new ArrayList<Service>();
162             services.add(service);
163             BulkResponse br = blm.saveServices(services);
164             assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus());
165         } catch (JAXRException je) {
166             je.printStackTrace();
167             fail(je.getMessage());
168         }
169         //find Service
170         try {
171             RegistryService rs = connection.getRegistryService();
172             bqm = rs.getBusinessQueryManager();
173             blm = rs.getBusinessLifeCycleManager();
174             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
175             //Find the service
176             Service service = finder.findService("registry", "Registry Test ServiceName", blm);
177             assertEquals("Registry Test ServiceName", service.getName().getValue());
178         } catch (JAXRException je) {
179             fail(je.getMessage());
180         }
181         //publish serviceBinding
182         try {
183             RegistryService rs = connection.getRegistryService();
184             bqm = rs.getBusinessQueryManager();
185             blm = rs.getBusinessLifeCycleManager();
186             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
187             //Find the service
188             Service service = finder.findService("registry", "Registry Test ServiceName", blm);
189 
190             ServiceBinding serviceBinding = blm.createServiceBinding();
191             serviceBinding.setDescription(blm.createInternationalString("eprDescription"));
192             String xml = "<epr>epr uri</epr>";
193             serviceBinding.setAccessURI(xml);
194 
195             ArrayList<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
196             serviceBindings.add(serviceBinding);
197             service.addServiceBindings(serviceBindings);
198             Collection<String> findQualifiers = new ArrayList<String>();
199             findQualifiers.add(FindQualifier.AND_ALL_KEYS);
200             //findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
201             ClassificationScheme cScheme = bqm.findClassificationSchemeByName(findQualifiers, "org.jboss.soa.esb.:testcategory");
202             Classification classification = blm.createClassification(cScheme, "category", "registry");
203             service.addClassification(classification);
204 
205             BulkResponse br = blm.saveServiceBindings(serviceBindings);
206             assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus());
207             BulkResponse br2 = blm.saveServiceBindings(serviceBindings); //Save one more
208             assertEquals(BulkResponse.STATUS_SUCCESS, br2.getStatus());
209 
210             findQualifiers = new ArrayList<String>();
211             findQualifiers.add(FindQualifier.AND_ALL_KEYS);
212             
213             cScheme = bqm.findClassificationSchemeByName(findQualifiers, "org.jboss.soa.esb.:testcategory");
214             //Delete one binding            
215             Collection<ServiceBinding> serviceBindings2 = finder.findServiceBindings(service.getKey(), classification);
216             if ((serviceBindings2 != null) && (serviceBindings2.iterator() != null)
217                     && (serviceBindings2.iterator().hasNext())) {
218                 ServiceBinding serviceBinding2 = serviceBindings2.iterator().next();
219                 Removerver.html#Remover">Remover remover = new Remover(blm);
220                 remover.removeServiceBinding(serviceBinding2);
221             }
222         } catch (JAXRException re) {
223             re.printStackTrace();
224             fail(re.getMessage());
225         }
226         //find all services for this organization
227         try {
228             RegistryService rs = connection.getRegistryService();
229             bqm = rs.getBusinessQueryManager();
230             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
231             Collection<Organization> orgs = finder.findOrganizationsByName("Red Hat/JBossESB");
232             Organization org = orgs.iterator().next();
233             //Listing out the services and their Bindings
234             System.out.println("-------------------------------------------------");
235             System.out.println("Organization name: " + org.getName().getValue());
236             System.out.println("Description: " + org.getDescription().getValue());
237             System.out.println("Key id: " + org.getKey().getId());
238             User primaryContact = org.getPrimaryContact();
239             System.out.println("Primary Contact: " + primaryContact.getPersonName().getFullName());
240             Collection services = org.getServices();
241             for (Iterator serviceIter = services.iterator(); serviceIter.hasNext();) {
242                 Service service = (Service) serviceIter.next();
243                 System.out.println("- Service Name: " + service.getName().getValue());
244                 System.out.println("  Service Key : " + service.getKey().getId());
245                 Collection serviceBindings = service.getServiceBindings();
246                 for (Iterator serviceBindingIter = serviceBindings.iterator(); serviceBindingIter.hasNext();) {
247                     ServiceBinding serviceBinding = (ServiceBinding) serviceBindingIter.next();
248                     System.out.println("  ServiceBinding Description: " + serviceBinding.getDescription().getValue());
249                     String xml = serviceBinding.getAccessURI();
250                     System.out.println("  ServiceBinding URI: " + xml);
251                     assertEquals("<epr>epr uri</epr>", xml);
252                 }
253             }
254             System.out.println("-------------------------------------------------");
255         } catch (Exception je) {
256             je.printStackTrace();
257             fail(je.getMessage());
258         }
259         //delete the service
260         try {
261             RegistryService rs = connection.getRegistryService();
262             bqm = rs.getBusinessQueryManager();
263             blm = rs.getBusinessLifeCycleManager();
264             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
265             //Find the service
266             Service service = finder.findService("registry", "Registry Test ServiceName", blm);
267             Removerver.html#Remover">Remover remover = new Remover(blm);
268             remover.removeService(service);
269         } catch (JAXRException je) {
270             je.printStackTrace();
271             fail(je.getMessage());
272         }
273         //delete the organization
274         try {
275             RegistryService rs = connection.getRegistryService();
276             bqm = rs.getBusinessQueryManager();
277             blm = rs.getBusinessLifeCycleManager();
278             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
279             Collection<Organization> orgs = finder.findOrganizationsByName("Red Hat/JBossESB");
280             Organization org = orgs.iterator().next();
281             Removerver.html#Remover">Remover remover = new Remover(blm);
282             remover.removeOrganization(org);
283         } catch (JAXRException je) {
284             je.printStackTrace();
285             fail(je.getMessage());
286         }
287     }
288 
289     public static junit.framework.Test suite() {
290         return new JUnit4TestAdapter(JAXR060RegistryTest.class);
291     }
292 
293 }