01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.jaxws.client;
20:
21: import java.util.Map;
22:
23: import javax.xml.bind.JAXBContext;
24: import javax.xml.bind.JAXBElement;
25: import javax.xml.namespace.QName;
26: import javax.xml.ws.Dispatch;
27: import javax.xml.ws.Service.Mode;
28:
29: import junit.framework.TestCase;
30: import org.apache.axis2.jaxws.BindingProvider;
31: import org.apache.axis2.jaxws.TestLogger;
32: import org.apache.axis2.jaxws.client.soapaction.BookStoreService;
33: import org.apache.axis2.jaxws.client.soapaction.GetPriceResponseType;
34: import org.apache.axis2.jaxws.client.soapaction.GetPriceType;
35: import org.apache.axis2.jaxws.client.soapaction.ObjectFactory;
36:
37: /**
38: * A suite of SOAPAction related tests for the dispatch client
39: */
40: public class DispatchSoapActionTests extends TestCase {
41:
42: private static final String targetNamespace = "http://jaxws.axis2.apache.org/client/soapaction";
43: private static final String portName = "BookStorePort";
44:
45: /**
46: * Invoke an operation this is defined in the WSDL as having a SOAPAction.
47: * Since this is a Dispatch client, we'll need to specify that SOAPAction
48: * ourselves for the invoke.
49: */
50: public void testSendRequestWithSoapAction() throws Exception {
51: TestLogger.logger.debug("----------------------------------");
52: TestLogger.logger.debug("test: " + getName());
53:
54: BookStoreService service = new BookStoreService();
55:
56: JAXBContext ctx = JAXBContext
57: .newInstance("org.apache.axis2.jaxws.client.soapaction");
58: Dispatch dispatch = service.createDispatch(new QName(
59: targetNamespace, portName), ctx, Mode.PAYLOAD);
60:
61: Map<String, Object> requestCtx = dispatch.getRequestContext();
62: requestCtx.put(BindingProvider.SOAPACTION_USE_PROPERTY,
63: Boolean.TRUE);
64: requestCtx
65: .put(BindingProvider.SOAPACTION_URI_PROPERTY,
66: "http://jaxws.axis2.apache.org/client/soapaction/getPrice");
67:
68: ObjectFactory of = new ObjectFactory();
69: GetPriceType gpt = of.createGetPriceType();
70: gpt.setItem("TEST");
71:
72: // The element that is sent should be <getPriceWithAction>
73: // so it will resolve to the getPriceWithAction operation
74: // defined in the WSDL.
75: JAXBElement<GetPriceType> getPrice = of
76: .createGetPriceWithAction(gpt);
77: JAXBElement<GetPriceResponseType> getPriceResponse = (JAXBElement<GetPriceResponseType>) dispatch
78: .invoke(getPrice);
79:
80: GetPriceResponseType value = getPriceResponse.getValue();
81: assertNotNull("The response was null", value);
82:
83: float price = value.getPrice();
84: TestLogger.logger.debug("return value [" + price + "]");
85: //assertTrue("The return value was invalid", price > 0);
86: }
87:
88: }
|