This project has retired. For details please refer to its Attic page.
JAXR015PrimaryContactTest 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.assertEquals;
20  import static org.junit.Assert.assertNull;
21  import static org.junit.Assert.assertTrue;
22  import static org.junit.Assert.fail;
23  
24  import java.util.ArrayList;
25  import java.util.Collection;
26  import java.util.Iterator;
27  
28  import javax.xml.registry.BulkResponse;
29  import javax.xml.registry.FindQualifier;
30  import javax.xml.registry.JAXRException;
31  import javax.xml.registry.JAXRResponse;
32  import javax.xml.registry.RegistryService;
33  import javax.xml.registry.infomodel.Classification;
34  import javax.xml.registry.infomodel.ClassificationScheme;
35  import javax.xml.registry.infomodel.EmailAddress;
36  import javax.xml.registry.infomodel.Key;
37  import javax.xml.registry.infomodel.Organization;
38  import javax.xml.registry.infomodel.PersonName;
39  import javax.xml.registry.infomodel.PostalAddress;
40  import javax.xml.registry.infomodel.Service;
41  import javax.xml.registry.infomodel.ServiceBinding;
42  import javax.xml.registry.infomodel.TelephoneNumber;
43  import javax.xml.registry.infomodel.User;
44  
45  import junit.framework.JUnit4TestAdapter;
46  
47  import org.apache.ws.scout.BaseTestCase;
48  import org.apache.ws.scout.Creator;
49  import org.apache.ws.scout.Finder;
50  import org.apache.ws.scout.Printer;
51  import org.apache.ws.scout.Remover;
52  import org.junit.After;
53  import static org.junit.Assert.assertEquals;
54  import static org.junit.Assert.fail;
55  import org.junit.Before;
56  import org.junit.Test;
57  
58  /**
59   * Test to check that the primary contact is added
60   *
61   * @author <a href="mailto:tcunning@redhat.com">Tom Cunningham</a>
62   * @since Dec 6, 2007
63   */
64  public class JAXR015PrimaryContactTest extends BaseTestCase {
65  
66      public static final String PERSON_NAME = "John AXel Rose";
67      public static final String PHONE_NUMBER = "111-222-3333";
68      public static final String STREET_NUMBER = "1";
69      public static final String STREET = "Uddi Drive";
70      public static final String CITY = "Apache Town";
71      public static final String STATE = "CA";
72      public static final String COUNTRY = "USA";
73      public static final String POSTAL_CODE = "00000-1111";
74  
75      public static final String EMAIL = "jaxr@apache.org";
76  
77      @Before
78      public void setUp() {
79          super.setUp();
80          login();
81          try {
82              RegistryService rs = connection.getRegistryService();
83              bqm = rs.getBusinessQueryManager();
84              blm = rs.getBusinessLifeCycleManager();
85              ClassificationScheme cScheme = blm.createClassificationScheme("org.jboss.soa.esb.:testcategory", "JBossESB Classification Scheme");
86              ArrayList<ClassificationScheme> cSchemes = new ArrayList<ClassificationScheme>();
87              cSchemes.add(cScheme);
88              BulkResponse br = blm.saveClassificationSchemes(cSchemes);
89              assertEquals(JAXRResponse.STATUS_SUCCESS, br.getStatus());
90          } catch (Exception je) {
91              je.printStackTrace();
92              fail(je.getMessage());
93          }
94      }
95  
96      @After
97      public void tearDown() {
98          super.tearDown();
99          login();
100         try {
101             RegistryService rs = connection.getRegistryService();
102             bqm = rs.getBusinessQueryManager();
103             blm = rs.getBusinessLifeCycleManager();
104             Collection<String> findQualifiers = new ArrayList<String>();
105             findQualifiers.add(FindQualifier.AND_ALL_KEYS);
106             //findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
107             ClassificationScheme cScheme = bqm.findClassificationSchemeByName(findQualifiers, "org.jboss.soa.esb.:testcategory");
108             Removerver.html#Remover">Remover remover = new Remover(blm);
109             remover.removeClassificationScheme(cScheme);
110         } catch (Exception je) {
111             je.printStackTrace();
112             fail(je.getMessage());
113         }
114     }
115 
116     @Test
117     public void publishClassificationScheme() {
118         login();
119         try {
120             RegistryService rs = connection.getRegistryService();
121             blm = rs.getBusinessLifeCycleManager();
122             Creatortor.html#Creator">Creator creator = new Creator(blm);
123 
124             Collection<ClassificationScheme> schemes = new ArrayList<ClassificationScheme>();
125             ClassificationScheme classificationScheme = creator.createClassificationScheme(this.getClass().getName());
126             schemes.add(classificationScheme);
127 
128             BulkResponse bulkResponse = blm.saveClassificationSchemes(schemes);
129             assertEquals(JAXRResponse.STATUS_SUCCESS, bulkResponse.getStatus());
130 
131         } catch (JAXRException e) {
132             e.printStackTrace();
133             assertTrue(false);
134         }
135     }
136 
137     @Test
138     public void publishOrganization() {
139         BulkResponse response = null;
140         login();
141         try {
142             RegistryService rs = connection.getRegistryService();
143             blm = rs.getBusinessLifeCycleManager();
144             bqm = rs.getBusinessQueryManager();
145             Creatortor.html#Creator">Creator creator = new Creator(blm);
146             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
147 
148             Collection<Organization> orgs = new ArrayList<Organization>();
149             Organization organization = creator.createOrganization(this.getClass().getName());
150 //          Add a Service
151             Service service = creator.createService(this.getClass().getName());
152             ServiceBinding serviceBinding = creator.createServiceBinding();
153             service.addServiceBinding(serviceBinding);
154             organization.addService(service);
155             //Add a classification
156             ClassificationScheme cs = finder.findClassificationSchemeByName(this.getClass().getName());
157             Classification classification = creator.createClassification(cs);
158             organization.addClassification(classification);
159 
160             User user = blm.createUser();
161             PersonName personName = blm.createPersonName(PERSON_NAME);
162             TelephoneNumber telephoneNumber = blm.createTelephoneNumber();
163             telephoneNumber.setNumber(PHONE_NUMBER);
164             telephoneNumber.setType(null);
165             PostalAddress address = blm.createPostalAddress(STREET_NUMBER,
166                     STREET, CITY, STATE, COUNTRY, POSTAL_CODE, "");
167 
168             Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
169             postalAddresses.add(address);
170             Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
171             EmailAddress emailAddress = blm.createEmailAddress(EMAIL);
172             emailAddresses.add(emailAddress);
173 
174             Collection<TelephoneNumber> numbers = new ArrayList<TelephoneNumber>();
175             numbers.add(telephoneNumber);
176             user.setPersonName(personName);
177             user.setPostalAddresses(postalAddresses);
178             user.setEmailAddresses(emailAddresses);
179             user.setTelephoneNumbers(numbers);
180             organization.setPrimaryContact(user);
181 
182             orgs.add(organization);
183 
184             //Now save the Organization along with a Service, ServiceBinding and Classification
185             BulkResponse br = blm.saveOrganizations(orgs);
186             if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
187                 System.out.println("Organization Saved");
188                 Collection coll = br.getCollection();
189                 Iterator iter = coll.iterator();
190                 while (iter.hasNext()) {
191                     Key key = (Key) iter.next();
192                     System.out.println("Saved Key=" + key.getId());
193                 }//end while
194             } else {
195                 System.err.println("JAXRExceptions "
196                         + "occurred during save:");
197                 Collection exceptions = br.getExceptions();
198                 if (exceptions != null) {
199                     Iterator iter = exceptions.iterator();
200                     while (iter.hasNext()) {
201                         Exception e = (Exception) iter.next();
202                         System.err.println(e.toString());
203                     }
204                 }
205             }
206 
207         } catch (JAXRException e) {
208             e.printStackTrace();
209             fail(e.getMessage());
210         }
211         assertNull(response);
212     }
213 
214     @SuppressWarnings("unchecked")
215     @Test
216     public void queryOrganization() {
217         login();
218         try {
219             
220             RegistryService rs = connection.getRegistryService();
221             blm = rs.getBusinessLifeCycleManager();
222             bqm = rs.getBusinessQueryManager();
223             Creatortor.html#Creator">Creator creator = new Creator(blm);
224             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
225 
226             Collection<Organization> orgs = new ArrayList<Organization>();
227             Organization organization = creator.createOrganization(this.getClass().getName());
228 //          Add a Service
229             Service service = creator.createService(this.getClass().getName());
230             ServiceBinding serviceBinding = creator.createServiceBinding();
231             service.addServiceBinding(serviceBinding);
232             organization.addService(service);
233             
234 
235             User user = blm.createUser();
236             PersonName personName = blm.createPersonName(PERSON_NAME);
237             TelephoneNumber telephoneNumber = blm.createTelephoneNumber();
238             telephoneNumber.setNumber(PHONE_NUMBER);
239             telephoneNumber.setType(null);
240             PostalAddress address = blm.createPostalAddress(STREET_NUMBER,
241                     STREET, CITY, STATE, COUNTRY, POSTAL_CODE, "");
242 
243             Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
244             postalAddresses.add(address);
245             Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
246             EmailAddress emailAddress = blm.createEmailAddress(EMAIL);
247             emailAddresses.add(emailAddress);
248 
249             Collection<TelephoneNumber> numbers = new ArrayList<TelephoneNumber>();
250             numbers.add(telephoneNumber);
251             user.setPersonName(personName);
252             user.setPostalAddresses(postalAddresses);
253             user.setEmailAddresses(emailAddresses);
254             user.setTelephoneNumbers(numbers);
255             organization.setPrimaryContact(user);
256 
257             orgs.add(organization);
258 
259             //Now save the Organization along with a Service, ServiceBinding and Classification
260             BulkResponse br = blm.saveOrganizations(orgs);
261             
262             
263             bqm = rs.getBusinessQueryManager();
264             System.out.println("We have the Business Query Manager");
265             Printerter.html#Printer">Printer printer = new Printer();
266             finder = new Finder(bqm, uddiversion);
267 
268             orgs = finder.findOrganizationsByName(this.getClass().getName());
269             if (orgs == null) {
270                 fail("Only Expecting 1 Organization");
271             } else {
272                 assertTrue(orgs.size() >= 1);
273                 // then step through them
274                 for (Iterator orgIter = orgs.iterator(); orgIter.hasNext();) {
275                     Organization org = (Organization) orgIter.next();
276                     System.out.println("Org name: " + printer.getName(org));
277                     System.out.println("Org description: " + printer.getDescription(org));
278                     System.out.println("Org key id: " + printer.getKey(org));
279 
280                     user = org.getPrimaryContact();
281                     System.out.println("Primary Contact Full Name : " + user.getPersonName().getFullName());
282                     assertEquals("User name does not match", user.getPersonName().getFullName(), PERSON_NAME);
283 
284                     emailAddresses = user.getEmailAddresses();
285                     System.out.println("Found " + emailAddresses.size() + " email addresses.");
286                     assertEquals("Should have found 1 email address, found " + emailAddresses.size(), 1, emailAddresses.size());
287                     for (EmailAddress email : emailAddresses) {
288                         System.out.println("Primary Contact email : " + email.getAddress());
289                         assertEquals("Email should be " + EMAIL, EMAIL, email.getAddress());
290                     }
291 
292                     postalAddresses = user.getPostalAddresses();
293                     System.out.println("Found " + postalAddresses.size() + " postal addresses.");
294                     assertEquals("Should have found 1 postal address, found " + postalAddresses.size(), 1, postalAddresses.size());
295                     for (PostalAddress postalAddress : postalAddresses) {
296                         System.out.println("Postal Address is " + postalAddress);
297                         assertEquals("Street number should be " + STREET_NUMBER, STREET_NUMBER, postalAddress.getStreetNumber());
298                         assertEquals("Street should be " + STREET, STREET, postalAddress.getStreet());
299                         assertEquals("City should be " + CITY, CITY, postalAddress.getCity());
300                         assertEquals("State should be " + STATE, STATE, postalAddress.getStateOrProvince());
301                         assertEquals("Country should be " + COUNTRY, COUNTRY, postalAddress.getCountry());
302                         assertEquals("Postal code should be " + POSTAL_CODE, POSTAL_CODE, postalAddress.getPostalCode());
303                     }
304 
305                     numbers = user.getTelephoneNumbers(null);
306                     System.out.println("Found " + numbers.size() + " telephone numbers.");
307                     assertEquals("Should have found 1 phone number, found " + numbers.size(), 1, numbers.size());
308                     for (TelephoneNumber tele : numbers) {
309                         System.out.println("Phone number is " + tele.getNumber());
310                         assertEquals("Telephone number should be " + PHONE_NUMBER, PHONE_NUMBER, tele.getNumber());
311                     }
312                     printer.printServices(org);
313                     printer.printClassifications(org);
314                 }
315             }//end else
316         } catch (JAXRException e) {
317             e.printStackTrace();
318             fail(e.getMessage());
319         }
320     }
321 
322     @Test
323     public void deleteOrganization() {
324         login();
325         try {
326             RegistryService rs = connection.getRegistryService();
327             blm = rs.getBusinessLifeCycleManager();
328             //      Get registry service and business query manager
329             bqm = rs.getBusinessQueryManager();
330             System.out.println("We have the Business Query Manager");
331             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
332             Removerver.html#Remover">Remover remover = new Remover(blm);
333             Collection orgs = finder.findOrganizationsByName(this.getClass().getName());
334             for (Iterator orgIter = orgs.iterator(); orgIter.hasNext();) {
335                 Organization org = (Organization) orgIter.next();
336                 remover.removeOrganization(org);
337             }
338 
339         } catch (Exception e) {
340             e.printStackTrace();
341             fail(e.getMessage());
342         }
343     }
344 
345     @Test
346     public void deleteClassificationScheme() {
347         login();
348         try {
349             RegistryService rs = connection.getRegistryService();
350             bqm = rs.getBusinessQueryManager();
351             blm = rs.getBusinessLifeCycleManager();
352             System.out.println("We have the Business Query Manager");
353             Findernder.html#Finder">Finder finder = new Finder(bqm, uddiversion);
354             Removerver.html#Remover">Remover remover = new Remover(blm);
355             Collection schemes = finder.findClassificationSchemesByName(this.getClass().getName());
356             for (Iterator iter = schemes.iterator(); iter.hasNext();) {
357                 ClassificationScheme scheme = (ClassificationScheme) iter.next();
358                 remover.removeClassificationScheme(scheme);
359             }
360 
361         } catch (Exception e) {
362             e.printStackTrace();
363             fail(e.getMessage());
364         }
365     }
366 
367     public static junit.framework.Test suite() {
368         return new JUnit4TestAdapter(JAXR015PrimaryContactTest.class);
369     }
370 }