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
9 package org.opendaylight.openflowplugin.impl.connection.listener;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.mockito.ArgumentMatchers;
16 import org.mockito.Mock;
17 import org.mockito.Mockito;
18 import org.mockito.runners.MockitoJUnitRunner;
19 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
20 import org.opendaylight.openflowplugin.api.OFConstants;
21 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
22 import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
23 import org.opendaylight.openflowplugin.api.openflow.md.core.HandshakeManager;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder;
30 * Test for {@link OpenflowProtocolListenerInitialImpl}.
32 @RunWith(MockitoJUnitRunner.class)
33 public class OpenflowProtocolListenerInitialImplTest {
36 private ConnectionContext connectionContext;
38 private HandshakeContext handshakeContext;
40 private ConnectionAdapter connectionAdapter;
42 private HandshakeManager handshakeManager;
44 private OpenflowProtocolListenerInitialImpl openflowProtocolListenerInitial;
47 public void setUp() throws Exception {
48 Mockito.when(connectionAdapter.isAlive()).thenReturn(true);
49 Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
50 Mockito.when(connectionContext.getConnectionState())
51 .thenReturn(null, ConnectionContext.CONNECTION_STATE.HANDSHAKING);
52 Mockito.when(handshakeContext.getHandshakeManager()).thenReturn(handshakeManager);
54 openflowProtocolListenerInitial = new OpenflowProtocolListenerInitialImpl(connectionContext, handshakeContext);
58 public void testOnEchoRequestMessage() throws Exception {
59 EchoRequestMessageBuilder echoRequestMessageBld = new EchoRequestMessageBuilder()
61 .setVersion(OFConstants.OFP_VERSION_1_3);
62 openflowProtocolListenerInitial.onEchoRequestMessage(echoRequestMessageBld.build());
64 Mockito.verify(connectionAdapter).echoReply(ArgumentMatchers.<EchoReplyInput>any());
68 public void testOnHelloMessage() throws Exception {
69 HelloMessageBuilder helloMessageBld = new HelloMessageBuilder()
71 .setVersion(OFConstants.OFP_VERSION_1_3);
72 openflowProtocolListenerInitial.onHelloMessage(helloMessageBld.build());
74 Mockito.verify(handshakeManager).shake(ArgumentMatchers.<HelloMessage>any());
78 public void testCheckState() throws Exception {
79 Assert.assertFalse(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));
80 Assert.assertTrue(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));