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.Key;
034: import javax.xml.registry.infomodel.Organization;
035: import javax.xml.registry.infomodel.Service;
036: import javax.xml.registry.infomodel.ServiceBinding;
037:
038: import junit.framework.JUnit4TestAdapter;
039:
040: import org.apache.ws.scout.BaseTestCase;
041: import org.apache.ws.scout.Creator;
042: import org.apache.ws.scout.Finder;
043: import org.apache.ws.scout.Printer;
044: import org.apache.ws.scout.Remover;
045: import org.junit.After;
046: import org.junit.Before;
047: import org.junit.Test;
048:
049: /**
050: * Test to check Jaxr Publish
051: * Open source UDDI Browser <http://www.uddibrowser.org>
052: * can be used to check your results
053: * @author <mailto:anil@apache.org>Anil Saldhana
054: * @since Nov 20, 2004
055: */
056: public class JAXR010OrganizationTest extends BaseTestCase {
057: @Before
058: public void setUp() {
059: super .setUp();
060: }
061:
062: @After
063: public void tearDown() {
064: super .tearDown();
065: }
066:
067: @Test
068: public void publishClassificationScheme() {
069: login();
070: try {
071: RegistryService rs = connection.getRegistryService();
072: blm = rs.getBusinessLifeCycleManager();
073: Creator creator = new Creator(blm);
074:
075: Collection<ClassificationScheme> schemes = new ArrayList<ClassificationScheme>();
076: ClassificationScheme classificationScheme = creator
077: .createClassificationScheme(this .getClass()
078: .getName());
079: schemes.add(classificationScheme);
080:
081: BulkResponse bulkResponse = blm
082: .saveClassificationSchemes(schemes);
083: assertEquals(JAXRResponse.STATUS_SUCCESS, bulkResponse
084: .getStatus());
085:
086: } catch (JAXRException e) {
087: e.printStackTrace();
088: assertTrue(false);
089: }
090: }
091:
092: @Test
093: public void publishOrganization() {
094: BulkResponse response = null;
095: login();
096: try {
097: RegistryService rs = connection.getRegistryService();
098: blm = rs.getBusinessLifeCycleManager();
099: bqm = rs.getBusinessQueryManager();
100: Creator creator = new Creator(blm);
101: Finder finder = new Finder(bqm);
102:
103: Collection<Organization> orgs = new ArrayList<Organization>();
104: Organization organization = creator.createOrganization(this
105: .getClass().getName());
106: // Add a Service
107: Service service = creator.createService(this .getClass()
108: .getName());
109: ServiceBinding serviceBinding = creator
110: .createServiceBinding();
111: service.addServiceBinding(serviceBinding);
112: organization.addService(service);
113: //Add a classification
114: ClassificationScheme cs = finder
115: .findClassificationSchemeByName(this .getClass()
116: .getName());
117: Classification classification = creator
118: .createClassification(cs);
119: organization.addClassification(classification);
120:
121: orgs.add(organization);
122:
123: //Now save the Organization along with a Service, ServiceBinding and Classification
124: BulkResponse br = blm.saveOrganizations(orgs);
125: if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
126: System.out.println("Organization Saved");
127: Collection coll = br.getCollection();
128: Iterator iter = coll.iterator();
129: while (iter.hasNext()) {
130: Key key = (Key) iter.next();
131: System.out.println("Saved Key=" + key.getId());
132: }//end while
133: } else {
134: System.err.println("JAXRExceptions "
135: + "occurred during save:");
136: Collection exceptions = br.getExceptions();
137: Iterator iter = exceptions.iterator();
138: while (iter.hasNext()) {
139: Exception e = (Exception) iter.next();
140: System.err.println(e.toString());
141: }
142: }
143:
144: } catch (JAXRException e) {
145: e.printStackTrace();
146: assertTrue(false);
147: }
148: assertNull(response);
149: }
150:
151: @Test
152: public void queryOrganization() {
153: login();
154: try {
155: // Get registry service and business query manager
156: RegistryService rs = connection.getRegistryService();
157: bqm = rs.getBusinessQueryManager();
158: System.out.println("We have the Business Query Manager");
159: Printer printer = new Printer();
160: Finder finder = new Finder(bqm);
161:
162: Collection orgs = finder.findOrganizationsByName(this
163: .getClass().getName());
164: if (orgs == null) {
165: fail("Only Expecting 1 Organization");
166: } else {
167: assertEquals(1, orgs.size());
168: // then step through them
169: for (Iterator orgIter = orgs.iterator(); orgIter
170: .hasNext();) {
171: Organization org = (Organization) orgIter.next();
172: System.out.println("Org name: "
173: + printer.getName(org));
174: System.out.println("Org description: "
175: + printer.getDescription(org));
176: System.out.println("Org key id: "
177: + printer.getKey(org));
178:
179: printer.printUser(org);
180: printer.printServices(org);
181: printer.printClassifications(org);
182: }
183: }//end else
184: } catch (JAXRException e) {
185: e.printStackTrace();
186: fail(e.getMessage());
187: }
188: }
189:
190: @Test
191: public void deleteOrganization() {
192: login();
193: try {
194: RegistryService rs = connection.getRegistryService();
195: blm = rs.getBusinessLifeCycleManager();
196: // Get registry service and business query manager
197: bqm = rs.getBusinessQueryManager();
198: System.out.println("We have the Business Query Manager");
199: Finder finder = new Finder(bqm);
200: Remover remover = new Remover(blm);
201: Collection orgs = finder.findOrganizationsByName(this
202: .getClass().getName());
203: for (Iterator orgIter = orgs.iterator(); orgIter.hasNext();) {
204: Organization org = (Organization) orgIter.next();
205: remover.removeOrganization(org);
206: }
207:
208: } catch (Exception e) {
209: e.printStackTrace();
210: fail(e.getMessage());
211: }
212: }
213:
214: @Test
215: public void deleteClassificationScheme() {
216: login();
217: try {
218: RegistryService rs = connection.getRegistryService();
219: bqm = rs.getBusinessQueryManager();
220: blm = rs.getBusinessLifeCycleManager();
221: System.out.println("We have the Business Query Manager");
222: Finder finder = new Finder(bqm);
223: Remover remover = new Remover(blm);
224: Collection schemes = finder
225: .findClassificationSchemesByName(this .getClass()
226: .getName());
227: for (Iterator iter = schemes.iterator(); iter.hasNext();) {
228: ClassificationScheme scheme = (ClassificationScheme) iter
229: .next();
230: remover.removeClassificationScheme(scheme);
231: }
232:
233: } catch (Exception e) {
234: e.printStackTrace();
235: fail(e.getMessage());
236: }
237: }
238:
239: public static junit.framework.Test suite() {
240: return new JUnit4TestAdapter(JAXR010OrganizationTest.class);
241: }
242: }
|