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: */package org.apache.cxf.jaxws;
019:
020: import java.net.URL;
021: import java.util.List;
022:
023: import javax.xml.namespace.QName;
024:
025: import org.apache.cxf.calculator.CalculatorImpl;
026: import org.apache.cxf.endpoint.Endpoint;
027: import org.apache.cxf.endpoint.EndpointException;
028: import org.apache.cxf.endpoint.EndpointImpl;
029: import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
030: import org.apache.cxf.message.Exchange;
031: import org.apache.cxf.message.ExchangeImpl;
032: import org.apache.cxf.message.Message;
033: import org.apache.cxf.message.MessageImpl;
034: import org.apache.cxf.service.Service;
035: import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
036: import org.apache.cxf.service.model.BindingOperationInfo;
037: import org.apache.cxf.service.model.EndpointInfo;
038: import org.apache.cxf.service.model.ServiceModelUtil;
039: import org.apache.hello_world_soap_http.GreeterImpl;
040: import org.apache.hello_world_soap_http.RPCLitGreeterImpl;
041: import org.junit.Before;
042: import org.junit.Test;
043:
044: public class ServiceModelUtilsTest extends AbstractJaxWsTest {
045:
046: Message message;
047: Exchange exchange;
048: ReflectionServiceFactoryBean bean;
049:
050: @Before
051: public void setUp() throws Exception {
052: super .setUpBus();
053:
054: message = new MessageImpl();
055: exchange = new ExchangeImpl();
056: message.setExchange(exchange);
057:
058: bean = new JaxWsServiceFactoryBean();
059: bean.setBus(getBus());
060: }
061:
062: private Service getService(URL wsdl, Class implClz, QName port)
063: throws EndpointException {
064: assertNotNull(wsdl);
065: bean.setWsdlURL(wsdl.toString());
066: bean.setServiceClass(implClz);
067: Service service = bean.create();
068: EndpointInfo endpointInfo = service.getServiceInfos().get(0)
069: .getEndpoint(port);
070: Endpoint endpoint = new EndpointImpl(getBus(), service,
071: endpointInfo);
072: exchange.put(Service.class, service);
073: exchange.put(Endpoint.class, endpoint);
074: return service;
075: }
076:
077: @Test
078: public void testGetOperationInputPartNamesWrapped()
079: throws Exception {
080: getService(getClass().getResource("/wsdl/hello_world.wsdl"),
081: GreeterImpl.class, new QName(
082: "http://apache.org/hello_world_soap_http",
083: "SoapPort"));
084:
085: BindingOperationInfo operation = ServiceModelUtil.getOperation(
086: message.getExchange(), "greetMe");
087: assertNotNull(operation);
088: List<String> names = ServiceModelUtil
089: .getOperationInputPartNames(operation
090: .getOperationInfo());
091: assertNotNull(names);
092: assertEquals(1, names.size());
093: assertEquals("requestType", names.get(0));
094:
095: operation = ServiceModelUtil.getOperation(
096: message.getExchange(), "sayHi");
097: assertNotNull(operation);
098: names = ServiceModelUtil.getOperationInputPartNames(operation
099: .getOperationInfo());
100: assertNotNull(names);
101: assertEquals(0, names.size());
102: }
103:
104: @Test
105: public void testGetOperationInputPartNamesWrapped2()
106: throws Exception {
107: getService(getClass().getResource("/wsdl/calculator.wsdl"),
108: CalculatorImpl.class, new QName(
109: "http://apache.org/cxf/calculator",
110: "CalculatorPort"));
111:
112: BindingOperationInfo operation = ServiceModelUtil.getOperation(
113: message.getExchange(), "add");
114: assertNotNull(operation);
115: List<String> names = ServiceModelUtil
116: .getOperationInputPartNames(operation
117: .getOperationInfo());
118: assertNotNull(names);
119: assertEquals(2, names.size());
120: assertEquals("arg0", names.get(0));
121: assertEquals("arg1", names.get(1));
122: }
123:
124: @Test
125: public void testGetOperationInputPartNamesBare() throws Exception {
126: getService(getClass().getResource(
127: "/wsdl/hello_world_xml_bare.wsdl"),
128: org.apache.hello_world_xml_http.bare.GreeterImpl.class,
129: new QName(
130: "http://apache.org/hello_world_xml_http/bare",
131: "XMLPort"));
132: BindingOperationInfo operation = ServiceModelUtil.getOperation(
133: message.getExchange(), "greetMe");
134: assertNotNull(operation);
135: List<String> names = ServiceModelUtil
136: .getOperationInputPartNames(operation
137: .getOperationInfo());
138: assertNotNull(names);
139: assertEquals(1, names.size());
140: assertEquals("requestType", names.get(0));
141:
142: operation = ServiceModelUtil.getOperation(
143: message.getExchange(), "sayHi");
144: assertNotNull(operation);
145: names = ServiceModelUtil.getOperationInputPartNames(operation
146: .getOperationInfo());
147: assertNotNull(names);
148: assertEquals(0, names.size());
149: }
150:
151: @Test
152: public void testGetOperationInputPartNamesRpc() throws Exception {
153: getService(getClass().getResource(
154: "/wsdl/hello_world_rpc_lit.wsdl"),
155: RPCLitGreeterImpl.class, new QName(
156: "http://apache.org/hello_world_rpclit",
157: "SoapPortRPCLit"));
158: BindingOperationInfo operation = ServiceModelUtil.getOperation(
159: message.getExchange(), "greetMe");
160: assertNotNull(operation);
161: List<String> names = ServiceModelUtil
162: .getOperationInputPartNames(operation
163: .getOperationInfo());
164: assertNotNull(names);
165: assertEquals(1, names.size());
166: assertEquals("in", names.get(0));
167:
168: operation = ServiceModelUtil.getOperation(
169: message.getExchange(), "sayHi");
170: assertNotNull(operation);
171: names = ServiceModelUtil.getOperationInputPartNames(operation
172: .getOperationInfo());
173: assertNotNull(names);
174: assertEquals(0, names.size());
175:
176: operation = ServiceModelUtil.getOperation(
177: message.getExchange(), "greetUs");
178: assertNotNull(operation);
179: names = ServiceModelUtil.getOperationInputPartNames(operation
180: .getOperationInfo());
181: assertNotNull(names);
182: assertEquals(2, names.size());
183: //System.err.println(names);
184: }
185: }
|