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: package org.apache.axis2.jaxws.description;
020:
021: import java.lang.reflect.Proxy;
022: import java.net.URL;
023:
024: import javax.xml.namespace.QName;
025: import javax.xml.ws.Dispatch;
026: import javax.xml.ws.Service;
027:
028: import junit.framework.TestCase;
029: import org.apache.axis2.description.AxisService;
030: import org.apache.axis2.jaxws.spi.BindingProvider;
031: import org.apache.axis2.jaxws.spi.ServiceDelegate;
032: import org.apache.ws.axis2.tests.EchoPort;
033:
034: /**
035: * Test that the EndpointDescription can be gotten from
036: * the Binding Provider impl class and that the AxisService can be
037: * gotten from the EndpointDesc. Note that the BindingProvider class is NOT
038: * the jaxws API one; it is the internal implementation BindingProvider class.
039: */
040: public class GetDescFromBindingProviderTests extends TestCase {
041:
042: private static final String wsdlSOAPAddress = "http://localhost:8080/axis2/services/EchoService";
043:
044: public void testForProxy() {
045: String namespaceURI = "http://ws.apache.org/axis2/tests";
046: String localPart = "EchoService";
047:
048: URL wsdlURL = DescriptionTestUtils2.getWSDLURL();
049: assertNotNull(wsdlURL);
050:
051: Service service = Service.create(wsdlURL, new QName(
052: namespaceURI, localPart));
053: assertNotNull(service);
054:
055: QName validPortQName = new QName(namespaceURI, "EchoPort");
056: EchoPort echoPort = service.getPort(validPortQName,
057: EchoPort.class);
058: assertNotNull(echoPort);
059:
060: BindingProvider bindingProvider = (BindingProvider) Proxy
061: .getInvocationHandler(echoPort);
062: ServiceDelegate serviceDelegate = bindingProvider
063: .getServiceDelegate();
064: assertNotNull(serviceDelegate);
065: EndpointDescription endpointDesc = bindingProvider
066: .getEndpointDescription();
067: assertNotNull(endpointDesc);
068: AxisService axisService = endpointDesc.getAxisService();
069: assertNotNull(axisService);
070:
071: // The endpoint address should match what is in the WSDL
072: String endpointAddress = endpointDesc.getEndpointAddress();
073: assertEquals(wsdlSOAPAddress, endpointAddress);
074: }
075:
076: public void testForDispatch() {
077: String namespaceURI = "http://ws.apache.org/axis2/tests";
078: String localPart = "EchoService";
079:
080: URL wsdlURL = DescriptionTestUtils2.getWSDLURL();
081: assertNotNull(wsdlURL);
082:
083: Service service = Service.create(wsdlURL, new QName(
084: namespaceURI, localPart));
085: assertNotNull(service);
086:
087: QName validPortQName = new QName(namespaceURI, "EchoPort");
088: Dispatch<String> dispatch = service.createDispatch(
089: validPortQName, String.class, null);
090: assertNotNull(dispatch);
091:
092: BindingProvider bindingProvider = (BindingProvider) dispatch;
093: ServiceDelegate serviceDelegate = bindingProvider
094: .getServiceDelegate();
095: assertNotNull(serviceDelegate);
096: EndpointDescription endpointDesc = bindingProvider
097: .getEndpointDescription();
098: assertNotNull(endpointDesc);
099: AxisService axisService = endpointDesc.getAxisService();
100: assertNotNull(axisService);
101:
102: // The endpoint address should match what is in the WSDL
103: String endpointAddress = endpointDesc.getEndpointAddress();
104: assertEquals(wsdlSOAPAddress, endpointAddress);
105: }
106:
107: public void testForAddPort() {
108: String namespaceURI = "http://ws.apache.org/axis2/tests";
109: String localPart = "EchoService";
110:
111: URL wsdlURL = DescriptionTestUtils2.getWSDLURL();
112: assertNotNull(wsdlURL);
113:
114: Service service = Service.create(wsdlURL, new QName(
115: namespaceURI, localPart));
116: assertNotNull(service);
117:
118: QName validPortQName = new QName(namespaceURI, "EchoPortAdded");
119: service.addPort(validPortQName, null, null);
120: Dispatch<String> dispatch = service.createDispatch(
121: validPortQName, String.class, null);
122: assertNotNull(dispatch);
123:
124: BindingProvider bindingProvider = (BindingProvider) dispatch;
125: ServiceDelegate serviceDelegate = bindingProvider
126: .getServiceDelegate();
127: assertNotNull(serviceDelegate);
128: EndpointDescription endpointDesc = bindingProvider
129: .getEndpointDescription();
130: assertNotNull(endpointDesc);
131: AxisService axisService = endpointDesc.getAxisService();
132: assertNotNull(axisService);
133: // The endpoint address should be null since it wasn't specified on the addPort
134: String endpointAddress = endpointDesc.getEndpointAddress();
135: assertNull(endpointAddress);
136:
137: QName validPortQName2 = new QName(namespaceURI,
138: "EchoPortAdded2");
139: final String port2EndpointAddress = "http://testAddress:8080/my/test/address";
140: service.addPort(validPortQName2, null, port2EndpointAddress);
141: dispatch = service.createDispatch(validPortQName2,
142: String.class, null);
143: assertNotNull(dispatch);
144: bindingProvider = (BindingProvider) dispatch;
145: endpointDesc = bindingProvider.getEndpointDescription();
146: assertNotNull(endpointDesc);
147: // The endpoint address should be as set on the addPort above.
148: endpointAddress = endpointDesc.getEndpointAddress();
149: assertEquals(port2EndpointAddress, endpointAddress);
150: }
151:
152: public void testForProxyNoWSDL() {
153: String namespaceURI = "http://ws.apache.org/axis2/tests";
154: String localPart = "EchoService";
155:
156: Service service = Service.create(null, new QName(namespaceURI,
157: localPart));
158: assertNotNull(service);
159:
160: QName validPortQName = new QName(namespaceURI, "EchoPort");
161: EchoPort echoPort = service.getPort(validPortQName,
162: EchoPort.class);
163: assertNotNull(echoPort);
164:
165: BindingProvider bindingProvider = (BindingProvider) Proxy
166: .getInvocationHandler(echoPort);
167: ServiceDelegate serviceDelegate = bindingProvider
168: .getServiceDelegate();
169: assertNotNull(serviceDelegate);
170: EndpointDescription endpointDesc = bindingProvider
171: .getEndpointDescription();
172: assertNotNull(endpointDesc);
173: AxisService axisService = endpointDesc.getAxisService();
174: assertNotNull(axisService);
175: // The endpoint address should be null since there was no WSDL and it hasn't been set yet
176: String endpointAddress = endpointDesc.getEndpointAddress();
177: assertNull(endpointAddress);
178: }
179:
180: public void testForDispatchNoWSDL() {
181: String namespaceURI = "http://ws.apache.org/axis2/tests";
182: String localPart = "EchoService";
183:
184: Service service = Service.create(null, new QName(namespaceURI,
185: localPart));
186: assertNotNull(service);
187:
188: QName validPortQName = new QName(namespaceURI, "EchoPort");
189: EchoPort echoPort = service.getPort(validPortQName,
190: EchoPort.class);
191: Dispatch<String> dispatch = service.createDispatch(
192: validPortQName, String.class, null);
193: assertNotNull(dispatch);
194:
195: BindingProvider bindingProvider = (BindingProvider) dispatch;
196: ServiceDelegate serviceDelegate = bindingProvider
197: .getServiceDelegate();
198: assertNotNull(serviceDelegate);
199: EndpointDescription endpointDesc = bindingProvider
200: .getEndpointDescription();
201: assertNotNull(endpointDesc);
202: AxisService axisService = endpointDesc.getAxisService();
203: assertNotNull(axisService);
204: }
205:
206: public void testForAddPortNoWSDL() {
207: String namespaceURI = "http://ws.apache.org/axis2/tests";
208: String localPart = "EchoService";
209:
210: Service service = Service.create(null, new QName(namespaceURI,
211: localPart));
212: assertNotNull(service);
213:
214: QName validPortQName = new QName(namespaceURI, "EchoPortAdded");
215: service.addPort(validPortQName, null, null);
216: Dispatch<String> dispatch = service.createDispatch(
217: validPortQName, String.class, null);
218: assertNotNull(dispatch);
219:
220: BindingProvider bindingProvider = (BindingProvider) dispatch;
221: ServiceDelegate serviceDelegate = bindingProvider
222: .getServiceDelegate();
223: assertNotNull(serviceDelegate);
224: EndpointDescription endpointDesc = bindingProvider
225: .getEndpointDescription();
226: assertNotNull(endpointDesc);
227: AxisService axisService = endpointDesc.getAxisService();
228: assertNotNull(axisService);
229: }
230: }
|