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 org.apache.axis2.jaxws.provider.DataSourceImpl;
022: import org.apache.axis2.jaxws.proxy.rpclitswa.sei.RPCLitSWA;
023:
024: import javax.activation.DataHandler;
025: import javax.activation.DataSource;
026: import javax.imageio.ImageIO;
027: import javax.imageio.stream.FileImageInputStream;
028: import javax.imageio.stream.ImageInputStream;
029: import javax.xml.namespace.QName;
030: import javax.xml.ws.BindingProvider;
031: import javax.xml.ws.Dispatch;
032: import javax.xml.ws.Holder;
033: import javax.xml.ws.Service;
034:
035: import java.awt.Image;
036: import java.io.File;
037: import java.net.MalformedURLException;
038: import java.net.URL;
039:
040: import junit.framework.TestCase;
041:
042: public class RPCLitSWAProxyTests extends TestCase {
043:
044: private QName serviceName = new QName(
045: "http://org/apache/axis2/jaxws/proxy/rpclitswa",
046: "RPCLitSWAService");
047: private String axisEndpoint = "http://localhost:8080/axis2/services/RPCLitSWAService";
048: private QName portName = new QName(
049: "http://org/apache/axis2/jaxws/proxy/rpclitswa",
050: "RPCLitSWA");
051: private String wsdlLocation = System.getProperty("basedir", ".")
052: + "/"
053: + "test/org/apache/axis2/jaxws/proxy/rpclitswa/META-INF/RPCLitSWA.wsdl";
054:
055: private DataSource imageDS;
056:
057: public void setUp() throws Exception {
058: String imageResourceDir = System.getProperty("basedir", ".")
059: + "/" + "test-resources" + File.separator + "image";
060:
061: //Create a DataSource from an image
062: File file = new File(imageResourceDir + File.separator
063: + "test.jpg");
064: ImageInputStream fiis = new FileImageInputStream(file);
065: Image image = ImageIO.read(fiis);
066: imageDS = new DataSourceImpl("image/jpeg", "test.jpg", image);
067: }
068:
069: /**
070: * Utility method to get the proxy
071: * @return RPCLit proxy
072: * @throws MalformedURLException
073: */
074: public RPCLitSWA getProxy() throws MalformedURLException {
075: File wsdl = new File(wsdlLocation);
076: assertTrue("WSDL does not exist:" + wsdlLocation, wsdl.exists());
077: URL wsdlUrl = wsdl.toURL();
078: Service service = Service.create(wsdlUrl, serviceName);
079: Object proxy = service.getPort(portName, RPCLitSWA.class);
080: BindingProvider p = (BindingProvider) proxy;
081: p.getRequestContext()
082: .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
083: axisEndpoint);
084:
085: return (RPCLitSWA) proxy;
086: }
087:
088: /**
089: * Utility Method to get a Dispatch<String>
090: * @return
091: * @throws MalformedURLException
092: */
093: public Dispatch<String> getDispatch() throws MalformedURLException {
094: File wsdl = new File(wsdlLocation);
095: URL wsdlUrl = wsdl.toURL();
096: Service service = Service.create(null, serviceName);
097: service.addPort(portName, null, axisEndpoint);
098: Dispatch<String> dispatch = service.createDispatch(portName,
099: String.class, Service.Mode.PAYLOAD);
100: return dispatch;
101: }
102:
103: public void testNOOP() {
104:
105: }
106:
107: /**
108: * Simple test that ensures that we can echo a string to an rpc/lit web service
109: * NOTE:
110: * To enable this test, remove the _.
111: * Once you do this, you can add the following code to OperationDescriptionImpl.
112: * buildAttachmentInformation()
113: * // TODO: Start HACK for RPCLitSWAProxyTest
114: addPartAttachmentDescription("dummyAttachmentIN",
115: new AttachmentDescriptionImpl(AttachmentType.SWA,
116: new String[] {"text/plain"}));
117: addPartAttachmentDescription("dummyAttachmentINOUT",
118: new AttachmentDescriptionImpl(AttachmentType.SWA,
119: new String[] {"image/jpeg"}));
120: addPartAttachmentDescription("dummyAttachmentOUT",
121: new AttachmentDescriptionImpl(AttachmentType.SWA,
122: new String[] {"text/plain"}));
123: // TODO: End HACK for RPCListSWAProxyTest
124: */
125: public void testRPCLitSWAEcho() throws Exception {
126:
127: RPCLitSWA proxy = getProxy();
128: String request = "This is a not attachment data";
129:
130: String attachmentIN = "Data for plain text attachment";
131: DataHandler attachmentINOUT = getImageDH();
132:
133: Holder<DataHandler> attachmentINOUT_Holder = new Holder<DataHandler>();
134: attachmentINOUT_Holder.value = attachmentINOUT;
135: Holder<String> response_Holder = new Holder<String>();
136: Holder<String> attachmentOUT_Holder = new Holder<String>();
137:
138: proxy.echo(request, attachmentIN, attachmentINOUT_Holder,
139: response_Holder, attachmentOUT_Holder);
140:
141: assertTrue("Bad Response Holder", response_Holder != null);
142: assertTrue("Response value is null",
143: response_Holder.value != null);
144: assertTrue("Response is not the same as request. Receive="
145: + response_Holder.value, request
146: .equals(response_Holder.value));
147:
148: assertTrue("The output attachment holder is null",
149: attachmentOUT_Holder != null);
150: assertTrue("The output attachment is null",
151: attachmentOUT_Holder.value != null);
152: assertTrue(
153: "The output attachment is not the same as the input. Received="
154: + attachmentOUT_Holder.value, attachmentIN
155: .equals(attachmentOUT_Holder.value));
156:
157: assertTrue("The inout attachment holder is null",
158: attachmentINOUT_Holder != null);
159: assertTrue("The inout attachment is null",
160: attachmentINOUT_Holder.value != null);
161: // Ensure that this is not the same object
162: assertTrue(attachmentINOUT_Holder.value != attachmentINOUT);
163:
164: }
165:
166: private DataHandler getImageDH() {
167: return new DataHandler(imageDS);
168: }
169:
170: }
|