Source Code Cross Referenced for ServiceImplTest.java in  » Web-Services-apache-cxf-2.0.1 » frontend » org » apache » cxf » jaxws » 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 apache cxf 2.0.1 » frontend » org.apache.cxf.jaxws 
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:         */package org.apache.cxf.jaxws;
019:
020:        import java.lang.reflect.Proxy;
021:        import java.net.URL;
022:        import java.util.ArrayList;
023:        import java.util.Iterator;
024:        import java.util.List;
025:
026:        import javax.xml.namespace.QName;
027:        import javax.xml.transform.Source;
028:        import javax.xml.ws.Dispatch;
029:        import javax.xml.ws.Service;
030:        import javax.xml.ws.WebServiceException;
031:        import javax.xml.ws.handler.Handler;
032:        import javax.xml.ws.handler.HandlerResolver;
033:        import javax.xml.ws.handler.PortInfo;
034:        import javax.xml.ws.soap.SOAPBinding;
035:
036:        import org.apache.cxf.Bus;
037:        import org.apache.cxf.BusException;
038:        import org.apache.cxf.bus.spring.SpringBusFactory;
039:        import org.apache.cxf.calculator.CalculatorPortType;
040:        import org.apache.cxf.endpoint.Client;
041:        import org.apache.cxf.endpoint.NullConduitSelector;
042:        import org.apache.cxf.frontend.ClientProxy;
043:        import org.apache.cxf.jaxb.JAXBDataBinding;
044:        import org.apache.hello_world_soap_http.Greeter;
045:        import org.apache.hello_world_soap_http.SOAPService;
046:        import org.junit.Test;
047:
048:        public class ServiceImplTest extends AbstractJaxWsTest {
049:
050:            private static final QName SERVICE_1 = new QName(
051:                    "http://apache.org/cxf/calculator", "CalculatorService");
052:
053:            private static final QName PORT_1 = new QName(
054:                    "http://apache.org/cxf/calculator", "CalculatorPort");
055:
056:            private static final QName SOAP_PORT = new QName(
057:                    "http://apache.org/hello_world_soap_http", "SoapPort");
058:
059:            @Test
060:            public void testServiceImpl() throws Exception {
061:                SOAPService service = new SOAPService();
062:
063:                Greeter proxy = service.getSoapPort();
064:
065:                Client client = ClientProxy.getClient(proxy);
066:                assertEquals("bar", client.getEndpoint().get("foo"));
067:                assertNotNull("expected ConduitSelector", client
068:                        .getConduitSelector());
069:                assertTrue("unexpected ConduitSelector", client
070:                        .getConduitSelector() instanceof  NullConduitSelector);
071:            }
072:
073:            @Test
074:            public void testNonSpecificGetPort() throws Exception {
075:                SOAPService service = new SOAPService();
076:
077:                Greeter proxy = service.getPort(Greeter.class);
078:
079:                Client client = ClientProxy.getClient(proxy);
080:                assertEquals("unexpected port selected", SOAP_PORT, client
081:                        .getEndpoint().getEndpointInfo().getName());
082:                assertEquals("bar", client.getEndpoint().get("foo"));
083:                assertNotNull("expected ConduitSelector", client
084:                        .getConduitSelector());
085:                assertTrue("unexpected ConduitSelector", client
086:                        .getConduitSelector() instanceof  NullConduitSelector);
087:            }
088:
089:            @Override
090:            protected Bus createBus() throws BusException {
091:                SpringBusFactory bf = new SpringBusFactory();
092:                return bf
093:                        .createBus("/org/apache/cxf/jaxws/soapServiceConfig.xml");
094:            }
095:
096:            @Test
097:            public void testBadServiceName() {
098:                URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
099:                assertNotNull(wsdl1);
100:
101:                QName badService = new QName(
102:                        "http://apache.org/cxf/calculator", "DoesNotExist");
103:
104:                try {
105:                    new ServiceImpl(getBus(), wsdl1, badService,
106:                            ServiceImpl.class);
107:                    fail("Did not throw exception");
108:                } catch (WebServiceException e) {
109:                    // that's expected
110:                }
111:            }
112:
113:            @Test
114:            public void testPorts() {
115:                URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
116:                assertNotNull(wsdl1);
117:
118:                ServiceImpl service = new ServiceImpl(getBus(), wsdl1,
119:                        SERVICE_1, ServiceImpl.class);
120:                Iterator iter = service.getPorts();
121:                assertNotNull(iter);
122:                assertTrue(iter.hasNext());
123:                assertEquals(PORT_1, iter.next());
124:                assertFalse(iter.hasNext());
125:            }
126:
127:            @Test
128:            public void testGetBadPort() {
129:                URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
130:                assertNotNull(wsdl1);
131:
132:                ServiceImpl service = new ServiceImpl(getBus(), wsdl1,
133:                        SERVICE_1, ServiceImpl.class);
134:
135:                QName badPort = new QName("http://apache.org/cxf/calculator",
136:                        "PortDoesNotExist");
137:                try {
138:                    service.getPort(badPort, CalculatorPortType.class);
139:                    fail("Did not throw expected exception");
140:                } catch (WebServiceException e) {
141:                    // that's ok
142:                }
143:            }
144:
145:            @Test
146:            public void testGetBadSEI() {
147:                URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
148:                assertNotNull(wsdl1);
149:
150:                ServiceImpl service = new ServiceImpl(getBus(), wsdl1,
151:                        SERVICE_1, ServiceImpl.class);
152:
153:                try {
154:                    service.getPort(ServiceImpl.class);
155:                    fail("Did not throw expected exception");
156:                } catch (WebServiceException e) {
157:                    // that's ok
158:                }
159:            }
160:
161:            @Test
162:            public void testGetGoodPort() {
163:                URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
164:                assertNotNull(wsdl1);
165:
166:                ServiceImpl service = new ServiceImpl(getBus(), wsdl1,
167:                        SERVICE_1, ServiceImpl.class);
168:
169:                CalculatorPortType cal = (CalculatorPortType) service.getPort(
170:                        PORT_1, CalculatorPortType.class);
171:                assertNotNull(cal);
172:            }
173:
174:            @Test
175:            public void testJAXBCachedOnRepeatGetPort() {
176:                URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
177:                assertNotNull(wsdl1);
178:
179:                ServiceImpl service = new ServiceImpl(getBus(), wsdl1,
180:                        SERVICE_1, ServiceImpl.class);
181:
182:                CalculatorPortType cal1 = (CalculatorPortType) service.getPort(
183:                        PORT_1, CalculatorPortType.class);
184:                assertNotNull(cal1);
185:
186:                ClientProxy cp = (ClientProxy) Proxy.getInvocationHandler(cal1);
187:                JAXBDataBinding db1 = (JAXBDataBinding) cp.getClient()
188:                        .getEndpoint().getService().getDataBinding();
189:                assertNotNull(db1);
190:
191:                System.gc();
192:                System.gc();
193:                System.gc();
194:                System.gc();
195:
196:                CalculatorPortType cal2 = (CalculatorPortType) service.getPort(
197:                        PORT_1, CalculatorPortType.class);
198:                assertNotNull(cal2);
199:
200:                cp = (ClientProxy) Proxy.getInvocationHandler(cal2);
201:                JAXBDataBinding db2 = (JAXBDataBinding) cp.getClient()
202:                        .getEndpoint().getService().getDataBinding();
203:                assertNotNull(db2);
204:
205:                assertEquals("got cached JAXBContext", db1.getContext(), db2
206:                        .getContext());
207:            }
208:
209:            @Test
210:            public void testCreateDispatchGoodPort() {
211:                URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
212:                assertNotNull(wsdl1);
213:
214:                ServiceImpl service = new ServiceImpl(getBus(), wsdl1,
215:                        SERVICE_1, ServiceImpl.class);
216:
217:                Dispatch dispatch = service.createDispatch(PORT_1,
218:                        Source.class, Service.Mode.PAYLOAD);
219:                assertNotNull(dispatch);
220:            }
221:
222:            @Test
223:            public void testCreateDispatchBadPort() {
224:                URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
225:                assertNotNull(wsdl1);
226:
227:                ServiceImpl service = new ServiceImpl(getBus(), wsdl1,
228:                        SERVICE_1, ServiceImpl.class);
229:
230:                QName badPort = new QName("http://apache.org/cxf/calculator",
231:                        "PortDoesNotExist");
232:                try {
233:                    service.createDispatch(badPort, Source.class,
234:                            Service.Mode.PAYLOAD);
235:                } catch (WebServiceException e) {
236:                    // that's ok
237:                }
238:            }
239:
240:            @Test
241:            public void testHandlerResolver() {
242:                URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
243:                assertNotNull(wsdl1);
244:
245:                ServiceImpl service = new ServiceImpl(getBus(), wsdl1,
246:                        SERVICE_1, ServiceImpl.class);
247:
248:                TestHandlerResolver resolver = new TestHandlerResolver();
249:                assertNull(resolver.getPortInfo());
250:
251:                service.setHandlerResolver(resolver);
252:
253:                CalculatorPortType cal = (CalculatorPortType) service.getPort(
254:                        PORT_1, CalculatorPortType.class);
255:                assertNotNull(cal);
256:
257:                PortInfo info = resolver.getPortInfo();
258:                assertNotNull(info);
259:                assertEquals(SERVICE_1, info.getServiceName());
260:                assertEquals(PORT_1, info.getPortName());
261:                assertEquals(SOAPBinding.SOAP12HTTP_BINDING, info
262:                        .getBindingID());
263:            }
264:
265:            private static class TestHandlerResolver implements  HandlerResolver {
266:                private PortInfo info;
267:
268:                public PortInfo getPortInfo() {
269:                    return info;
270:                }
271:
272:                public List<Handler> getHandlerChain(PortInfo portInfo) {
273:                    List<Handler> handlerList = new ArrayList<Handler>();
274:                    this.info = portInfo;
275:                    return handlerList;
276:                }
277:            }
278:
279:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.