Source Code Cross Referenced for ServiceTests.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » description » 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 AXIS2 » jax ws » org.apache.axis2.jaxws.description 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:
020:        package org.apache.axis2.jaxws.description;
021:
022:        import java.net.URL;
023:        import java.util.Iterator;
024:        import java.util.List;
025:
026:        import javax.xml.namespace.QName;
027:        import javax.xml.ws.Dispatch;
028:        import javax.xml.ws.Service;
029:        import javax.xml.ws.WebServiceException;
030:
031:        import junit.framework.TestCase;
032:        import org.apache.axis2.jaxws.sample.addnumbers.AddNumbersPortType;
033:        import org.apache.axis2.jaxws.spi.ServiceDelegate;
034:
035:        public class ServiceTests extends TestCase {
036:            private static String VALID_SERVICE_NAMESPACE = "http://org/test/addnumbers";
037:            private static String VALID_SERVICE_LOCALPART_1 = "AddNumbersService1";
038:            private static String VALID_SERVICE_LOCALPART_2 = "AddNumbersService2";
039:            private static String VALID_PORT_S1P1 = "AddNumbersPortS1P1";
040:            private static String VALID_PORT_S1P2 = "AddNumbersPortS1P2";
041:            private static String VALID_PORT_S1P3 = "AddNumbersPortS1P3";
042:            private static String VALID_PORT_S2P1 = "AddNumbersPortS2P1";
043:            private static String VALID_PORT_S2P2 = "AddNumbersPortS2P2";
044:            private static String VALID_PORT_S2P3 = "AddNumbersPortS2P3";
045:            private static String VALID_PORT_S2P4 = "AddNumbersPortS2P4";
046:
047:            public void testInvalidServiceNamespace() {
048:                URL wsdlURL = DescriptionTestUtils2
049:                        .getWSDLURL("WSDLMultiTests.wsdl");
050:                QName invalidServiceQN = new QName("invalidServiceNamespace",
051:                        VALID_SERVICE_LOCALPART_1);
052:                try {
053:                    Service invalidService = Service.create(wsdlURL,
054:                            invalidServiceQN);
055:                    fail("Created service with invalid namespace");
056:                } catch (WebServiceException ex) {
057:                    // Expected code path
058:                } catch (Exception ex) {
059:                    fail("Caught unexpected exception " + ex.toString());
060:                }
061:            }
062:
063:            public void testInvalidServiceLocalPart() {
064:                URL wsdlURL = DescriptionTestUtils2
065:                        .getWSDLURL("WSDLMultiTests.wsdl");
066:                QName invalidServiceQN = new QName(VALID_SERVICE_NAMESPACE,
067:                        "invalidServiceName");
068:                try {
069:                    Service invalidService = Service.create(wsdlURL,
070:                            invalidServiceQN);
071:                    fail("Created service with invalid namespace");
072:                } catch (WebServiceException ex) {
073:                    // Expected code path
074:                } catch (Exception ex) {
075:                    fail("Caught unexpected exception " + ex.toString());
076:                }
077:            }
078:
079:            public void testValidSameService() {
080:                URL wsdlURL = DescriptionTestUtils2
081:                        .getWSDLURL("WSDLMultiTests.wsdl");
082:
083:                QName validService1QN = new QName(VALID_SERVICE_NAMESPACE,
084:                        VALID_SERVICE_LOCALPART_1);
085:                Service validService1 = Service
086:                        .create(wsdlURL, validService1QN);
087:                assertNotNull(validService1);
088:
089:                QName validService2QN = new QName(VALID_SERVICE_NAMESPACE,
090:                        VALID_SERVICE_LOCALPART_1);
091:                Service validService2 = Service
092:                        .create(wsdlURL, validService2QN);
093:                assertNotNull(validService2);
094:
095:            }
096:
097:            public void testValidMultiServices() {
098:                URL wsdlURL = DescriptionTestUtils2
099:                        .getWSDLURL("WSDLMultiTests.wsdl");
100:
101:                QName validService1QN = new QName(VALID_SERVICE_NAMESPACE,
102:                        VALID_SERVICE_LOCALPART_1);
103:                Service validService1 = Service
104:                        .create(wsdlURL, validService1QN);
105:                assertNotNull(validService1);
106:
107:                QName validService2QN = new QName(VALID_SERVICE_NAMESPACE,
108:                        VALID_SERVICE_LOCALPART_2);
109:                Service validService2 = Service
110:                        .create(wsdlURL, validService2QN);
111:                assertNotNull(validService2);
112:                assertNotSame(validService1, validService2);
113:
114:            }
115:
116:            public void testGetServiceDeclaredPorts() {
117:                URL wsdlURL = DescriptionTestUtils2
118:                        .getWSDLURL("WSDLMultiTests.wsdl");
119:
120:                QName service1QN = new QName(VALID_SERVICE_NAMESPACE,
121:                        VALID_SERVICE_LOCALPART_1);
122:                Service service1 = Service.create(wsdlURL, service1QN);
123:                assertNotNull(service1);
124:                ServiceDelegate service1Delegate = DescriptionTestUtils2
125:                        .getServiceDelegate(service1);
126:                assertNotNull(service1Delegate);
127:                ServiceDescription service1Desc = service1Delegate
128:                        .getServiceDescription();
129:                assertNotNull(service1Desc);
130:                List<QName> service1PortsList = service1Desc.getPorts();
131:                assertNotNull(service1PortsList);
132:                assertEquals(3, service1PortsList.size());
133:                Iterator<QName> service1PortIterator = service1.getPorts();
134:                assertQNameIteratorSameAsList(service1PortIterator,
135:                        service1PortsList);
136:
137:                QName service2QN = new QName(VALID_SERVICE_NAMESPACE,
138:                        VALID_SERVICE_LOCALPART_2);
139:                Service service2 = Service.create(wsdlURL, service2QN);
140:                assertNotNull(service2);
141:                ServiceDelegate service2Delegate = DescriptionTestUtils2
142:                        .getServiceDelegate(service2);
143:                assertNotNull(service2Delegate);
144:                ServiceDescription service2Desc = service2Delegate
145:                        .getServiceDescription();
146:                assertNotNull(service2Desc);
147:                List<QName> service2PortsList = service2Desc.getPorts();
148:                assertNotNull(service2PortsList);
149:                assertEquals(4, service2PortsList.size());
150:                Iterator<QName> service2PortIterator = service2.getPorts();
151:                assertQNameIteratorSameAsList(service2PortIterator,
152:                        service2PortsList);
153:            }
154:
155:            public void testGetServiceAddedPorts() {
156:                URL wsdlURL = DescriptionTestUtils2
157:                        .getWSDLURL("WSDLMultiTests.wsdl");
158:
159:                QName service1QN = new QName(VALID_SERVICE_NAMESPACE,
160:                        VALID_SERVICE_LOCALPART_1);
161:                Service service1 = Service.create(wsdlURL, service1QN);
162:                assertNotNull(service1);
163:                ServiceDelegate service1Delegate = DescriptionTestUtils2
164:                        .getServiceDelegate(service1);
165:                assertNotNull(service1Delegate);
166:                ServiceDescription service1Desc = service1Delegate
167:                        .getServiceDescription();
168:                assertNotNull(service1Desc);
169:                List<QName> service1PortsList = service1Desc.getPorts();
170:                assertNotNull(service1PortsList);
171:                assertEquals(3, service1PortsList.size());
172:                service1.addPort(new QName(VALID_SERVICE_NAMESPACE,
173:                        "addedPortS1P1"), null, null);
174:                service1.addPort(new QName(VALID_SERVICE_NAMESPACE,
175:                        "addedPortS1P2"), null, null);
176:                service1PortsList = service1Desc.getPorts();
177:                assertEquals(5, service1PortsList.size());
178:                Iterator<QName> service1PortIterator = service1.getPorts();
179:                assertQNameIteratorSameAsList(service1PortIterator,
180:                        service1PortsList);
181:
182:                QName service2QN = new QName(VALID_SERVICE_NAMESPACE,
183:                        VALID_SERVICE_LOCALPART_2);
184:                Service service2 = Service.create(wsdlURL, service2QN);
185:                assertNotNull(service2);
186:                ServiceDelegate service2Delegate = DescriptionTestUtils2
187:                        .getServiceDelegate(service2);
188:                assertNotNull(service2Delegate);
189:                ServiceDescription service2Desc = service2Delegate
190:                        .getServiceDescription();
191:                assertNotNull(service2Desc);
192:                List<QName> service2PortsList = service2Desc.getPorts();
193:                assertNotNull(service2PortsList);
194:                assertEquals(4, service2PortsList.size());
195:                service2.addPort(new QName(VALID_SERVICE_NAMESPACE,
196:                        "addedPortS2P1"), null, null);
197:                service2.addPort(new QName(VALID_SERVICE_NAMESPACE,
198:                        "addedPortS2P2"), null, null);
199:                service2PortsList = service2Desc.getPorts();
200:                assertEquals(6, service2PortsList.size());
201:                Iterator<QName> service2PortIterator = service2.getPorts();
202:                assertQNameIteratorSameAsList(service2PortIterator,
203:                        service2PortsList);
204:            }
205:
206:            public void testGetServiceDeclaredPortsAfterGetPort() {
207:                URL wsdlURL = DescriptionTestUtils2
208:                        .getWSDLURL("WSDLMultiTests.wsdl");
209:
210:                QName service1QN = new QName(VALID_SERVICE_NAMESPACE,
211:                        VALID_SERVICE_LOCALPART_1);
212:                Service service1 = Service.create(wsdlURL, service1QN);
213:                assertNotNull(service1);
214:                ServiceDelegate service1Delegate = DescriptionTestUtils2
215:                        .getServiceDelegate(service1);
216:                assertNotNull(service1Delegate);
217:                ServiceDescription service1Desc = service1Delegate
218:                        .getServiceDescription();
219:                assertNotNull(service1Desc);
220:                List<QName> service1PortsList = service1Desc.getPorts();
221:                assertNotNull(service1PortsList);
222:                assertEquals(3, service1PortsList.size());
223:                AddNumbersPortType addNumbersPortS1P1 = service1.getPort(
224:                        new QName(VALID_SERVICE_NAMESPACE, VALID_PORT_S1P1),
225:                        AddNumbersPortType.class);
226:                service1PortsList = service1Desc.getPorts();
227:                assertEquals(3, service1PortsList.size());
228:                AddNumbersPortType addNumbersPortS1P3 = service1.getPort(
229:                        new QName(VALID_SERVICE_NAMESPACE, VALID_PORT_S1P3),
230:                        AddNumbersPortType.class);
231:                assertEquals(3, service1PortsList.size());
232:                service1.addPort(new QName(VALID_SERVICE_NAMESPACE,
233:                        "addedPortS1P1"), null, null);
234:                service1.addPort(new QName(VALID_SERVICE_NAMESPACE,
235:                        "addedPortS1P2"), null, null);
236:                service1PortsList = service1Desc.getPorts();
237:                assertEquals(5, service1PortsList.size());
238:                Iterator<QName> service1PortIterator = service1.getPorts();
239:                assertQNameIteratorSameAsList(service1PortIterator,
240:                        service1PortsList);
241:
242:                QName service2QN = new QName(VALID_SERVICE_NAMESPACE,
243:                        VALID_SERVICE_LOCALPART_2);
244:                Service service2 = Service.create(wsdlURL, service2QN);
245:                assertNotNull(service2);
246:                ServiceDelegate service2Delegate = DescriptionTestUtils2
247:                        .getServiceDelegate(service2);
248:                assertNotNull(service2Delegate);
249:                ServiceDescription service2Desc = service2Delegate
250:                        .getServiceDescription();
251:                assertNotNull(service2Desc);
252:                List<QName> service2PortsList = service2Desc.getPorts();
253:                assertNotNull(service2PortsList);
254:                assertEquals(4, service2PortsList.size());
255:                AddNumbersPortType addNumbersPortS2P1 = service2.getPort(
256:                        new QName(VALID_SERVICE_NAMESPACE, VALID_PORT_S2P1),
257:                        AddNumbersPortType.class);
258:                service2PortsList = service2Desc.getPorts();
259:                assertEquals(4, service2PortsList.size());
260:                AddNumbersPortType addNumbersPortS2P3 = service2.getPort(
261:                        new QName(VALID_SERVICE_NAMESPACE, VALID_PORT_S2P3),
262:                        AddNumbersPortType.class);
263:                assertEquals(4, service2PortsList.size());
264:                AddNumbersPortType addNumbersPortS2P4 = service2.getPort(
265:                        new QName(VALID_SERVICE_NAMESPACE, VALID_PORT_S2P4),
266:                        AddNumbersPortType.class);
267:                assertEquals(4, service2PortsList.size());
268:                service2.addPort(new QName(VALID_SERVICE_NAMESPACE,
269:                        "addedPortS2P1"), null, null);
270:                service2.addPort(new QName(VALID_SERVICE_NAMESPACE,
271:                        "addedPortS2P2"), null, null);
272:                service2PortsList = service2Desc.getPorts();
273:                assertEquals(6, service2PortsList.size());
274:                Iterator<QName> service2PortIterator = service2.getPorts();
275:                assertQNameIteratorSameAsList(service2PortIterator,
276:                        service2PortsList);
277:            }
278:
279:            public void testDynamicService() {
280:                QName service1QN = new QName(VALID_SERVICE_NAMESPACE,
281:                        "DynamicService1");
282:                Service service1 = Service.create(null, service1QN);
283:                assertNotNull(service1);
284:                ServiceDelegate service1Delegate = DescriptionTestUtils2
285:                        .getServiceDelegate(service1);
286:                assertNotNull(service1Delegate);
287:                ServiceDescription service1Desc = service1Delegate
288:                        .getServiceDescription();
289:                assertNotNull(service1Desc);
290:                List<QName> service1PortsList = service1Desc.getPorts();
291:                assertNotNull(service1PortsList);
292:                assertTrue(service1PortsList.isEmpty());
293:                assertEquals(0, service1PortsList.size());
294:                AddNumbersPortType addNumbersPortS1P1 = service1.getPort(
295:                        new QName(VALID_SERVICE_NAMESPACE, "dynamicPortS1P1"),
296:                        AddNumbersPortType.class);
297:                service1PortsList = service1Desc.getPorts();
298:                assertEquals(1, service1PortsList.size());
299:                AddNumbersPortType addNumbersPortS1P3 = service1.getPort(
300:                        new QName(VALID_SERVICE_NAMESPACE, "dynamicPortS1P2"),
301:                        AddNumbersPortType.class);
302:                service1PortsList = service1Desc.getPorts();
303:                assertEquals(2, service1PortsList.size());
304:                service1.addPort(new QName(VALID_SERVICE_NAMESPACE,
305:                        "addedPortS1P1"), null, null);
306:                service1.addPort(new QName(VALID_SERVICE_NAMESPACE,
307:                        "addedPortS1P2"), null, null);
308:                service1PortsList = service1Desc.getPorts();
309:                assertEquals(4, service1PortsList.size());
310:                Iterator<QName> service1PortIterator = service1.getPorts();
311:                assertQNameIteratorSameAsList(service1PortIterator,
312:                        service1PortsList);
313:            }
314:
315:            public void testCreateDispatchWSDL() {
316:                URL wsdlURL = DescriptionTestUtils2
317:                        .getWSDLURL("WSDLMultiTests.wsdl");
318:
319:                QName service1QN = new QName(VALID_SERVICE_NAMESPACE,
320:                        VALID_SERVICE_LOCALPART_1);
321:                Service service1 = Service.create(wsdlURL, service1QN);
322:                assertNotNull(service1);
323:                // Create Dispatch should work on a WSDL declared port prior to a getPort
324:                // and again after the call to getPort
325:                QName validPortQName = new QName(VALID_SERVICE_NAMESPACE,
326:                        VALID_PORT_S1P1);
327:                Dispatch<String> dispatch = service1.createDispatch(
328:                        validPortQName, String.class, null);
329:                assertNotNull(dispatch);
330:                AddNumbersPortType addNumbersPortS1P1 = service1.getPort(
331:                        validPortQName, AddNumbersPortType.class);
332:                assertNotNull(addNumbersPortS1P1);
333:
334:                // Create Dispatch should NOT work on a dynamic port that has not been added yet
335:                // but should work after it has been added
336:                QName addedPort = new QName(VALID_SERVICE_NAMESPACE,
337:                        "addedPortS1P1");
338:                try {
339:                    Dispatch<String> dispatch2 = service1.createDispatch(
340:                            addedPort, String.class, null);
341:                    fail("Create Dispatch on non-existant port should have thrown an exception");
342:                } catch (WebServiceException ex) {
343:                    // Expected path
344:                } catch (Exception ex) {
345:                    fail("Unexpected exception thrown " + ex.toString());
346:                }
347:                service1.addPort(addedPort, null, null);
348:                Dispatch<String> dispatch2 = service1.createDispatch(addedPort,
349:                        String.class, null);
350:                assertNotNull(dispatch2);
351:
352:            }
353:
354:            public void testCreateDispatchNoWSDL() {
355:
356:                // Note that this test is intentionally using the same names as the WSDL test, even though no WSDL is
357:                // provided.  This is to verify that using the same names in the abscense of WSDL doesn't cause any
358:                // issues.
359:
360:                QName service1QN = new QName(VALID_SERVICE_NAMESPACE,
361:                        VALID_SERVICE_LOCALPART_1);
362:                Service service1 = Service.create(service1QN);
363:                assertNotNull(service1);
364:                // Create Dispatch should NOT work on a dynamic port prior to a getPort
365:                // but should work after the getPort causes the port to be added.
366:                QName validPortQName = new QName(VALID_SERVICE_NAMESPACE,
367:                        VALID_PORT_S1P1);
368:                try {
369:                    Dispatch<String> dispatch = service1.createDispatch(
370:                            validPortQName, String.class, null);
371:                    fail("Create Dispatch on non-existant port should have thrown and exception");
372:                } catch (WebServiceException ex) {
373:                    // Expected path
374:                } catch (Exception ex) {
375:                    fail("Unexpected exception thrown " + ex.toString());
376:                }
377:                AddNumbersPortType addNumbersPortS1P1 = service1.getPort(
378:                        validPortQName, AddNumbersPortType.class);
379:                Dispatch<String> dispatch = service1.createDispatch(
380:                        validPortQName, String.class, null);
381:                assertNotNull(dispatch);
382:
383:                // Create Dispatch should NOT work on a dynamic port that has not been added yet
384:                // but should work after it has been added
385:                QName addedPort = new QName(VALID_SERVICE_NAMESPACE,
386:                        "addedPortS1P1");
387:                try {
388:                    Dispatch<String> dispatch2 = service1.createDispatch(
389:                            addedPort, String.class, null);
390:                    fail("Create Dispatch on non-existant port should have thrown an exception");
391:                } catch (WebServiceException ex) {
392:                    // Expected path
393:                } catch (Exception ex) {
394:                    fail("Unexpected exception thrown " + ex.toString());
395:                }
396:                service1.addPort(addedPort, null, null);
397:                Dispatch<String> dispatch2 = service1.createDispatch(addedPort,
398:                        String.class, null);
399:                assertNotNull(dispatch2);
400:            }
401:
402:            private void assertQNameIteratorSameAsList(
403:                    Iterator<QName> iterator, List<QName> list) {
404:                int iteratorSize = 0;
405:                for (QName iteratorElement = null; iterator.hasNext();) {
406:                    iteratorElement = iterator.next();
407:                    iteratorSize++;
408:                    assertTrue(list.contains(iteratorElement));
409:                }
410:                assertEquals(list.size(), iteratorSize);
411:            }
412:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.