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.service.factory;
019:
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import javax.wsdl.extensions.soap.SOAPAddress;
024: import javax.xml.namespace.QName;
025:
026: import org.apache.cxf.binding.soap.model.SoapBindingInfo;
027: import org.apache.cxf.binding.soap.model.SoapOperationInfo;
028: import org.apache.cxf.endpoint.Client;
029: import org.apache.cxf.endpoint.Endpoint;
030: import org.apache.cxf.frontend.ClientFactoryBean;
031: import org.apache.cxf.jaxb.JAXBDataBinding;
032: import org.apache.cxf.service.Service;
033: import org.apache.cxf.service.model.BindingInfo;
034: import org.apache.cxf.service.model.BindingOperationInfo;
035: import org.apache.cxf.service.model.EndpointInfo;
036: import org.apache.hello_world.types.GreetMe;
037: import org.apache.hello_world_soap_http.types.GreetMeOneWay;
038: import org.junit.Test;
039:
040: public class ClientFactoryBeanTest extends AbstractSimpleFrontendTest {
041:
042: @Test
043: public void testClientFactoryBean() throws Exception {
044:
045: ClientFactoryBean cfBean = new ClientFactoryBean();
046: cfBean.setAddress("http://localhost/Hello");
047: cfBean.setBus(getBus());
048: cfBean.setServiceClass(HelloService.class);
049:
050: Client client = cfBean.create();
051: assertNotNull(client);
052:
053: Service service = client.getEndpoint().getService();
054: Map<QName, Endpoint> eps = service.getEndpoints();
055: assertEquals(1, eps.size());
056:
057: Endpoint ep = eps.values().iterator().next();
058: EndpointInfo endpointInfo = ep.getEndpointInfo();
059:
060: SOAPAddress soapAddress = endpointInfo
061: .getExtensor(SOAPAddress.class);
062: assertNotNull(soapAddress);
063:
064: BindingInfo b = endpointInfo.getService().getBindings()
065: .iterator().next();
066:
067: assertTrue(b instanceof SoapBindingInfo);
068:
069: SoapBindingInfo sb = (SoapBindingInfo) b;
070: assertEquals("HelloServiceSoapBinding", b.getName()
071: .getLocalPart());
072: assertEquals("document", sb.getStyle());
073:
074: assertEquals(4, b.getOperations().size());
075:
076: BindingOperationInfo bop = b.getOperations().iterator().next();
077: SoapOperationInfo sop = bop
078: .getExtensor(SoapOperationInfo.class);
079: assertNotNull(sop);
080: assertEquals("", sop.getAction());
081: assertEquals("document", sop.getStyle());
082: }
083:
084: @SuppressWarnings("unchecked")
085: @Test
086: public void testJaxbExtraClass() throws Exception {
087:
088: ClientFactoryBean cfBean = new ClientFactoryBean();
089: cfBean.setAddress("http://localhost/Hello");
090: cfBean.setBus(getBus());
091: cfBean.setServiceClass(HelloService.class);
092: Map props = cfBean.getProperties();
093: if (props == null) {
094: props = new HashMap<String, Object>();
095: }
096: props.put("jaxb.additionalContextClasses", new Class[] {
097: GreetMe.class, GreetMeOneWay.class });
098: cfBean.setProperties(props);
099: Client client = cfBean.create();
100: assertNotNull(client);
101: Class[] extraClass = ((JAXBDataBinding) cfBean
102: .getServiceFactory().getDataBinding()).getExtraClass();
103: assertEquals(extraClass.length, 2);
104: assertEquals(extraClass[0], GreetMe.class);
105: assertEquals(extraClass[1], GreetMeOneWay.class);
106: }
107: }
|