5e365b8633f09ae16d09885a89ca70138ad0ae5f
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / core / DelegatingInboundHandlerTest.java
1 /*
2  * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.core;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.times;
13 import static org.mockito.Mockito.verify;
14 import io.netty.channel.ChannelHandlerContext;
15
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Mock;
19 import org.mockito.MockitoAnnotations;
20 import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer;
21 import org.opendaylight.yangtools.yang.binding.DataObject;
22
23 /**
24  * @author jameshall
25  */
26 public class DelegatingInboundHandlerTest {
27
28     @Mock ChannelHandlerContext mockChHndlrCtx ;
29     @Mock MessageConsumer mockMsgConsumer ;
30     @Mock DataObject mockDataObject ;
31
32     DelegatingInboundHandler dih ;
33
34     /**
35      * Sets up test environment
36      */
37     @Before
38     public void setUp() {
39         MockitoAnnotations.initMocks(this);
40         dih = new DelegatingInboundHandler(mockMsgConsumer) ;
41     }
42
43     /**
44      * 
45      */
46     @Test
47     public void testChannelReadSuccess()   {
48         dih.channelRead(mockChHndlrCtx, mockDataObject) ;
49
50         // Verify that the message buf was released...
51         verify( mockMsgConsumer, times(1)).consume(mockDataObject);
52     }
53     /**
54      * 
55      */
56     @Test
57     public void testChannelInactive()   {
58         dih.channelInactive(mockChHndlrCtx);
59
60         verify( mockMsgConsumer, times(1)).consume(any(DataObject.class));
61     }
62
63     /**
64      * ChannelUnregistered
65      */
66     @Test
67     public void testChannelUnregistered()   {
68         dih.channelUnregistered(mockChHndlrCtx);
69
70         verify( mockMsgConsumer, times(1)).consume(any(DataObject.class));
71     }
72 }