This project has retired. For details please refer to its Attic page.
JAXR010OrganizationTest xref
View Javadoc
1   /**
2    *
3    * Copyright 2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.ws.scout.registry.qa;
18  
19  import static org.junit.Assert.assertNull;
20  import static org.junit.Assert.assertTrue;
21  
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.Iterator;
25  
26  import javax.xml.registry.BulkResponse;
27  import javax.xml.registry.FindQualifier;
28  import javax.xml.registry.JAXRException;
29  import javax.xml.registry.JAXRResponse;
30  import static javax.xml.registry.LifeCycleManager.PERSON_NAME;
31  import javax.xml.registry.RegistryService;
32  import javax.xml.registry.infomodel.Classification;
33  import javax.xml.registry.infomodel.ClassificationScheme;
34  import javax.xml.registry.infomodel.EmailAddress;
35  import javax.xml.registry.infomodel.Key;
36  import javax.xml.registry.infomodel.Organization;
37  import javax.xml.registry.infomodel.PersonName;
38  import javax.xml.registry.infomodel.PostalAddress;
39  import javax.xml.registry.infomodel.Service;
40  import javax.xml.registry.infomodel.ServiceBinding;
41  import javax.xml.registry.infomodel.TelephoneNumber;
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.Printer;
50  import org.apache.ws.scout.Remover;
51  import static org.apache.ws.scout.registry.qa.JAXR015PrimaryContactTest.CITY;
52  import static org.apache.ws.scout.registry.qa.JAXR015PrimaryContactTest.COUNTRY;
53  import static org.apache.ws.scout.registry.qa.JAXR015PrimaryContactTest.EMAIL;
54  import static org.apache.ws.scout.registry.qa.JAXR015PrimaryContactTest.PHONE_NUMBER;
55  import static org.apache.ws.scout.registry.qa.JAXR015PrimaryContactTest.POSTAL_CODE;
56  import static org.apache.ws.scout.registry.qa.JAXR015PrimaryContactTest.STATE;
57  import static org.apache.ws.scout.registry.qa.JAXR015PrimaryContactTest.STREET;
58  import static org.apache.ws.scout.registry.qa.JAXR015PrimaryContactTest.STREET_NUMBER;
59  import org.junit.After;
60  import static org.junit.Assert.assertEquals;
61  import static org.junit.Assert.fail;
62  import org.junit.Before;
63  import org.junit.Test;
64  
65  /**
66   * Test to check Jaxr Publish
67   * Open source UDDI Browser  http://www.uddibrowser.org or using the juddi-gui project
68   * can be used to check your results
69   * @author <mailto:anil@apache.org>Anil Saldhana
70   * @since Nov 20, 2004
71   */
72  public class JAXR010OrganizationTest extends BaseTestCase
73  {
74      @Before
75      public void setUp() {
76          super.setUp();
77          login();
78          try {
79              RegistryService rs = connection.getRegistryService();
80              bqm = rs.getBusinessQueryManager();
81              blm = rs.getBusinessLifeCycleManager();
82              ClassificationScheme cScheme = blm.createClassificationScheme("org.jboss.soa.esb.:testcategory", "JBossESB Classification Scheme");
83              ArrayList<ClassificationScheme> cSchemes = new ArrayList<ClassificationScheme>();
84              cSchemes.add(cScheme);
85              BulkResponse br = blm.saveClassificationSchemes(cSchemes);
86              assertEquals(JAXRResponse.STATUS_SUCCESS, br.getStatus());
87          } catch (Exception je) {
88              je.printStackTrace();
89              fail(je.getMessage());
90          }
91      }
92  
93      @After
94      public void tearDown() {
95          super.tearDown();
96          login();
97          try {
98              RegistryService rs = connection.getRegistryService();
99              bqm = rs.getBusinessQueryManager();
100             blm = rs.getBusinessLifeCycleManager();
101             Collection<String> findQualifiers = new ArrayList<String>();
102             findQualifiers.add(FindQualifier.AND_ALL_KEYS);
103             //findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
104             ClassificationScheme cScheme = bqm.findClassificationSchemeByName(findQualifiers, "org.jboss.soa.esb.:testcategory");
105             Removerver.html#Remover">Remover remover = new Remover(blm);
106             remover.removeClassificationScheme(cScheme);
107         } catch (Exception je) {
108             je.printStackTrace();
109             fail(je.getMessage());
110         }
111     }
112     
113     @Test 
114     public void publishClassificationScheme()
115     {
116         login();
117         try
118         {
119             RegistryService rs = connection.getRegistryService();
120             blm = rs.getBusinessLifeCycleManager();
121             Creatortor.html#Creator">Creator creator = new Creator(blm);
122             
123             Collection<ClassificationScheme> schemes = new ArrayList<ClassificationScheme>();
124             ClassificationScheme classificationScheme = creator.createClassificationScheme(this.getClass().getName());
125             schemes.add(classificationScheme);
126             
127             BulkResponse bulkResponse = blm.saveClassificationSchemes(schemes);
128             assertEquals(JAXRResponse.STATUS_SUCCESS,bulkResponse.getStatus());
129             
130             
131         } catch (JAXRException e) {
132             e.printStackTrace();
133             assertTrue(false);
134         }   
135     }
136     
137     @Test
138     public void publishOrganization()
139     {
140         BulkResponse response = null;
141         login();
142         try
143         {
144             RegistryService rs = connection.getRegistryService();
145             blm = rs.getBusinessLifeCycleManager();
146             bqm = rs.getBusinessQueryManager();
147             Creatortor.html#Creator">Creator creator = new Creator(blm);
148             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
149             
150             Collection<Organization> orgs = new ArrayList<Organization>();
151             Organization organization = creator.createOrganization(this.getClass().getName());
152 //          Add a Service
153             Service service = creator.createService(this.getClass().getName());
154             ServiceBinding serviceBinding = creator.createServiceBinding();
155             service.addServiceBinding(serviceBinding);
156             organization.addService(service);
157             //Add a classification
158             ClassificationScheme cs = finder.findClassificationSchemeByName(this.getClass().getName());
159             Classification classification = creator.createClassification(cs);
160             organization.addClassification(classification);
161             
162             orgs.add(organization);
163 
164             //Now save the Organization along with a Service, ServiceBinding and Classification
165             BulkResponse br = blm.saveOrganizations(orgs);
166             if (br.getStatus() == JAXRResponse.STATUS_SUCCESS)
167             {
168                 System.out.println("Organization Saved");
169                 Collection coll = br.getCollection();
170                 Iterator iter = coll.iterator();
171                 while (iter.hasNext())
172                 {
173                     Key key = (Key) iter.next();
174                     System.out.println("Saved Key=" + key.getId());
175                 }//end while
176             } else
177             {
178                 System.err.println("JAXRExceptions " +
179                         "occurred during save:");
180                 Collection exceptions = br.getExceptions();
181                 if (exceptions!=null) {
182                     Iterator iter = exceptions.iterator();
183                     while (iter.hasNext())
184                     {
185                         Exception e = (Exception) iter.next();
186                         System.err.println(e.toString());
187                     }
188                 }
189             }
190             
191         } catch (JAXRException e) {
192             e.printStackTrace();
193 			assertTrue(false);
194         }
195         assertNull(response);
196     }
197     
198     @Test
199     public void queryOrganization()
200     {
201         login();
202         try
203         {
204             RegistryService rs = connection.getRegistryService();
205             blm = rs.getBusinessLifeCycleManager();
206             bqm = rs.getBusinessQueryManager();
207             Creatortor.html#Creator">Creator creator = new Creator(blm);
208             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
209 
210             Collection<Organization> orgs = new ArrayList<Organization>();
211             Organization organization = creator.createOrganization(this.getClass().getName());
212 //          Add a Service
213             Service service = creator.createService(this.getClass().getName());
214             ServiceBinding serviceBinding = creator.createServiceBinding();
215             service.addServiceBinding(serviceBinding);
216             organization.addService(service);
217             
218 
219             User user = blm.createUser();
220             PersonName personName = blm.createPersonName(PERSON_NAME);
221             TelephoneNumber telephoneNumber = blm.createTelephoneNumber();
222             telephoneNumber.setNumber(PHONE_NUMBER);
223             telephoneNumber.setType(null);
224             PostalAddress address = blm.createPostalAddress(STREET_NUMBER,
225                     STREET, CITY, STATE, COUNTRY, POSTAL_CODE, "");
226 
227             Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
228             postalAddresses.add(address);
229             Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
230             EmailAddress emailAddress = blm.createEmailAddress(EMAIL);
231             emailAddresses.add(emailAddress);
232 
233             Collection<TelephoneNumber> numbers = new ArrayList<TelephoneNumber>();
234             numbers.add(telephoneNumber);
235             user.setPersonName(personName);
236             user.setPostalAddresses(postalAddresses);
237             user.setEmailAddresses(emailAddresses);
238             user.setTelephoneNumbers(numbers);
239             organization.setPrimaryContact(user);
240 
241             orgs.add(organization);
242 
243             //Now save the Organization along with a Service, ServiceBinding and Classification
244             BulkResponse br = blm.saveOrganizations(orgs);
245             
246             // Get registry service and business query manager
247              rs = connection.getRegistryService();
248             bqm = rs.getBusinessQueryManager();
249             System.out.println("We have the Business Query Manager");
250             Printerter.html#Printer">Printer printer = new Printer();
251              finder = new Finder(bqm, uddiversion);
252 
253              orgs = finder.findOrganizationsByName(this.getClass().getName());
254             if (orgs == null) {
255                 fail("Only Expecting 1 Organization");
256             } else {
257                 assertTrue(orgs.size()>=1);
258                 // then step through them
259                 for (Iterator orgIter = orgs.iterator(); orgIter.hasNext();)
260                 {
261                     Organization org = (Organization) orgIter.next();
262                     System.out.println("Org name: " + printer.getName(org));
263                     System.out.println("Org description: " + printer.getDescription(org));
264                     System.out.println("Org key id: " + printer.getKey(org));
265 
266                     printer.printUser(org);
267                     printer.printServices(org);
268                     printer.printClassifications(org);
269                 }
270             }//end else
271         } catch (JAXRException e) {
272             e.printStackTrace();
273             fail(e.getMessage());
274         } 
275     }
276     
277     @Test
278     public void deleteOrganization()
279     {
280         login();
281         try
282         {
283             RegistryService rs = connection.getRegistryService();
284             blm = rs.getBusinessLifeCycleManager();
285     //      Get registry service and business query manager
286             bqm = rs.getBusinessQueryManager();
287             System.out.println("We have the Business Query Manager");
288             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
289             Removerver.html#Remover">Remover remover = new Remover(blm);
290             Collection orgs = finder.findOrganizationsByName(this.getClass().getName());
291             for (Iterator orgIter = orgs.iterator(); orgIter.hasNext();)
292             {
293                 Organization org = (Organization) orgIter.next();
294                 remover.removeOrganization(org);
295             }
296             
297         } catch (Exception e) {
298             e.printStackTrace();
299             fail(e.getMessage());
300         }
301     }
302     
303     @Test
304     public void deleteClassificationScheme()
305     {
306         login();
307         try {
308             RegistryService rs = connection.getRegistryService();
309             bqm = rs.getBusinessQueryManager();
310             blm = rs.getBusinessLifeCycleManager();
311             System.out.println("We have the Business Query Manager");
312             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
313             Removerver.html#Remover">Remover remover = new Remover(blm);
314             Collection schemes = finder.findClassificationSchemesByName(this.getClass().getName());
315             for (Iterator iter = schemes.iterator(); iter.hasNext();)
316             {
317                 ClassificationScheme scheme = (ClassificationScheme) iter.next();
318                 remover.removeClassificationScheme(scheme);
319             }
320             
321         } catch (Exception e) {
322             e.printStackTrace();
323             fail(e.getMessage());
324         }
325     }
326     
327     public static junit.framework.Test suite() {
328         return new JUnit4TestAdapter(JAXR010OrganizationTest.class);
329     }
330 }