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.EchoRequestMessageBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder;
28 * Test for {@link OpenflowProtocolListenerInitialImpl}.
30 @RunWith(MockitoJUnitRunner.class)
31 public class OpenflowProtocolListenerInitialImplTest {
34 private ConnectionContext connectionContext;
36 private HandshakeContext handshakeContext;
38 private ConnectionAdapter connectionAdapter;
40 private HandshakeManager handshakeManager;
42 private OpenflowProtocolListenerInitialImpl openflowProtocolListenerInitial;
46 Mockito.when(connectionAdapter.isAlive()).thenReturn(true);
47 Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
48 Mockito.when(connectionContext.getConnectionState())
49 .thenReturn(null, ConnectionContext.CONNECTION_STATE.HANDSHAKING);
50 Mockito.when(handshakeContext.getHandshakeManager()).thenReturn(handshakeManager);
52 openflowProtocolListenerInitial = new OpenflowProtocolListenerInitialImpl(connectionContext, handshakeContext);
56 public void testOnEchoRequestMessage() {
57 EchoRequestMessageBuilder echoRequestMessageBld = new EchoRequestMessageBuilder()
59 .setVersion(OFConstants.OFP_VERSION_1_3);
60 openflowProtocolListenerInitial.onEchoRequestMessage(echoRequestMessageBld.build());
62 Mockito.verify(connectionAdapter).echoReply(ArgumentMatchers.any());
66 public void testOnHelloMessage() {
67 HelloMessageBuilder helloMessageBld = new HelloMessageBuilder()
69 .setVersion(OFConstants.OFP_VERSION_1_3);
70 openflowProtocolListenerInitial.onHelloMessage(helloMessageBld.build());
72 Mockito.verify(handshakeManager).shake(ArgumentMatchers.any());
76 public void testCheckState() {
77 Assert.assertFalse(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));
78 Assert.assertTrue(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));