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.support;
019:
020: import java.net.URL;
021: import java.util.Collection;
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import javax.wsdl.Definition;
026: import javax.wsdl.factory.WSDLFactory;
027: import javax.xml.namespace.QName;
028:
029: import org.w3c.dom.Document;
030: import org.w3c.dom.NodeList;
031:
032: import org.apache.cxf.Bus;
033: import org.apache.cxf.jaxws.AbstractJaxWsTest;
034: import org.apache.cxf.mtom_xop.TestMtomImpl;
035: import org.apache.cxf.service.Service;
036: import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
037: import org.apache.cxf.service.invoker.BeanInvoker;
038: import org.apache.cxf.service.model.FaultInfo;
039: import org.apache.cxf.service.model.InterfaceInfo;
040: import org.apache.cxf.service.model.MessagePartInfo;
041: import org.apache.cxf.service.model.OperationInfo;
042: import org.apache.cxf.service.model.SchemaInfo;
043: import org.apache.cxf.service.model.ServiceInfo;
044: import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
045: import org.apache.hello_world_soap_http.GreeterImpl;
046: import org.junit.Test;
047:
048: public class JaxWsServiceFactoryBeanTest extends AbstractJaxWsTest {
049:
050: @Test
051: public void testEndpoint() throws Exception {
052: ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
053:
054: URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
055: assertNotNull(resource);
056: bean.setWsdlURL(resource.toString());
057: Bus bus = getBus();
058: bean.setBus(bus);
059: bean.setServiceClass(GreeterImpl.class);
060:
061: BeanInvoker invoker = new BeanInvoker(new GreeterImpl());
062: bean.setInvoker(invoker);
063:
064: Service service = bean.create();
065:
066: String ns = "http://apache.org/hello_world_soap_http";
067: assertEquals("SOAPService", service.getName().getLocalPart());
068: assertEquals(ns, service.getName().getNamespaceURI());
069:
070: InterfaceInfo intf = service.getServiceInfos().get(0)
071: .getInterface();
072:
073: OperationInfo op = intf.getOperation(new QName(ns, "sayHi"));
074:
075: Class wrapper = (Class) op.getInput().getMessageParts().get(0)
076: .getTypeClass();
077: assertNotNull(wrapper);
078:
079: wrapper = (Class) op.getOutput().getMessageParts().get(0)
080: .getTypeClass();
081: assertNotNull(wrapper);
082:
083: assertEquals(invoker, service.getInvoker());
084:
085: op = intf.getOperation(new QName(ns, "testDocLitFault"));
086: Collection<FaultInfo> faults = op.getFaults();
087: assertEquals(2, faults.size());
088:
089: FaultInfo f = op.getFault(new QName(ns, "BadRecordLitFault"));
090: assertNotNull(f);
091: Class c = f.getProperty(Class.class.getName(), Class.class);
092: assertNotNull(c);
093:
094: assertEquals(1, f.getMessageParts().size());
095: MessagePartInfo mpi = f.getMessagePartByIndex(0);
096: assertNotNull(mpi.getTypeClass());
097: }
098:
099: @Test
100: public void testHolder() throws Exception {
101: ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
102:
103: Bus bus = getBus();
104: bean.setBus(bus);
105: bean.setServiceClass(TestMtomImpl.class);
106:
107: Service service = bean.create();
108: InterfaceInfo intf = service.getServiceInfos().get(0)
109: .getInterface();
110:
111: OperationInfo op = intf.getOperation(new QName(
112: "http://cxf.apache.org/mime", "testXop"));
113: assertNotNull(op);
114:
115: Iterator<MessagePartInfo> itr = op.getInput().getMessageParts()
116: .iterator();
117: assertTrue(itr.hasNext());
118: MessagePartInfo part = itr.next();
119: assertEquals("testXop", part.getElementQName().getLocalPart());
120:
121: op = op.getUnwrappedOperation();
122: assertNotNull(op);
123:
124: // test setup of input parts
125: itr = op.getInput().getMessageParts().iterator();
126: assertTrue(itr.hasNext());
127: part = itr.next();
128: assertEquals("name", part.getName().getLocalPart());
129: assertEquals(String.class, part.getTypeClass());
130:
131: /*
132: * revisit, try to use other wsdl operation rewrite test in future
133: assertTrue(itr.hasNext());
134: part = itr.next();
135: assertEquals(Boolean.TRUE, part.getProperty(JaxWsServiceFactoryBean.MODE_INOUT));
136: assertEquals(byte[].class, part.getTypeClass());
137:
138: assertFalse(itr.hasNext());
139:
140: // test output setup
141: itr = op.getOutput().getMessageParts().iterator();
142:
143: assertTrue(itr.hasNext());
144: part = itr.next();
145: assertEquals(Boolean.TRUE, part.getProperty(JaxWsServiceFactoryBean.MODE_INOUT));
146: */
147: }
148:
149: @Test
150: public void testWrappedDocLit() throws Exception {
151: ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
152: Bus bus = getBus();
153: bean.setBus(bus);
154: bean
155: .setServiceClass(org.apache.hello_world_doc_lit.Greeter.class);
156: Service service = bean.create();
157:
158: ServiceInfo si = service.getServiceInfos().get(0);
159: InterfaceInfo intf = si.getInterface();
160:
161: assertEquals(4, intf.getOperations().size());
162:
163: String ns = si.getName().getNamespaceURI();
164: assertEquals("http://apache.org/hello_world_doc_lit", ns);
165: OperationInfo greetMeOp = intf.getOperation(new QName(ns,
166: "greetMe"));
167: assertNotNull(greetMeOp);
168:
169: assertEquals("greetMe", greetMeOp.getInput().getName()
170: .getLocalPart());
171: assertEquals("http://apache.org/hello_world_doc_lit", greetMeOp
172: .getInput().getName().getNamespaceURI());
173:
174: List<MessagePartInfo> messageParts = greetMeOp.getInput()
175: .getMessageParts();
176: assertEquals(1, messageParts.size());
177:
178: MessagePartInfo inMessagePart = messageParts.get(0);
179: assertEquals("http://apache.org/hello_world_doc_lit",
180: inMessagePart.getName().getNamespaceURI());
181: assertEquals("http://apache.org/hello_world_doc_lit/types",
182: inMessagePart.getElementQName().getNamespaceURI());
183:
184: // test output
185: messageParts = greetMeOp.getOutput().getMessageParts();
186: assertEquals(1, messageParts.size());
187: assertEquals("greetMeResponse", greetMeOp.getOutput().getName()
188: .getLocalPart());
189:
190: MessagePartInfo outMessagePart = messageParts.get(0);
191: assertEquals("result", outMessagePart.getName().getLocalPart());
192: assertEquals("http://apache.org/hello_world_doc_lit",
193: outMessagePart.getName().getNamespaceURI());
194: assertEquals("http://apache.org/hello_world_doc_lit/types",
195: outMessagePart.getElementQName().getNamespaceURI());
196:
197: OperationInfo greetMeOneWayOp = si.getInterface().getOperation(
198: new QName(ns, "greetMeOneWay"));
199: assertEquals(1, greetMeOneWayOp.getInput().getMessageParts()
200: .size());
201: assertNull(greetMeOneWayOp.getOutput());
202:
203: Collection<SchemaInfo> schemas = si.getSchemas();
204: assertEquals(1, schemas.size());
205: }
206:
207: @Test
208: public void testBareBug() throws Exception {
209: ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
210: Bus bus = getBus();
211: bean.setBus(bus);
212: bean
213: .setServiceClass(org.apache.cxf.test.TestInterfacePort.class);
214: Service service = bean.create();
215: ServiceInfo si = service.getServiceInfos().get(0);
216: ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, si);
217: Definition def = builder.build();
218:
219: Document wsdl = WSDLFactory.newInstance().newWSDLWriter()
220: .getDocument(def);
221: NodeList nodeList = assertValid(
222: "/wsdl:definitions/wsdl:types/xsd:schema"
223: + "[@targetNamespace='http://cxf.apache.org/"
224: + "org.apache.cxf.test.TestInterface/xsd']"
225: + "/xsd:element[@name='getMessage']", wsdl);
226: assertEquals(1, nodeList.getLength());
227:
228: assertValid(
229: "/wsdl:definitions/wsdl:message[@name='setMessage']"
230: + "/wsdl:part[@name = 'parameters'][@element='ns2:setMessage']",
231: wsdl);
232:
233: assertValid(
234: "/wsdl:definitions/wsdl:message[@name='echoCharResponse']"
235: + "/wsdl:part[@name = 'y'][@element='ns2:charEl_y']",
236: wsdl);
237:
238: assertValid(
239: "/wsdl:definitions/wsdl:message[@name='echoCharResponse']"
240: + "/wsdl:part[@name = 'return'][@element='ns2:charEl_return']",
241: wsdl);
242:
243: assertValid(
244: "/wsdl:definitions/wsdl:message[@name='echoCharResponse']"
245: + "/wsdl:part[@name = 'z'][@element='ns2:charEl_z']",
246: wsdl);
247:
248: assertValid("/wsdl:definitions/wsdl:message[@name='echoChar']"
249: + "/wsdl:part[@name = 'x'][@element='ns2:charEl_x']",
250: wsdl);
251:
252: assertValid("/wsdl:definitions/wsdl:message[@name='echoChar']"
253: + "/wsdl:part[@name = 'y'][@element='ns2:charEl_y']",
254: wsdl);
255:
256: }
257:
258: }
|