KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jaxr > scout > publish > JaxrSaveOrganizationTestCase


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.jaxr.scout.publish;
23
24
25 import org.jboss.test.jaxr.scout.JaxrBaseTestCase;
26
27 import javax.xml.registry.BulkResponse JavaDoc;
28 import javax.xml.registry.JAXRException JavaDoc;
29 import javax.xml.registry.JAXRResponse JavaDoc;
30 import javax.xml.registry.infomodel.Key JavaDoc;
31 import javax.xml.registry.infomodel.Organization JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.Collection JavaDoc;
34 import java.util.Iterator JavaDoc;
35
36 /**
37  * Tests Jaxr Save Organization
38  *
39  * @author <mailto:Anil.Saldhana@jboss.org>Anil Saldhana
40  * @since Dec 29, 2004
41  */

42
43 public class JaxrSaveOrganizationTestCase extends JaxrBaseTestCase
44 {
45    private Key JavaDoc orgKey = null;
46    
47     public void testSaveOrg() throws JAXRException JavaDoc
48     {
49         String JavaDoc keyid = "";
50         login();
51         try
52         {
53             rs = connection.getRegistryService();
54
55             blm = rs.getBusinessLifeCycleManager();
56             Collection JavaDoc orgs = new ArrayList JavaDoc();
57             Organization JavaDoc org = createOrganization("JBOSS");
58
59             orgs.add(org);
60             BulkResponse JavaDoc br = blm.saveOrganizations(orgs);
61             if (br.getStatus() == JAXRResponse.STATUS_SUCCESS)
62             {
63                 if ("true".equalsIgnoreCase(debugProp))
64                     System.out.println("Organization Saved");
65                 Collection JavaDoc coll = br.getCollection();
66                 Iterator JavaDoc iter = coll.iterator();
67                 while (iter.hasNext())
68                 {
69                     Key JavaDoc key = (Key JavaDoc) iter.next();
70                     keyid = key.getId();
71                     if ("true".equalsIgnoreCase(debugProp))
72                         System.out.println("Saved Key=" + key.getId());
73                     assertNotNull(keyid);
74                 }//end while
75
} else
76             {
77                 System.err.println("JAXRExceptions " +
78                         "occurred during save:");
79                 Collection JavaDoc exceptions = br.getExceptions();
80                 Iterator JavaDoc iter = exceptions.iterator();
81                 while (iter.hasNext())
82                 {
83                     Exception JavaDoc e = (Exception JavaDoc) iter.next();
84                     System.err.println(e.toString());
85                     fail(e.toString());
86                 }
87             }
88         } catch (JAXRException JavaDoc e)
89         {
90             e.printStackTrace();
91             fail(e.getMessage());
92         }
93         checkBusinessExists("JBOSS");
94     }
95
96     private void checkBusinessExists(String JavaDoc bizname)
97     {
98         String JavaDoc request = "<find_business generic='2.0' xmlns='urn:uddi-org:api_v2'>" +
99                 "<name xml:lang='en'>" + bizname + "</name></find_business>";
100         String JavaDoc response = null;
101         try
102         {
103             response = rs.makeRegistrySpecificRequest(request);
104         } catch (Exception JavaDoc e)
105         {
106             fail(e.getLocalizedMessage());
107         }
108         if (response == null || "".equals(response))
109             fail("Find Business failed");
110
111     }
112     
113     protected void tearDown() throws Exception JavaDoc
114     {
115        super.tearDown();
116        if(this.orgKey != null)
117           this.deleteOrganization(orgKey);
118     }
119 }
120
Popular Tags