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.interceptor;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: import org.apache.cxf.Bus;
024: import org.apache.cxf.binding.Binding;
025: import org.apache.cxf.endpoint.Endpoint;
026: import org.apache.cxf.message.Exchange;
027: import org.apache.cxf.message.ExchangeImpl;
028: import org.apache.cxf.message.MessageImpl;
029: import org.apache.cxf.phase.Phase;
030: import org.apache.cxf.phase.PhaseManager;
031: import org.apache.cxf.phase.PhaseManagerImpl;
032: import org.apache.cxf.service.Service;
033: import org.apache.cxf.service.model.BindingMessageInfo;
034: import org.apache.cxf.service.model.BindingOperationInfo;
035: import org.apache.cxf.service.model.MessageInfo;
036: import org.apache.cxf.service.model.OperationInfo;
037: import org.easymock.IMocksControl;
038: import org.easymock.classextension.EasyMock;
039: import org.junit.After;
040: import org.junit.Assert;
041: import org.junit.Before;
042: import org.junit.Test;
043:
044: public class OutgoingChainInterceptorTest extends Assert {
045:
046: private IMocksControl control;
047: private Bus bus;
048: private Service service;
049: private Endpoint endpoint;
050: private BindingOperationInfo bopInfo;
051: private OperationInfo opInfo;
052: private BindingMessageInfo bmInfo;
053: private MessageInfo mInfo;
054: private List<Phase> phases;
055: private List<Interceptor> empty;
056: private Binding binding;
057:
058: @Before
059: public void setUp() throws Exception {
060:
061: control = EasyMock.createNiceControl();
062:
063: phases = new ArrayList<Phase>();
064: phases.add(new Phase(Phase.SEND, 1000));
065: empty = new ArrayList<Interceptor>();
066:
067: bus = control.createMock(Bus.class);
068: PhaseManager pm = new PhaseManagerImpl();
069: EasyMock.expect(bus.getExtension(PhaseManager.class))
070: .andReturn(pm).anyTimes();
071:
072: service = control.createMock(Service.class);
073: endpoint = control.createMock(Endpoint.class);
074: binding = control.createMock(Binding.class);
075: EasyMock.expect(endpoint.getBinding()).andStubReturn(binding);
076: MessageImpl m = new MessageImpl();
077: EasyMock.expect(binding.createMessage()).andStubReturn(m);
078:
079: EasyMock.expect(endpoint.getService()).andReturn(service)
080: .anyTimes();
081: EasyMock.expect(endpoint.getOutInterceptors()).andReturn(empty);
082: EasyMock.expect(service.getOutInterceptors()).andReturn(empty);
083: EasyMock.expect(bus.getOutInterceptors()).andReturn(empty);
084:
085: bopInfo = control.createMock(BindingOperationInfo.class);
086: opInfo = control.createMock(OperationInfo.class);
087: mInfo = control.createMock(MessageInfo.class);
088: bmInfo = control.createMock(BindingMessageInfo.class);
089: EasyMock.expect(bopInfo.getOperationInfo()).andReturn(opInfo)
090: .times(3);
091: EasyMock.expect(opInfo.getOutput()).andReturn(mInfo);
092: EasyMock.expect(opInfo.isOneWay()).andReturn(false);
093: EasyMock.expect(bopInfo.getOutput()).andReturn(bmInfo);
094:
095: control.replay();
096:
097: }
098:
099: @After
100: public void tearDown() {
101: control.verify();
102: }
103:
104: @Test
105: public void testInterceptor() throws Exception {
106: OutgoingChainInterceptor intc = new OutgoingChainInterceptor();
107:
108: MessageImpl m = new MessageImpl();
109: Exchange exchange = new ExchangeImpl();
110: m.setExchange(exchange);
111: exchange.put(Bus.class, bus);
112: exchange.put(Endpoint.class, endpoint);
113: exchange.put(Binding.class, binding);
114: exchange.put(BindingOperationInfo.class, bopInfo);
115: exchange.setOutMessage(m);
116: intc.handleMessage(m);
117: }
118:
119: }
|