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.io.IOException;
021: import java.util.ArrayList;
022: import java.util.HashMap;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.apache.cxf.endpoint.ServerImpl;
027: import org.apache.cxf.frontend.ServerFactoryBean;
028: import org.apache.cxf.jaxb.JAXBDataBinding;
029: import org.apache.cxf.message.Message;
030: import org.apache.cxf.service.model.EndpointInfo;
031: import org.apache.cxf.transport.AbstractTransportFactory;
032: import org.apache.cxf.transport.Conduit;
033: import org.apache.cxf.transport.Destination;
034: import org.apache.cxf.transport.DestinationFactory;
035: import org.apache.cxf.transport.MessageObserver;
036: import org.apache.cxf.ws.addressing.EndpointReferenceType;
037: import org.apache.hello_world.types.GreetMe;
038: import org.apache.hello_world_soap_http.types.GreetMeOneWay;
039: import org.junit.Test;
040:
041: public class ServerFactoryTest extends AbstractSimpleFrontendTest {
042:
043: @Test
044: public void testSetDF() throws Exception {
045: ServerFactoryBean svrBean = new ServerFactoryBean();
046: svrBean.setAddress("http://localhost/Hello");
047: svrBean.setServiceClass(HelloService.class);
048: svrBean.setBus(getBus());
049: svrBean.setDestinationFactory(new CustomDestinationFactory());
050:
051: ServerImpl server = (ServerImpl) svrBean.create();
052: assertTrue(server.getDestination() instanceof CustomDestination);
053: }
054:
055: @SuppressWarnings("unchecked")
056: @Test
057: public void testJaxbExtraClass() throws Exception {
058: ServerFactoryBean svrBean = new ServerFactoryBean();
059: svrBean.setAddress("http://localhost/Hello");
060: svrBean.setServiceClass(HelloService.class);
061: svrBean.setBus(getBus());
062:
063: Map props = svrBean.getProperties();
064: if (props == null) {
065: props = new HashMap<String, Object>();
066: }
067: props.put("jaxb.additionalContextClasses", new Class[] {
068: GreetMe.class, GreetMeOneWay.class });
069: svrBean.setProperties(props);
070: svrBean.create();
071: Class[] extraClass = ((JAXBDataBinding) svrBean
072: .getServiceFactory().getDataBinding()).getExtraClass();
073: assertEquals(extraClass.length, 2);
074: assertEquals(extraClass[0], GreetMe.class);
075: assertEquals(extraClass[1], GreetMeOneWay.class);
076: }
077:
078: public class CustomDestinationFactory extends
079: AbstractTransportFactory implements DestinationFactory {
080:
081: public Destination getDestination(EndpointInfo ei)
082: throws IOException {
083: return new CustomDestination();
084: }
085:
086: @Override
087: public List<String> getTransportIds() {
088: List<String> ids = new ArrayList<String>();
089: ids.add("id");
090: return ids;
091: }
092:
093: }
094:
095: public static class CustomDestination implements Destination {
096:
097: public EndpointReferenceType getAddress() {
098: // TODO Auto-generated method stub
099: return null;
100: }
101:
102: public Conduit getBackChannel(Message inMessage,
103: Message partialResponse, EndpointReferenceType address)
104: throws IOException {
105: // TODO Auto-generated method stub
106: return null;
107: }
108:
109: public void shutdown() {
110: // TODO Auto-generated method stub
111:
112: }
113:
114: public void setMessageObserver(MessageObserver observer) {
115: // TODO Auto-generated method stub
116:
117: }
118:
119: public MessageObserver getMessageObserver() {
120: // TODO Auto-generated method stub
121: return null;
122: }
123:
124: }
125: }
|