001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.jaxr.scout.publish;
023:
024: import org.jboss.test.jaxr.scout.JaxrBaseTestCase;
025:
026: import javax.xml.registry.BulkResponse;
027: import javax.xml.registry.JAXRException;
028: import javax.xml.registry.JAXRResponse;
029: import javax.xml.registry.infomodel.Key;
030: import javax.xml.registry.infomodel.Organization;
031: import java.util.ArrayList;
032: import java.util.Collection;
033: import java.util.Iterator;
034:
035: /**
036: * Tests Jaxr Save Organization
037: *
038: * @author <mailto:Anil.Saldhana@jboss.org>Anil Saldhana
039: * @since Dec 29, 2004
040: */
041:
042: public class JaxrSaveOrganizationTestCase extends JaxrBaseTestCase {
043: private Key orgKey = null;
044:
045: public void testSaveOrg() throws JAXRException {
046: String keyid = "";
047: login();
048: try {
049: rs = connection.getRegistryService();
050:
051: blm = rs.getBusinessLifeCycleManager();
052: Collection orgs = new ArrayList();
053: Organization org = createOrganization("JBOSS");
054:
055: orgs.add(org);
056: BulkResponse br = blm.saveOrganizations(orgs);
057: if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
058: if ("true".equalsIgnoreCase(debugProp))
059: System.out.println("Organization Saved");
060: Collection coll = br.getCollection();
061: Iterator iter = coll.iterator();
062: while (iter.hasNext()) {
063: Key key = (Key) iter.next();
064: keyid = key.getId();
065: if ("true".equalsIgnoreCase(debugProp))
066: System.out.println("Saved Key=" + key.getId());
067: assertNotNull(keyid);
068: }//end while
069: } else {
070: System.err.println("JAXRExceptions "
071: + "occurred during save:");
072: Collection exceptions = br.getExceptions();
073: Iterator iter = exceptions.iterator();
074: while (iter.hasNext()) {
075: Exception e = (Exception) iter.next();
076: System.err.println(e.toString());
077: fail(e.toString());
078: }
079: }
080: } catch (JAXRException e) {
081: e.printStackTrace();
082: fail(e.getMessage());
083: }
084: checkBusinessExists("JBOSS");
085: }
086:
087: private void checkBusinessExists(String bizname) {
088: String request = "<find_business generic='2.0' xmlns='urn:uddi-org:api_v2'>"
089: + "<name xml:lang='en'>"
090: + bizname
091: + "</name></find_business>";
092: String response = null;
093: try {
094: response = rs.makeRegistrySpecificRequest(request);
095: } catch (Exception e) {
096: fail(e.getLocalizedMessage());
097: }
098: if (response == null || "".equals(response))
099: fail("Find Business failed");
100:
101: }
102:
103: protected void tearDown() throws Exception {
104: super.tearDown();
105: if (this.orgKey != null)
106: this.deleteOrganization(orgKey);
107: }
108: }
|