001: /**
002: *
003: * Copyright 2004 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.ws.scout.registry.qa;
017:
018: import static org.junit.Assert.assertEquals;
019: import static org.junit.Assert.assertNull;
020: import static org.junit.Assert.assertTrue;
021: import static org.junit.Assert.fail;
022:
023: import java.util.ArrayList;
024: import java.util.Collection;
025: import java.util.Iterator;
026:
027: import javax.xml.registry.BulkResponse;
028: import javax.xml.registry.JAXRException;
029: import javax.xml.registry.JAXRResponse;
030: import javax.xml.registry.RegistryService;
031: import javax.xml.registry.infomodel.Classification;
032: import javax.xml.registry.infomodel.ClassificationScheme;
033: import javax.xml.registry.infomodel.EmailAddress;
034: import javax.xml.registry.infomodel.Key;
035: import javax.xml.registry.infomodel.Organization;
036: import javax.xml.registry.infomodel.PersonName;
037: import javax.xml.registry.infomodel.PostalAddress;
038: import javax.xml.registry.infomodel.Service;
039: import javax.xml.registry.infomodel.ServiceBinding;
040: import javax.xml.registry.infomodel.TelephoneNumber;
041: import javax.xml.registry.infomodel.User;
042:
043: import junit.framework.JUnit4TestAdapter;
044:
045: import org.apache.ws.scout.BaseTestCase;
046: import org.apache.ws.scout.Creator;
047: import org.apache.ws.scout.Finder;
048: import org.apache.ws.scout.Printer;
049: import org.apache.ws.scout.Remover;
050: import org.junit.After;
051: import org.junit.Before;
052: import org.junit.Test;
053:
054: /**
055: * Test to check that the primary contact is added
056: * @author <a href="mailto:tcunning@redhat.com">Tom Cunningham</a>
057: * @since Dec 6, 2007
058: */
059: public class JAXR015PrimaryContactTest extends BaseTestCase {
060: private static final String PERSON_NAME = "John AXel Rose";
061: private static final String PHONE_NUMBER = "111-222-3333";
062: private static final String STREET_NUMBER = "1";
063: private static final String STREET = "Uddi Drive";
064: private static final String CITY = "Apache Town";
065: private static final String STATE = "CA";
066: private static final String COUNTRY = "USA";
067: private static final String POSTAL_CODE = "00000-1111";
068:
069: private static final String EMAIL = "jaxr@apache.org";
070:
071: @Before
072: public void setUp() {
073: super .setUp();
074: }
075:
076: @After
077: public void tearDown() {
078: super .tearDown();
079: }
080:
081: @Test
082: public void publishClassificationScheme() {
083: login();
084: try {
085: RegistryService rs = connection.getRegistryService();
086: blm = rs.getBusinessLifeCycleManager();
087: Creator creator = new Creator(blm);
088:
089: Collection<ClassificationScheme> schemes = new ArrayList<ClassificationScheme>();
090: ClassificationScheme classificationScheme = creator
091: .createClassificationScheme(this .getClass()
092: .getName());
093: schemes.add(classificationScheme);
094:
095: BulkResponse bulkResponse = blm
096: .saveClassificationSchemes(schemes);
097: assertEquals(JAXRResponse.STATUS_SUCCESS, bulkResponse
098: .getStatus());
099:
100: } catch (JAXRException e) {
101: e.printStackTrace();
102: assertTrue(false);
103: }
104: }
105:
106: @Test
107: public void publishOrganization() {
108: BulkResponse response = null;
109: login();
110: try {
111: RegistryService rs = connection.getRegistryService();
112: blm = rs.getBusinessLifeCycleManager();
113: bqm = rs.getBusinessQueryManager();
114: Creator creator = new Creator(blm);
115: Finder finder = new Finder(bqm);
116:
117: Collection<Organization> orgs = new ArrayList<Organization>();
118: Organization organization = creator.createOrganization(this
119: .getClass().getName());
120: // Add a Service
121: Service service = creator.createService(this .getClass()
122: .getName());
123: ServiceBinding serviceBinding = creator
124: .createServiceBinding();
125: service.addServiceBinding(serviceBinding);
126: organization.addService(service);
127: //Add a classification
128: ClassificationScheme cs = finder
129: .findClassificationSchemeByName(this .getClass()
130: .getName());
131: Classification classification = creator
132: .createClassification(cs);
133: organization.addClassification(classification);
134:
135: User user = blm.createUser();
136: PersonName personName = blm.createPersonName(PERSON_NAME);
137: TelephoneNumber telephoneNumber = blm
138: .createTelephoneNumber();
139: telephoneNumber.setNumber(PHONE_NUMBER);
140: telephoneNumber.setType(null);
141: PostalAddress address = blm.createPostalAddress(
142: STREET_NUMBER, STREET, CITY, STATE, COUNTRY,
143: POSTAL_CODE, "");
144:
145: Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
146: postalAddresses.add(address);
147: Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
148: EmailAddress emailAddress = blm.createEmailAddress(EMAIL);
149: emailAddresses.add(emailAddress);
150:
151: Collection<TelephoneNumber> numbers = new ArrayList<TelephoneNumber>();
152: numbers.add(telephoneNumber);
153: user.setPersonName(personName);
154: user.setPostalAddresses(postalAddresses);
155: user.setEmailAddresses(emailAddresses);
156: user.setTelephoneNumbers(numbers);
157: organization.setPrimaryContact(user);
158:
159: orgs.add(organization);
160:
161: //Now save the Organization along with a Service, ServiceBinding and Classification
162: BulkResponse br = blm.saveOrganizations(orgs);
163: if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
164: System.out.println("Organization Saved");
165: Collection coll = br.getCollection();
166: Iterator iter = coll.iterator();
167: while (iter.hasNext()) {
168: Key key = (Key) iter.next();
169: System.out.println("Saved Key=" + key.getId());
170: }//end while
171: } else {
172: System.err.println("JAXRExceptions "
173: + "occurred during save:");
174: Collection exceptions = br.getExceptions();
175: Iterator iter = exceptions.iterator();
176: while (iter.hasNext()) {
177: Exception e = (Exception) iter.next();
178: System.err.println(e.toString());
179: }
180: }
181:
182: } catch (JAXRException e) {
183: e.printStackTrace();
184: assertTrue(false);
185: }
186: assertNull(response);
187: }
188:
189: @SuppressWarnings("unchecked")
190: @Test
191: public void queryOrganization() {
192: login();
193: try {
194: // Get registry service and business query manager
195: RegistryService rs = connection.getRegistryService();
196: bqm = rs.getBusinessQueryManager();
197: System.out.println("We have the Business Query Manager");
198: Printer printer = new Printer();
199: Finder finder = new Finder(bqm);
200:
201: Collection orgs = finder.findOrganizationsByName(this
202: .getClass().getName());
203: if (orgs == null) {
204: fail("Only Expecting 1 Organization");
205: } else {
206: assertEquals(1, orgs.size());
207: // then step through them
208: for (Iterator orgIter = orgs.iterator(); orgIter
209: .hasNext();) {
210: Organization org = (Organization) orgIter.next();
211: System.out.println("Org name: "
212: + printer.getName(org));
213: System.out.println("Org description: "
214: + printer.getDescription(org));
215: System.out.println("Org key id: "
216: + printer.getKey(org));
217:
218: User user = org.getPrimaryContact();
219: System.out.println("Primary Contact Full Name : "
220: + user.getPersonName().getFullName());
221: assertEquals("User name does not match", user
222: .getPersonName().getFullName(), PERSON_NAME);
223:
224: Collection<EmailAddress> emailAddresses = user
225: .getEmailAddresses();
226: System.out.println("Found " + emailAddresses.size()
227: + " email addresses.");
228: assertEquals(
229: "Should have found 1 email address, found "
230: + emailAddresses.size(), 1,
231: emailAddresses.size());
232: for (EmailAddress email : emailAddresses) {
233: System.out.println("Primary Contact email : "
234: + email.getAddress());
235: assertEquals("Email should be " + EMAIL, EMAIL,
236: email.getAddress());
237: }
238:
239: Collection<PostalAddress> postalAddresses = user
240: .getPostalAddresses();
241: System.out.println("Found "
242: + postalAddresses.size()
243: + " postal addresses.");
244: assertEquals(
245: "Should have found 1 postal address, found "
246: + postalAddresses.size(), 1,
247: postalAddresses.size());
248: for (PostalAddress postalAddress : postalAddresses) {
249: System.out.println("Postal Address is "
250: + postalAddress);
251: assertEquals("Street number should be "
252: + STREET_NUMBER, STREET_NUMBER,
253: postalAddress.getStreetNumber());
254: assertEquals("Street should be " + STREET,
255: STREET, postalAddress.getStreet());
256: assertEquals("City should be " + CITY, CITY,
257: postalAddress.getCity());
258: assertEquals("State should be " + STATE, STATE,
259: postalAddress.getStateOrProvince());
260: assertEquals("Country should be " + COUNTRY,
261: COUNTRY, postalAddress.getCountry());
262: assertEquals("Postal code should be "
263: + POSTAL_CODE, POSTAL_CODE,
264: postalAddress.getPostalCode());
265: }
266:
267: Collection<TelephoneNumber> numbers = user
268: .getTelephoneNumbers(null);
269: System.out.println("Found " + numbers.size()
270: + " telephone numbers.");
271: assertEquals(
272: "Should have found 1 phone number, found "
273: + numbers.size(), 1, numbers.size());
274: for (TelephoneNumber tele : numbers) {
275: System.out.println("Phone number is "
276: + tele.getNumber());
277: assertEquals("Telephone number should be "
278: + PHONE_NUMBER, PHONE_NUMBER, tele
279: .getNumber());
280: }
281: printer.printServices(org);
282: printer.printClassifications(org);
283: }
284: }//end else
285: } catch (JAXRException e) {
286: e.printStackTrace();
287: fail(e.getMessage());
288: }
289: }
290:
291: @Test
292: public void deleteOrganization() {
293: login();
294: try {
295: RegistryService rs = connection.getRegistryService();
296: blm = rs.getBusinessLifeCycleManager();
297: // Get registry service and business query manager
298: bqm = rs.getBusinessQueryManager();
299: System.out.println("We have the Business Query Manager");
300: Finder finder = new Finder(bqm);
301: Remover remover = new Remover(blm);
302: Collection orgs = finder.findOrganizationsByName(this
303: .getClass().getName());
304: for (Iterator orgIter = orgs.iterator(); orgIter.hasNext();) {
305: Organization org = (Organization) orgIter.next();
306: remover.removeOrganization(org);
307: }
308:
309: } catch (Exception e) {
310: e.printStackTrace();
311: fail(e.getMessage());
312: }
313: }
314:
315: @Test
316: public void deleteClassificationScheme() {
317: login();
318: try {
319: RegistryService rs = connection.getRegistryService();
320: bqm = rs.getBusinessQueryManager();
321: blm = rs.getBusinessLifeCycleManager();
322: System.out.println("We have the Business Query Manager");
323: Finder finder = new Finder(bqm);
324: Remover remover = new Remover(blm);
325: Collection schemes = finder
326: .findClassificationSchemesByName(this .getClass()
327: .getName());
328: for (Iterator iter = schemes.iterator(); iter.hasNext();) {
329: ClassificationScheme scheme = (ClassificationScheme) iter
330: .next();
331: remover.removeClassificationScheme(scheme);
332: }
333:
334: } catch (Exception e) {
335: e.printStackTrace();
336: fail(e.getMessage());
337: }
338: }
339:
340: public static junit.framework.Test suite() {
341: return new JUnit4TestAdapter(JAXR015PrimaryContactTest.class);
342: }
343: }
|