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.proxy;
020:
021: import java.io.File;
022: import java.net.URL;
023: import java.util.concurrent.Future;
024:
025: import javax.xml.namespace.QName;
026: import javax.xml.ws.AsyncHandler;
027: import javax.xml.ws.BindingProvider;
028: import javax.xml.ws.Service;
029:
030: import junit.framework.TestCase;
031: import org.apache.axis2.jaxws.proxy.doclitnonwrapped.sei.DocLitnonWrappedProxy;
032: import org.apache.axis2.jaxws.proxy.doclitnonwrapped.sei.ProxyDocLitUnwrappedService;
033: import org.apache.axis2.jaxws.TestLogger;
034: import org.test.proxy.doclitnonwrapped.Invoke;
035: import org.test.proxy.doclitnonwrapped.ObjectFactory;
036: import org.test.proxy.doclitnonwrapped.ReturnType;
037:
038: /**
039: * This test cases will use proxy NON wrapped wsdl to invoke methods
040: * on a deployed Server Endpoint.
041: */
042: public class ProxyNonWrappedTests extends TestCase {
043:
044: QName serviceName = new QName(
045: "http://doclitnonwrapped.proxy.test.org",
046: "ProxyDocLitUnwrappedService");
047: private String axisEndpoint = "http://localhost:8080/axis2/services/ProxyDocLitUnwrappedService";
048: private QName portName = new QName(
049: "http://org.apache.axis2.proxy.doclitwrapped",
050: "ProxyDocLitWrappedPort");
051: private String wsdlLocation = System.getProperty("basedir", ".")
052: + "/" + "test-resources/wsdl/ProxyDocLitnonWrapped.wsdl";
053:
054: public ProxyNonWrappedTests() {
055: super ();
056: // TODO Auto-generated constructor stub
057: }
058:
059: /**
060: * @param arg0
061: */
062: public ProxyNonWrappedTests(String arg0) {
063: super (arg0);
064: // TODO Auto-generated constructor stub
065: }
066:
067: public void testInvoke() {
068: TestLogger.logger.debug("-----------------------------------");
069: TestLogger.logger.debug("test: " + getName());
070: TestLogger.logger
071: .debug(">>Testing Sync Inovoke on Proxy DocLit non-wrapped");
072: ObjectFactory factory = new ObjectFactory();
073: Invoke invokeObj = factory.createInvoke();
074: invokeObj.setInvokeStr("test request for twoWay Operation");
075: Service service = Service.create(null, serviceName);
076: assertNotNull(service);
077: DocLitnonWrappedProxy proxy = service.getPort(portName,
078: DocLitnonWrappedProxy.class);
079: assertNotNull(proxy);
080: BindingProvider p = (BindingProvider) proxy;
081: p.getRequestContext()
082: .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
083: axisEndpoint);
084: ReturnType response = proxy.invoke(invokeObj);
085: assertNotNull(response);
086: TestLogger.logger.debug(">>Response ="
087: + response.getReturnStr());
088:
089: TestLogger.logger
090: .debug("-------------------------------------");
091: }
092:
093: public void testNullInvoke() {
094: TestLogger.logger.debug("-----------------------------------");
095: TestLogger.logger.debug("test: " + getName());
096: TestLogger.logger
097: .debug(">>Testing Sync Invoke on Proxy DocLit bare with a null parameter");
098: ObjectFactory factory = new ObjectFactory();
099: Invoke invokeObj = null;
100: Service service = Service.create(null, serviceName);
101: assertNotNull(service);
102: DocLitnonWrappedProxy proxy = service.getPort(portName,
103: DocLitnonWrappedProxy.class);
104: assertNotNull(proxy);
105: BindingProvider p = (BindingProvider) proxy;
106: p.getRequestContext()
107: .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
108: axisEndpoint);
109: ReturnType response = proxy.invoke(invokeObj);
110: assertNull(response);
111:
112: TestLogger.logger
113: .debug("-------------------------------------");
114: }
115:
116: public void testInvokeAsyncCallback() {
117: try {
118: TestLogger.logger
119: .debug("---------------------------------------");
120: TestLogger.logger.debug("DocLitNonWrapped test case: "
121: + getName());
122: //Create wsdl url
123: File wsdl = new File(wsdlLocation);
124: URL wsdlUrl = wsdl.toURL();
125: ObjectFactory factory = new ObjectFactory();
126: //create input object to web service operation
127: Invoke invokeObj = factory.createInvoke();
128: invokeObj
129: .setInvokeStr("test request for twoWay Async Operation");
130: //Create Service
131: ProxyDocLitUnwrappedService service = new ProxyDocLitUnwrappedService(
132: wsdlUrl, serviceName);
133: //Create proxy
134: DocLitnonWrappedProxy proxy = service
135: .getProxyDocLitnonWrappedPort();
136: TestLogger.logger
137: .debug(">>Invoking Binding Provider property");
138: //Setup Endpoint url -- optional.
139: BindingProvider p = (BindingProvider) proxy;
140: p.getRequestContext().put(
141: BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
142: axisEndpoint);
143: TestLogger.logger
144: .debug(">> Invoking Proxy Asynchronous Callback");
145: AsyncHandler<ReturnType> handler = new AsyncCallback();
146: //Invoke operation Asynchronously.
147: Future<?> monitor = proxy.invokeAsync(invokeObj, handler);
148: while (!monitor.isDone()) {
149: Thread.sleep(1000);
150: }
151: TestLogger.logger
152: .debug("---------------------------------------");
153: } catch (Exception e) {
154: e.printStackTrace();
155: fail("Exception received" + e);
156: }
157: }
158:
159: public void testInvokeAsyncPolling() {
160:
161: }
162:
163: }
|