2 * Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.protocol.impl.core;
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;
16 import java.util.concurrent.TimeUnit;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
29 public class IdleHandlerTest {
31 @Mock ChannelHandlerContext mockChHndlrCtx ;
33 IdleHandler idleHandler ;
36 * Sets up test environment
41 MockitoAnnotations.initMocks(this);
42 idleHandler = new IdleHandler(60L, TimeUnit.MINUTES ) ;
46 * Test message passing on channel read
49 public void testChannelRead() {
51 idleHandler.channelRead(mockChHndlrCtx, new Object() );
52 } catch (Exception e) {
56 // Verify that a read was fired for the next handler ...
57 verify(mockChHndlrCtx, times(1)).fireChannelRead(any(SwitchIdleEvent.class)) ;
61 * Test channel read timeout
64 public void testReadTimedOut() {
66 idleHandler.readTimedOut( mockChHndlrCtx );
67 } catch (Exception e) {
71 // Verify a read was fired for the next handler to process ...
72 verify(mockChHndlrCtx, times(1)).fireChannelRead(any(SwitchIdleEvent.class)) ;
76 * Test only one timeout notification
79 public void testReadTimedOutNoOpNotFirst() {
81 idleHandler.readTimedOut(mockChHndlrCtx);
82 idleHandler.readTimedOut(mockChHndlrCtx);
83 } catch (Exception e) {
87 // Verify that only one notification was sent to the next handler ...
88 verify(mockChHndlrCtx, times(1)).fireChannelRead(any(Object.class)) ;
92 * Test two timeout notifications
95 public void testReadTimedOutTwice() {
97 idleHandler.readTimedOut(mockChHndlrCtx);
98 verify(mockChHndlrCtx, times(1)).fireChannelRead(any(Object.class)) ;
100 idleHandler.channelRead(mockChHndlrCtx, new String() );
101 verify(mockChHndlrCtx, times(2)).fireChannelRead(any(Object.class)) ;
103 idleHandler.readTimedOut(mockChHndlrCtx);
104 verify(mockChHndlrCtx, times(3)).fireChannelRead(any(Object.class)) ;
105 } catch (Exception e) {