2 * Copyright (c) 2015 Cisco 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
8 package org.opendaylight.openflowplugin.impl.connection.listener;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.Mockito.when;
16 import com.google.common.util.concurrent.Futures;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mock;
21 import org.mockito.junit.MockitoJUnitRunner;
22 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
23 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
24 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
25 import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
26 import org.opendaylight.openflowplugin.api.openflow.md.core.HandshakeManager;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder;
29 import org.opendaylight.yangtools.yang.common.Uint32;
32 * Test for {@link OpenflowProtocolListenerInitialImpl}.
34 @RunWith(MockitoJUnitRunner.class)
35 public class OpenflowProtocolListenerInitialImplTest {
37 private ConnectionContext connectionContext;
39 private HandshakeContext handshakeContext;
41 private ConnectionAdapter connectionAdapter;
43 private HandshakeManager handshakeManager;
45 private OpenflowProtocolListenerInitialImpl openflowProtocolListenerInitial;
49 when(connectionAdapter.isAlive()).thenReturn(true);
50 when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
51 when(connectionContext.getConnectionState())
52 .thenReturn(null, ConnectionContext.CONNECTION_STATE.HANDSHAKING);
53 when(handshakeContext.getHandshakeManager()).thenReturn(handshakeManager);
55 openflowProtocolListenerInitial = new OpenflowProtocolListenerInitialImpl(connectionContext, handshakeContext);
59 public void testOnEchoRequestMessage() {
60 when(connectionAdapter.echoReply(any())).thenReturn(Futures.immediateFuture(null));
62 openflowProtocolListenerInitial.onEchoRequestMessage(
63 new EchoRequestMessageBuilder()
64 .setXid(Uint32.valueOf(42))
65 .setVersion(EncodeConstants.OF_VERSION_1_3)
68 verify(connectionAdapter).echoReply(any());
72 public void testOnHelloMessage() {
73 HelloMessageBuilder helloMessageBld = new HelloMessageBuilder()
74 .setXid(Uint32.valueOf(42))
75 .setVersion(EncodeConstants.OF_VERSION_1_3);
76 openflowProtocolListenerInitial.onHelloMessage(helloMessageBld.build());
78 verify(handshakeManager).shake(any());
82 public void testCheckState() {
83 assertFalse(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));
84 assertTrue(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));