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.HashMap;
021: import java.util.Map;
022: import javax.wsdl.Definition;
023: import javax.wsdl.xml.WSDLWriter;
024: import javax.xml.xpath.XPathConstants;
025:
026: import org.w3c.dom.Document;
027:
028: import org.apache.cxf.Bus;
029: import org.apache.cxf.calculator.CalculatorPortType;
030: import org.apache.cxf.endpoint.Endpoint;
031: import org.apache.cxf.endpoint.Server;
032: import org.apache.cxf.frontend.ServerFactoryBean;
033: import org.apache.cxf.helpers.XPathUtils;
034: import org.apache.cxf.jaxb.JAXBDataBinding;
035: import org.apache.cxf.jaxws.javaee.DescriptionType;
036: import org.apache.cxf.jaxws.javaee.DisplayNameType;
037: import org.apache.cxf.jaxws.service.Hello;
038: import org.apache.cxf.service.model.ServiceInfo;
039: import org.apache.cxf.wsdl.WSDLManager;
040: import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
041: import org.apache.hello_world_doc_lit.GreeterImplDoc;
042: import org.junit.Test;
043:
044: public class JaxWsServerFactoryBeanTest extends AbstractJaxWsTest {
045:
046: @Test
047: public void testBean() {
048: JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
049: sf.setBus(getBus());
050: sf.setAddress("http://localhost:9000/test");
051: sf.setServiceClass(Hello.class);
052: sf.setStart(false);
053:
054: Server server = sf.create();
055: assertNotNull(server);
056: }
057:
058: @SuppressWarnings("unchecked")
059: @Test
060: public void testJaxbExtraClass() {
061: JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
062: sf.setBus(getBus());
063: sf.setAddress("http://localhost:9000/test");
064: sf.setServiceClass(Hello.class);
065: sf.setStart(false);
066: Map props = sf.getProperties();
067: if (props == null) {
068: props = new HashMap<String, Object>();
069: }
070: props.put("jaxb.additionalContextClasses", new Class[] {
071: DescriptionType.class, DisplayNameType.class });
072: sf.setProperties(props);
073: Server server = sf.create();
074: assertNotNull(server);
075: Class[] extraClass = ((JAXBDataBinding) sf.getServiceFactory()
076: .getDataBinding()).getExtraClass();
077: assertEquals(extraClass.length, 2);
078: assertEquals(extraClass[0], DescriptionType.class);
079: assertEquals(extraClass[1], DisplayNameType.class);
080: }
081:
082: @Test
083: public void testBareGreeter() throws Exception {
084: JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
085: sf.setBus(getBus());
086: sf.setServiceClass(GreeterImplDoc.class);
087: sf.setStart(false);
088:
089: Server server = sf.create();
090: assertNotNull(server);
091: }
092:
093: @Test
094: public void testSimpleServiceClass() throws Exception {
095: ServerFactoryBean factory = new ServerFactoryBean();
096: factory.setServiceClass(Hello.class);
097: String address = "http://localhost:9001/jaxwstest";
098: factory.setAddress(address);
099: Server server = factory.create();
100: Endpoint endpoint = server.getEndpoint();
101: ServiceInfo service = endpoint.getEndpointInfo().getService();
102: assertNotNull(service);
103:
104: Bus bus = factory.getBus();
105: Definition def = new ServiceWSDLBuilder(bus, service).build();
106:
107: WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class)
108: .getWSDLFactory().newWSDLWriter();
109: def.setExtensionRegistry(bus.getExtension(WSDLManager.class)
110: .getExtenstionRegistry());
111: Document doc = wsdlWriter.getDocument(def);
112:
113: Map<String, String> ns = new HashMap<String, String>();
114: ns.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
115: ns.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
116: XPathUtils xpather = new XPathUtils(ns);
117: xpather.isExist("/wsdl:definitions/wsdl:binding/soap:binding",
118: doc, XPathConstants.NODE);
119: xpather
120: .isExist(
121: "/wsdl:definitions/wsdl:binding/wsdl:operation[@name='add']/soap:operation",
122: doc, XPathConstants.NODE);
123: xpather
124: .isExist(
125: "/wsdl:definitions/wsdl:service/wsdl:port[@name='add']/soap:address[@location='"
126: + address + "']", doc,
127: XPathConstants.NODE);
128: }
129:
130: @Test
131: public void testJaxwsServiceClass() throws Exception {
132: JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
133: factory.setServiceClass(CalculatorPortType.class);
134: String address = "http://localhost:9001/jaxwstest";
135: factory.setAddress(address);
136: Server server = factory.create();
137: Endpoint endpoint = server.getEndpoint();
138: ServiceInfo service = endpoint.getEndpointInfo().getService();
139: assertNotNull(service);
140:
141: Bus bus = factory.getBus();
142: Definition def = new ServiceWSDLBuilder(bus, service).build();
143:
144: WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class)
145: .getWSDLFactory().newWSDLWriter();
146: def.setExtensionRegistry(bus.getExtension(WSDLManager.class)
147: .getExtenstionRegistry());
148: Document doc = wsdlWriter.getDocument(def);
149:
150: Map<String, String> ns = new HashMap<String, String>();
151: ns.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
152: ns.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
153: XPathUtils xpather = new XPathUtils(ns);
154: xpather.isExist("/wsdl:definitions/wsdl:binding/soap:binding",
155: doc, XPathConstants.NODE);
156: xpather
157: .isExist(
158: "/wsdl:definitions/wsdl:binding/wsdl:operation[@name='add']/soap:operation",
159: doc, XPathConstants.NODE);
160: xpather
161: .isExist(
162: "/wsdl:definitions/wsdl:service/wsdl:port[@name='add']/soap:address[@location='"
163: + address + "']", doc,
164: XPathConstants.NODE);
165: }
166: }
|