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.holder;
019:
020: import javax.xml.ws.Holder;
021:
022: import org.w3c.dom.Node;
023:
024: import org.apache.cxf.Bus;
025: import org.apache.cxf.BusException;
026: import org.apache.cxf.bus.CXFBusFactory;
027: import org.apache.cxf.jaxws.AbstractJaxWsTest;
028: import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
029: import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
030: import org.apache.cxf.jaxws.MessageReplayObserver;
031: import org.apache.cxf.service.model.EndpointInfo;
032: import org.apache.cxf.transport.Destination;
033: import org.apache.cxf.transport.local.LocalTransportFactory;
034: import org.junit.Test;
035:
036: public class HolderTest extends AbstractJaxWsTest {
037: private final String address = "http://localhost:9000/HolderService";
038:
039: @Override
040: protected Bus createBus() throws BusException {
041: return new CXFBusFactory().createBus();
042: }
043:
044: @Test
045: public void testClient() throws Exception {
046: EndpointInfo ei = new EndpointInfo(null,
047: "http://schemas.xmlsoap.org/soap/http");
048: ei.setAddress(address);
049:
050: Destination d = localTransport.getDestination(ei);
051: d.setMessageObserver(new MessageReplayObserver(
052: "/org/apache/cxf/jaxws/holder/echoResponse.xml"));
053:
054: JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
055: factory.getClientFactoryBean().setServiceClass(
056: HolderService.class);
057: factory.getClientFactoryBean().setBus(getBus());
058: factory.getClientFactoryBean().setAddress(address);
059:
060: HolderService h = (HolderService) factory.create();
061: Holder<String> holder = new Holder<String>();
062: assertEquals("one", h.echo("one", "two", holder));
063: assertEquals("two", holder.value);
064: }
065:
066: @Test
067: public void testServer() throws Exception {
068: JaxWsServerFactoryBean svr = new JaxWsServerFactoryBean();
069: svr.setBus(getBus());
070: svr.setServiceBean(new HolderServiceImpl());
071: svr.setAddress(address);
072: svr.create();
073:
074: addNamespace("h", "http://holder.jaxws.cxf.apache.org/");
075: Node response;
076:
077: response = invoke(address, LocalTransportFactory.TRANSPORT_ID,
078: "echo.xml");
079:
080: assertNotNull(response);
081: assertValid("//h:echoResponse/return[text()='one']", response);
082: assertValid("//h:echoResponse/return1[text()='two']", response);
083: assertNoFault(response);
084:
085: response = invoke(address, LocalTransportFactory.TRANSPORT_ID,
086: "echo2.xml");
087:
088: assertNotNull(response);
089: assertNoFault(response);
090: assertValid("//h:echo2Response/return[text()='one']", response);
091: assertValid("//h:echo2Response/return1[text()='two']", response);
092:
093: // test holder with in/out header
094: response = invoke(address, LocalTransportFactory.TRANSPORT_ID,
095: "echo3.xml");
096:
097: assertNotNull(response);
098: assertNoFault(response);
099: assertValid("//h:echo3Response/return[text()='one']", response);
100: assertValid("//s:Header/h:header[text()='header']", response);
101:
102: }
103:
104: }
|