Source Code Cross Referenced for JAXR040ServiceTest.java in  » Web-Services » XML-Registry-JAXR » org » apache » ws » scout » registry » qa » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services » XML Registry JAXR » org.apache.ws.scout.registry.qa 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.fail;
019:
020:        import java.util.ArrayList;
021:        import java.util.Collection;
022:        import java.util.Iterator;
023:
024:        import javax.xml.registry.BulkResponse;
025:        import javax.xml.registry.BusinessQueryManager;
026:        import javax.xml.registry.FindQualifier;
027:        import javax.xml.registry.JAXRException;
028:        import javax.xml.registry.JAXRResponse;
029:        import javax.xml.registry.RegistryService;
030:        import javax.xml.registry.infomodel.InternationalString;
031:        import javax.xml.registry.infomodel.Key;
032:        import javax.xml.registry.infomodel.Organization;
033:        import javax.xml.registry.infomodel.Service;
034:
035:        import junit.framework.JUnit4TestAdapter;
036:
037:        import org.apache.ws.scout.BaseTestCase;
038:        import org.junit.After;
039:        import org.junit.Before;
040:        import org.junit.Test;
041:
042:        /**
043:         * Tests Publish, Delete (and indirectly, find) for service bindings.
044:         * 
045:         * You can comment out the deletion portion and use 
046:         * Open source UDDI Browser  <http://www.uddibrowser.org>
047:         * to check your intermediate results.
048:         *
049:         * Based on query/publish tests written by 
050:         * <a href="mailto:anil@apache.org">Anil Saldhana</a>.
051:         *
052:         * @author <a href="mailto:dbhole@redhat.com">Deepak Bhole</a>
053:         * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
054:         *
055:         * @since Sep 27, 2005
056:         */
057:        public class JAXR040ServiceTest extends BaseTestCase {
058:            private BusinessQueryManager bqm = null;
059:
060:            String serviceName = "Apache JAXR Service -- APACHE SCOUT TEST";
061:            String tempOrgName = "Apache JAXR Service Org -- APACHE SCOUT TEST";
062:
063:            @Before
064:            public void setUp() {
065:                super .setUp();
066:            }
067:
068:            @After
069:            public void tearDown() {
070:                super .tearDown();
071:            }
072:
073:            /**
074:             * Tests publishing and deleting of services.
075:             * 
076:             * Do not break this into testPublish(), testDelete(), etc. Order is
077:             * important, and not all jvms can guarantee order since the JUnit framework
078:             * uses getMethods() to gather test methods, and getMethods() does not
079:             * guarantee order.
080:             */
081:            @Test
082:            public void testPublishFindAndDeleteService() {
083:                login();
084:                try {
085:                    RegistryService rs = connection.getRegistryService();
086:                    bqm = rs.getBusinessQueryManager();
087:                    blm = rs.getBusinessLifeCycleManager();
088:
089:                    System.out
090:                            .println("\nCreating temporary organization...\n");
091:                    Organization org = createTempOrg();
092:
093:                    System.out.println("\nCreating service...\n");
094:                    createService(org);
095:
096:                    // All created ... now try to delete.
097:
098:                    findAndDeleteService(org.getKey());
099:                    deleteTempOrg(org.getKey());
100:
101:                } catch (JAXRException e) {
102:                    e.printStackTrace();
103:                    fail(e.getMessage());
104:                }
105:            }
106:
107:            private void createService(Organization org) throws JAXRException {
108:                Service service = blm.createService(getIString(serviceName));
109:                service.setDescription(getIString("Services in UDDI Registry"));
110:                service.setProvidingOrganization(org);
111:
112:                ArrayList<Service> services = new ArrayList<Service>();
113:                services.add(service);
114:
115:                BulkResponse br = blm.saveServices(services);
116:                if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
117:                    System.out.println("Service Saved");
118:                    Collection coll = br.getCollection();
119:                    Iterator iter = coll.iterator();
120:                    while (iter.hasNext()) {
121:                        Key key = (Key) iter.next();
122:                        System.out.println("Saved Key=" + key.getId());
123:                    }//end while
124:                } else {
125:                    System.err.println("JAXRExceptions "
126:                            + "occurred during save:");
127:                    Collection exceptions = br.getExceptions();
128:                    Iterator iter = exceptions.iterator();
129:                    while (iter.hasNext()) {
130:                        Exception e = (Exception) iter.next();
131:                        System.err.println(e.toString());
132:                        fail(e.toString());
133:                    }
134:                }
135:            }
136:
137:            private void findAndDeleteService(Key orgKey) throws JAXRException {
138:                Collection<String> findQualifiers = new ArrayList<String>();
139:                findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
140:                Collection<String> namePatterns = new ArrayList<String>();
141:                namePatterns.add("%" + serviceName + "%");
142:
143:                BulkResponse br = bqm.findServices(orgKey, findQualifiers,
144:                        namePatterns, null, null);
145:                Collection services = br.getCollection();
146:
147:                if (services == null) {
148:                    System.out.println("\n-- Matched 0 orgs");
149:
150:                } else {
151:                    System.out.println("\n-- Matched " + services.size()
152:                            + " services --\n");
153:
154:                    // then step through them
155:                    for (Iterator conceptIter = services.iterator(); conceptIter
156:                            .hasNext();) {
157:                        Service s = (Service) conceptIter.next();
158:
159:                        System.out.println("Id: " + s.getKey().getId());
160:                        System.out.println("Name: " + s.getName().getValue());
161:
162:                        // Print spacer between messages
163:                        System.out.println(" --- ");
164:
165:                        deleteService(s.getKey());
166:
167:                        System.out
168:                                .println("\n ============================== \n");
169:                    }
170:                }
171:            }
172:
173:            private void deleteService(Key key) throws JAXRException {
174:
175:                String id = key.getId();
176:
177:                System.out.println("\nDeleting service with id " + id + "\n");
178:
179:                Collection<Key> keys = new ArrayList<Key>();
180:                keys.add(key);
181:                BulkResponse response = blm.deleteServices(keys);
182:
183:                Collection exceptions = response.getExceptions();
184:                if (exceptions == null) {
185:                    Collection retKeys = response.getCollection();
186:                    Iterator keyIter = retKeys.iterator();
187:                    javax.xml.registry.infomodel.Key orgKey = null;
188:                    if (keyIter.hasNext()) {
189:                        orgKey = (javax.xml.registry.infomodel.Key) keyIter
190:                                .next();
191:                        id = orgKey.getId();
192:                        System.out.println("Service with ID=" + id
193:                                + " was deleted");
194:                    }
195:                }
196:            }
197:
198:            private Organization createTempOrg() throws JAXRException {
199:
200:                Key orgKey = null;
201:                Organization org = blm
202:                        .createOrganization(getIString(tempOrgName));
203:                org
204:                        .setDescription(getIString("Temporary organization to test saveService()"));
205:
206:                Collection<Organization> orgs = new ArrayList<Organization>();
207:                orgs.add(org);
208:                BulkResponse br = blm.saveOrganizations(orgs);
209:
210:                if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
211:                    orgKey = (Key) br.getCollection().iterator().next();
212:                    System.out
213:                            .println("Temporary Organization Created with id="
214:                                    + orgKey.getId());
215:                    org.setKey(orgKey);
216:                } else {
217:                    System.err
218:                            .println("JAXRExceptions "
219:                                    + "occurred during creation of temporary organization:");
220:
221:                    Iterator iter = br.getCollection().iterator();
222:
223:                    while (iter.hasNext()) {
224:                        Exception e = (Exception) iter.next();
225:                        System.err.println(e.toString());
226:                    }
227:
228:                    fail();
229:                }
230:
231:                return org;
232:            }
233:
234:            private void deleteTempOrg(Key orgKey) throws JAXRException {
235:
236:                String id = orgKey.getId();
237:
238:                System.out.println("\nDeleting temporary organization with id "
239:                        + id + "\n");
240:
241:                Collection<Key> keys = new ArrayList<Key>();
242:                keys.add(orgKey);
243:                BulkResponse response = blm.deleteOrganizations(keys);
244:
245:                Collection exceptions = response.getExceptions();
246:                if (exceptions == null) {
247:                    Collection retKeys = response.getCollection();
248:                    Iterator keyIter = retKeys.iterator();
249:                    orgKey = null;
250:                    if (keyIter.hasNext()) {
251:                        orgKey = (javax.xml.registry.infomodel.Key) keyIter
252:                                .next();
253:                        id = orgKey.getId();
254:                        System.out.println("Organization with ID=" + id
255:                                + " was deleted");
256:                    }
257:                }
258:            }
259:
260:            private InternationalString getIString(String str)
261:                    throws JAXRException {
262:                return blm.createInternationalString(str);
263:            }
264:
265:            public static junit.framework.Test suite() {
266:                return new JUnit4TestAdapter(JAXR040ServiceTest.class);
267:            }
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.