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.util.Collection;
021:
022: import javax.wsdl.Definition;
023: import javax.xml.namespace.QName;
024:
025: import org.apache.cxf.Bus;
026: import org.apache.cxf.frontend.ServerFactoryBean;
027: import org.apache.cxf.jaxws.service.Hello2;
028: import org.apache.cxf.jaxws.service.Hello3;
029: import org.apache.cxf.jaxws.support.JaxWsImplementorInfo;
030: import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
031: import org.apache.cxf.service.Service;
032: import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
033: import org.apache.cxf.service.model.BindingInfo;
034: import org.apache.cxf.service.model.InterfaceInfo;
035: import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
036: import org.junit.Test;
037:
038: public class CodeFirstWSDLTest extends AbstractJaxWsTest {
039: String address = "local://localhost:9000/Hello";
040:
041: private Definition createService(Class clazz) throws Exception {
042:
043: JaxWsImplementorInfo info = new JaxWsImplementorInfo(clazz);
044: ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean(
045: info);
046:
047: Bus bus = getBus();
048: bean.setBus(bus);
049:
050: Service service = bean.create();
051:
052: InterfaceInfo i = service.getServiceInfos().get(0)
053: .getInterface();
054: assertEquals(4, i.getOperations().size());
055:
056: ServerFactoryBean svrFactory = new ServerFactoryBean();
057: svrFactory.setBus(bus);
058: svrFactory.setServiceFactory(bean);
059: svrFactory.setAddress(address);
060: svrFactory.create();
061:
062: Collection<BindingInfo> bindings = service.getServiceInfos()
063: .get(0).getBindings();
064: assertEquals(1, bindings.size());
065:
066: ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(bus,
067: service.getServiceInfos().get(0));
068: return wsdlBuilder.build();
069: }
070:
071: @Test
072: public void testWSDL1() throws Exception {
073: Definition d = createService(Hello2.class);
074:
075: QName serviceName = new QName(
076: "http://service.jaxws.cxf.apache.org/", "Hello2Service");
077:
078: javax.wsdl.Service service = d.getService(serviceName);
079:
080: assertNotNull(service);
081:
082: QName portName = new QName(
083: "http://service.jaxws.cxf.apache.org/", "Hello2Port");
084:
085: javax.wsdl.Port port = service.getPort(portName.getLocalPart());
086:
087: assertNotNull(port);
088:
089: QName portTypeName = new QName(
090: "http://service.jaxws.cxf.apache.org/",
091: "HelloInterface");
092:
093: javax.wsdl.PortType portType = d.getPortType(portTypeName);
094:
095: assertNotNull(portType);
096: assertEquals(4, portType.getOperations().size());
097: }
098:
099: @Test
100: public void testWSDL2() throws Exception {
101: Definition d = createService(Hello3.class);
102:
103: QName serviceName = new QName("http://mynamespace.com/",
104: "MyService");
105:
106: javax.wsdl.Service service = d.getService(serviceName);
107:
108: assertNotNull(service);
109:
110: QName portName = new QName("http://mynamespace.com/", "MyPort");
111:
112: javax.wsdl.Port port = service.getPort(portName.getLocalPart());
113:
114: assertNotNull(port);
115:
116: QName portTypeName = new QName(
117: "http://service.jaxws.cxf.apache.org/",
118: "HelloInterface");
119:
120: javax.wsdl.PortType portType = d.getPortType(portTypeName);
121:
122: assertNotNull(portType);
123: assertEquals(4, portType.getOperations().size());
124: }
125:
126: }
|