alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Apache CXF example source code file (AbstractProtocolHandlerInterceptorTest.java)

This example Apache CXF source code file (AbstractProtocolHandlerInterceptorTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Apache CXF tags/keywords

abstractwrappedmessage, after, arraylist, iiophandlerinterceptor, iiophandlerinterceptor, iiopmessage, iiopmessage, iiopmessagecontext, iiopmessagecontext, imockscontrol, list, messagecontext, test, test, util, xml

The Apache CXF AbstractProtocolHandlerInterceptorTest.java source code

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.cxf.jaxws.handler;

import java.util.ArrayList;
import java.util.List;

import javax.xml.ws.Binding;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.handler.MessageContext;

import org.apache.cxf.message.AbstractWrappedMessage;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
import org.easymock.classextension.IMocksControl;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.isA;
import static org.easymock.classextension.EasyMock.createNiceControl;

public class AbstractProtocolHandlerInterceptorTest extends Assert {
    
    private IMocksControl control;
    private Binding binding;
    private HandlerChainInvoker invoker;
    private IIOPMessage message;
    private Exchange exchange;
    
    @Before
    public void setUp() {
        control = createNiceControl();
        invoker = control.createMock(HandlerChainInvoker.class);
        message = control.createMock(IIOPMessage.class);
        exchange = control.createMock(Exchange.class);
        binding = control.createMock(Binding.class);
        
        List<Handler> list = new ArrayList();
        list.add(null);
        expect(binding.getHandlerChain()).andReturn(list).anyTimes();
    }
    
    @After
    public void tearDown() {
        control.verify();
    }

    @Test
    public void testInterceptSuccess() {
        expect(message.getExchange()).andReturn(exchange).anyTimes();
        expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
        expect(invoker.invokeProtocolHandlers(eq(false),
                        isA(MessageContext.class))).andReturn(true);
        expect(exchange.getOutMessage()).andReturn(message);
        control.replay();
        IIOPHandlerInterceptor pi = new IIOPHandlerInterceptor(binding);
        assertEquals("unexpected phase", "user-protocol", pi.getPhase());
        pi.handleMessage(message);
    }

    @Test
    public void testInterceptFailure() {
        expect(message.getExchange()).andReturn(exchange).anyTimes();
        expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
        expect(exchange.getOutMessage()).andReturn(message);
        expect(
                invoker.invokeProtocolHandlers(eq(false),
                        isA(MessageContext.class))).andReturn(false);
        control.replay();
        IIOPHandlerInterceptor pi = new IIOPHandlerInterceptor(binding);
        pi.handleMessage(message);
    }

    class IIOPMessage extends AbstractWrappedMessage {
        public IIOPMessage(Message m) {
            super(m);
        }
    }
    
    interface IIOPMessageContext extends MessageContext {
        
    }
     
    interface IIOPHandler<T extends IIOPMessageContext> extends Handler {
        
    }
    
    class IIOPHandlerInterceptor extends AbstractProtocolHandlerInterceptor<IIOPMessage> {
        IIOPHandlerInterceptor(Binding binding) {
            super(binding);
        }
    }
    
    
}

Other Apache CXF examples (source code examples)

Here is a short list of links related to this Apache CXF AbstractProtocolHandlerInterceptorTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.