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.handler;
019:
020: import javax.xml.ws.Binding;
021: import javax.xml.ws.handler.Handler;
022: import javax.xml.ws.handler.MessageContext;
023:
024: import org.apache.cxf.message.AbstractWrappedMessage;
025: import org.apache.cxf.message.Exchange;
026: import org.apache.cxf.message.Message;
027: import org.easymock.classextension.IMocksControl;
028: import org.junit.After;
029: import org.junit.Assert;
030: import org.junit.Before;
031: import org.junit.Test;
032:
033: import static org.easymock.EasyMock.eq;
034: import static org.easymock.EasyMock.expect;
035: import static org.easymock.EasyMock.isA;
036: import static org.easymock.classextension.EasyMock.createNiceControl;
037:
038: public class AbstractProtocolHandlerInterceptorTest extends Assert {
039:
040: private IMocksControl control;
041: private Binding binding;
042: private HandlerChainInvoker invoker;
043: private IIOPMessage message;
044: private Exchange exchange;
045:
046: @Before
047: public void setUp() {
048: control = createNiceControl();
049: invoker = control.createMock(HandlerChainInvoker.class);
050: message = control.createMock(IIOPMessage.class);
051: exchange = control.createMock(Exchange.class);
052:
053: }
054:
055: @After
056: public void tearDown() {
057: control.verify();
058: }
059:
060: @Test
061: public void testInterceptSuccess() {
062: expect(message.getExchange()).andReturn(exchange).anyTimes();
063: expect(exchange.get(HandlerChainInvoker.class)).andReturn(
064: invoker).anyTimes();
065: expect(
066: invoker.invokeProtocolHandlers(eq(false),
067: isA(MessageContext.class))).andReturn(true);
068: expect(exchange.getOutMessage()).andReturn(message);
069: control.replay();
070: IIOPHandlerInterceptor pi = new IIOPHandlerInterceptor(binding);
071: assertEquals("unexpected phase", "user-protocol", pi.getPhase());
072: pi.handleMessage(message);
073: }
074:
075: @Test
076: public void testInterceptFailure() {
077: expect(message.getExchange()).andReturn(exchange).anyTimes();
078: expect(exchange.get(HandlerChainInvoker.class)).andReturn(
079: invoker).anyTimes();
080: expect(exchange.getOutMessage()).andReturn(message);
081: expect(
082: invoker.invokeProtocolHandlers(eq(false),
083: isA(MessageContext.class))).andReturn(false);
084: control.replay();
085: IIOPHandlerInterceptor pi = new IIOPHandlerInterceptor(binding);
086: pi.handleMessage(message);
087: }
088:
089: class IIOPMessage extends AbstractWrappedMessage {
090: public IIOPMessage(Message m) {
091: super (m);
092: }
093: }
094:
095: interface IIOPMessageContext extends MessageContext {
096:
097: }
098:
099: interface IIOPHandler<T extends IIOPMessageContext> extends
100: Handler<IIOPMessageContext> {
101:
102: }
103:
104: class IIOPHandlerInterceptor extends
105: AbstractProtocolHandlerInterceptor<IIOPMessage> {
106: IIOPHandlerInterceptor(Binding binding) {
107: super(binding);
108: }
109: }
110:
111: }
|