001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package docStyle;
059:
060: import http.net.pointwsp.www.ws.finance.ArrayOfCurrency;
061: import http.net.pointwsp.www.ws.finance.Currency;
062: import http.net.pointwsp.www.ws.finance.Currencyrates;
063: import java.io.StringReader;
064: import java.io.StringWriter;
065:
066: import junit.framework.Test;
067: import junit.framework.TestCase;
068: import junit.framework.TestSuite;
069:
070: import org.apache.wsif.WSIFConstants;
071: import org.apache.wsif.WSIFMessage;
072: import org.apache.wsif.WSIFOperation;
073: import org.apache.wsif.WSIFPort;
074: import org.apache.wsif.WSIFService;
075: import org.apache.wsif.WSIFServiceFactory;
076: import org.apache.xerces.parsers.DOMParser;
077: import org.apache.xml.serialize.OutputFormat;
078: import org.apache.xml.serialize.XMLSerializer;
079: import org.w3c.dom.Element;
080: import org.xml.sax.InputSource;
081: import util.TestUtilities;
082:
083: import docStyle.wsifservice.PwspNoCentrbankCurRatesSoap;
084:
085: /**
086: * Junit test to test out the AXIS provider docstyle support.
087: * Uses the norwegian central bank daily rates service
088: * (this has no input parts and returns complex types)
089: */
090: public class NWBankTest extends TestCase {
091: String wsdlLocation = TestUtilities
092: .getWsdlPath("java\\test\\docStyle\\wsifservice")
093: + "nwBank.wsdl";
094:
095: // + "nwBankLocal.wsdl";
096:
097: public NWBankTest(String name) {
098: super (name);
099: }
100:
101: public static void main(String[] args) {
102: TestUtilities.startListeners(TestUtilities.ADDRESSBOOK_LISTENER
103: | TestUtilities.ASYNC_LISTENER
104: | TestUtilities.NATIVEJMS_LISTENER);
105: junit.textui.TestRunner.run(suite());
106: TestUtilities.stopListeners();
107: }
108:
109: public static Test suite() {
110: return new TestSuite(NWBankTest.class);
111: }
112:
113: public void setUp() {
114: TestUtilities.setUpExtensionsAndProviders();
115: }
116:
117: public void testDynamicAxis() {
118: doitDyn("pwspNoCentrbankCurRatesSoap", "axis");
119: }
120:
121: public void testStubsAxis() {
122: doitStub("pwspNoCentrbankCurRatesSoap", "axis");
123: }
124:
125: public void testMessagingAxis() {
126: doitMessaging("pwspNoCentrbankCurRatesSoap", "axis");
127: }
128:
129: public void testDynJMS() {
130: doitDyn("pwspNoCentrbankCurRatesSoapJMS", "axis");
131: }
132:
133: public void testStubsAxisJMS() {
134: doitStub("pwspNoCentrbankCurRatesSoapJMS", "axis");
135: }
136:
137: private void doitDyn(String portName, String protocol) {
138: if (portName.toUpperCase().indexOf("JMS") != -1
139: && !TestUtilities.areWeTesting("jms"))
140: return;
141:
142: TestUtilities.setProviderForProtocol(protocol);
143:
144: try {
145: WSIFServiceFactory factory = WSIFServiceFactory
146: .newInstance();
147: WSIFService service = factory.getService(wsdlLocation,
148: null, null, "http/www.pointwsp.net/ws/finance",
149: "pwspNoCentrbankCurRatesSoap");
150:
151: service.mapType(
152: new javax.xml.namespace.QName(
153: "http/www.pointwsp.net/ws/finance",
154: "currencyrates"), Currencyrates.class);
155:
156: service.mapType(new javax.xml.namespace.QName(
157: "http/www.pointwsp.net/ws/finance",
158: "ArrayOfCurrency"), ArrayOfCurrency.class);
159:
160: service.mapType(new javax.xml.namespace.QName(
161: "http/www.pointwsp.net/ws/finance", "currency"),
162: Currency.class);
163:
164: // force to use a 'wrapped' type operation
165: WSIFMessage context = service.getContext();
166: context.setObjectPart(
167: WSIFConstants.CONTEXT_OPERATION_STYLE,
168: WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED);
169: service.setContext(context);
170:
171: WSIFPort port = service.getPort(portName);
172:
173: WSIFOperation operation = port
174: .createOperation("GetRatesXML");
175:
176: WSIFMessage inMsg = operation.createInputMessage();
177: WSIFMessage outMsg = operation.createOutputMessage();
178: WSIFMessage faultMsg = operation.createFaultMessage();
179:
180: boolean ok = operation.executeRequestResponseOperation(
181: inMsg, outMsg, faultMsg);
182:
183: assertTrue("operation returned false!!", ok);
184: Object o = outMsg.getObjectPart("GetRatesXMLResult");
185: assertTrue("unexpected result: " + o,
186: o instanceof Currencyrates);
187:
188: // Currencyrates cr = (Currencyrates) o;
189: // System.out.println("source=" + cr.getSource());
190:
191: } catch (Exception ex) {
192: ex.printStackTrace();
193: assertTrue("AddressBookTest(" + portName
194: + ") caught exception " + ex.getLocalizedMessage(),
195: false);
196: }
197: }
198:
199: private void doitStub(String portName, String protocol) {
200: if (portName.toUpperCase().indexOf("JMS") != -1
201: && !TestUtilities.areWeTesting("jms"))
202: return;
203:
204: TestUtilities.setProviderForProtocol(protocol);
205:
206: try {
207: WSIFServiceFactory factory = WSIFServiceFactory
208: .newInstance();
209: WSIFService service = factory.getService(wsdlLocation,
210: null, null, "http/www.pointwsp.net/ws/finance",
211: "pwspNoCentrbankCurRatesSoap");
212:
213: // force to use a 'wrapped' type operation
214: WSIFMessage context = service.getContext();
215: context.setObjectPart(
216: WSIFConstants.CONTEXT_OPERATION_STYLE,
217: WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED);
218: service.setContext(context);
219:
220: PwspNoCentrbankCurRatesSoap stub = (PwspNoCentrbankCurRatesSoap) service
221: .getStub(portName,
222: PwspNoCentrbankCurRatesSoap.class);
223:
224: Object o = stub.GetRatesXML();
225: assertTrue("unexpected result: " + o,
226: o instanceof Currencyrates);
227: // Currencyrates cr = (Currencyrates) o;
228: // System.out.println("source=" + cr.getSource());
229:
230: } catch (Exception ex) {
231: ex.printStackTrace();
232: assertTrue("AddressBookTest(" + portName
233: + ") caught exception " + ex.getLocalizedMessage(),
234: false);
235: }
236: }
237:
238: private void doitMessaging(String portName, String protocol) {
239: if (portName.toUpperCase().indexOf("JMS") != -1
240: && !TestUtilities.areWeTesting("jms"))
241: return;
242:
243: TestUtilities.setProviderForProtocol(protocol);
244:
245: try {
246: WSIFServiceFactory factory = WSIFServiceFactory
247: .newInstance();
248: WSIFService service = factory.getService(wsdlLocation,
249: null, null, "http/www.pointwsp.net/ws/finance",
250: "pwspNoCentrbankCurRatesSoap");
251:
252: service.mapType(
253: new javax.xml.namespace.QName(
254: "http/www.pointwsp.net/ws/finance",
255: "currencyrates"), Currencyrates.class);
256:
257: service.mapType(new javax.xml.namespace.QName(
258: "http/www.pointwsp.net/ws/finance",
259: "ArrayOfCurrency"), ArrayOfCurrency.class);
260:
261: service.mapType(new javax.xml.namespace.QName(
262: "http/www.pointwsp.net/ws/finance", "currency"),
263: Currency.class);
264:
265: WSIFPort port = service.getPort(portName);
266:
267: WSIFOperation operation = port
268: .createOperation("GetRatesXML");
269:
270: WSIFMessage inMsg = operation.createInputMessage();
271: WSIFMessage outMsg = operation.createOutputMessage();
272: WSIFMessage faultMsg = operation.createFaultMessage();
273:
274: String inputDocument = "<GetRatesXML xmlns=\"http/www.pointwsp.net/ws/finance\"/>";
275:
276: DOMParser parser = new DOMParser();
277: String xmlString = "<?xml version=\"1.0\"?>\n"
278: + inputDocument;
279: parser.parse(new InputSource(new StringReader(xmlString)));
280: Element element = parser.getDocument().getDocumentElement();
281: //printElement(element);
282:
283: inMsg.setObjectPart("parameters", element);
284:
285: boolean ok = operation.executeRequestResponseOperation(
286: inMsg, outMsg, faultMsg);
287:
288: assertTrue("operation returned false!!", ok);
289:
290: Element responseElement = (Element) outMsg
291: .getObjectPart("parameters");
292: //printElement(responseElement);
293: assertTrue("return element is null!!",
294: responseElement != null);
295:
296: } catch (Exception ex) {
297: ex.printStackTrace();
298: assertTrue("AddressBookTest(" + portName
299: + ") caught exception " + ex.getLocalizedMessage(),
300: false);
301: }
302: }
303:
304: private void printElement(Element e) throws Exception {
305: OutputFormat of = new OutputFormat(e.getOwnerDocument(),
306: "UTF-8", true);
307: XMLSerializer xmls = new XMLSerializer(of);
308: StringWriter sw = new StringWriter();
309: xmls.setOutputCharStream(sw);
310: xmls.serialize(e);
311: System.err.println("element=" + sw.toString());
312: }
313: }
|