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.binding.soap;
019:
020: import java.util.Arrays;
021: import java.util.List;
022:
023: import javax.xml.namespace.QName;
024: import javax.xml.stream.XMLInputFactory;
025: import javax.xml.stream.XMLStreamReader;
026:
027: import org.apache.cxf.binding.soap.interceptor.RPCInInterceptor;
028: import org.apache.cxf.jaxb.JAXBDataBinding;
029: import org.apache.cxf.message.Message;
030: import org.apache.cxf.service.Service;
031: import org.apache.cxf.service.model.BindingInfo;
032: import org.apache.cxf.service.model.BindingOperationInfo;
033: import org.apache.cxf.service.model.ServiceInfo;
034: import org.apache.hello_world_rpclit.types.MyComplexStruct;
035: import org.easymock.classextension.EasyMock;
036: import org.easymock.classextension.IMocksControl;
037: import org.junit.Before;
038: import org.junit.Test;
039:
040: public class RPCInInterceptorTest extends TestBase {
041:
042: private static final String TNS = "http://apache.org/hello_world_rpclit";
043:
044: private static final String OPNAME = "sendReceiveData";
045:
046: private IMocksControl control = EasyMock.createNiceControl();
047:
048: @Before
049: public void setUp() throws Exception {
050: super .setUp();
051: ServiceInfo si = getMockedServiceModel(this .getClass()
052: .getResource("/wsdl/hello_world_rpc_lit.wsdl")
053: .toString());
054: BindingInfo bi = si.getBinding(new QName(TNS,
055: "Greeter_SOAPBinding_RPCLit"));
056: BindingOperationInfo boi = bi.getOperation(new QName(TNS,
057: OPNAME));
058: boi.getOperationInfo().getInput().getMessagePartByIndex(0)
059: .setTypeClass(MyComplexStruct.class);
060: boi.getOperationInfo().getInput().getMessagePartByIndex(0)
061: .setIndex(1);
062: boi.getOperationInfo().getOutput().getMessagePartByIndex(0)
063: .setTypeClass(MyComplexStruct.class);
064: boi.getOperationInfo().getOutput().getMessagePartByIndex(0)
065: .setIndex(0);
066: soapMessage.getExchange().put(BindingOperationInfo.class, boi);
067:
068: control.reset();
069: Service service = control.createMock(Service.class);
070: JAXBDataBinding dataBinding = new JAXBDataBinding(
071: MyComplexStruct.class);
072: service.getDataBinding();
073: EasyMock.expectLastCall().andReturn(dataBinding).anyTimes();
074: service.getServiceInfos();
075: List<ServiceInfo> list = Arrays.asList(si);
076: EasyMock.expectLastCall().andReturn(list).anyTimes();
077:
078: soapMessage.getExchange().put(Service.class, service);
079: soapMessage.getExchange().put(
080: Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE);
081: control.replay();
082: }
083:
084: @Test
085: public void testInterceptorRPCLitOutbound() throws Exception {
086: RPCInInterceptor interceptor = new RPCInInterceptor();
087:
088: soapMessage.setContent(XMLStreamReader.class, XMLInputFactory
089: .newInstance().createXMLStreamReader(
090: getTestStream(getClass(), "/rpc-resp.xml")));
091: soapMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
092:
093: interceptor.handleMessage(soapMessage);
094:
095: List<?> parameters = (List<?>) soapMessage
096: .getContent(List.class);
097: assertEquals(1, parameters.size());
098:
099: Object obj = parameters.get(0);
100: assertTrue(obj instanceof MyComplexStruct);
101: MyComplexStruct s = (MyComplexStruct) obj;
102: assertEquals("elem1", s.getElem1());
103: assertEquals("elem2", s.getElem2());
104: assertEquals(45, s.getElem3());
105: }
106:
107: @Test
108: public void testInterceptorRPCLitInbound() throws Exception {
109: RPCInInterceptor interceptor = new RPCInInterceptor();
110: soapMessage.setContent(XMLStreamReader.class, XMLInputFactory
111: .newInstance().createXMLStreamReader(
112: getTestStream(getClass(), "/rpc-req.xml")));
113:
114: interceptor.handleMessage(soapMessage);
115:
116: List<?> parameters = (List<?>) soapMessage
117: .getContent(List.class);
118: assertEquals(2, parameters.size());
119:
120: Object obj = parameters.get(1);
121: assertTrue(obj instanceof MyComplexStruct);
122: MyComplexStruct s = (MyComplexStruct) obj;
123: assertEquals("elem1", s.getElem1());
124: assertEquals("elem2", s.getElem2());
125: assertEquals(45, s.getElem3());
126: }
127:
128: }
|