Ditch use of SystemNotificationsListener
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / device / listener / OpenflowProtocolListenerFullImplTest.java
index f203464150a4f3df31e64072422c4fcffb5a39bc..2de02d448ef9364a17c4faca4a33493e5fa4df17 100644 (file)
@@ -1,29 +1,29 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.impl.device.listener;
 
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
 
+import com.google.common.util.concurrent.Futures;
 import java.net.InetSocketAddress;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.ArgumentMatchers;
 import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
-import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder;
@@ -38,40 +38,39 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
 /**
  * openflowplugin-impl
  * org.opendaylight.openflowplugin.impl.connection.listener
  * test of {@link OpenflowProtocolListenerFullImpl} - lightweight version, using basic ways (TDD).
  *
- * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
- *
+ * @author Vaclav Demcak
  */
 @RunWith(MockitoJUnitRunner.class)
 public class OpenflowProtocolListenerFullImplTest {
-
-    private OpenflowProtocolListenerFullImpl ofProtocolListener;
-
     @Mock
     private DeviceReplyProcessor deviceReplyProcessor;
     @Mock
     private ConnectionAdapter connectionAdapter;
 
-    private final long xid = 42L;
+    private final Uint32 xid = Uint32.valueOf(42);
+
+    private OpenflowProtocolListenerFullImpl ofProtocolListener;
 
     @Before
     public void setUp() {
         // place for mocking method's general behavior for HandshakeContext and ConnectionContext
         ofProtocolListener = new OpenflowProtocolListenerFullImpl(connectionAdapter, deviceReplyProcessor);
         connectionAdapter.setMessageListener(ofProtocolListener);
-        Mockito.when(connectionAdapter.getRemoteAddress())
+        when(connectionAdapter.getRemoteAddress())
                 .thenReturn(InetSocketAddress.createUnresolved("ofp-junit.example.org", 6663));
-        Mockito.verify(connectionAdapter).setMessageListener(any(OpenflowProtocolListener.class));
+        verify(connectionAdapter).setMessageListener(any(OpenflowProtocolListener.class));
     }
 
     @After
     public void tearDown() {
-        Mockito.verifyNoMoreInteractions(connectionAdapter, deviceReplyProcessor);
+        verifyNoMoreInteractions(connectionAdapter, deviceReplyProcessor);
     }
 
     /**
@@ -81,11 +80,11 @@ public class OpenflowProtocolListenerFullImplTest {
      */
     @Test
     public void testOnEchoRequestMessage() {
-        EchoRequestMessage echoRequestMessage = new EchoRequestMessageBuilder()
-                .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build();
-        ofProtocolListener.onEchoRequestMessage(echoRequestMessage);
+        when(connectionAdapter.echoReply(any())).thenReturn(Futures.immediateFuture(null));
+        ofProtocolListener.onEchoRequestMessage(
+            new EchoRequestMessageBuilder().setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build());
 
-        Mockito.verify(connectionAdapter).echoReply(any(EchoReplyInput.class));
+        verify(connectionAdapter).echoReply(any(EchoReplyInput.class));
     }
 
     /**
@@ -96,10 +95,10 @@ public class OpenflowProtocolListenerFullImplTest {
     @Test
     public void testOnErrorMessage() {
         ErrorMessage errorMessage = new ErrorMessageBuilder()
-                .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build();
+                .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
         ofProtocolListener.onErrorMessage(errorMessage);
 
-        Mockito.verify(deviceReplyProcessor).processReply(any(ErrorMessage.class));
+        verify(deviceReplyProcessor).processReply(any(ErrorMessage.class));
     }
 
     /**
@@ -110,10 +109,10 @@ public class OpenflowProtocolListenerFullImplTest {
     @Test
     public void testOnExperimenterMessage() {
         ExperimenterMessage experimenterMessage = new ExperimenterMessageBuilder()
-                .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build();
+                .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
         ofProtocolListener.onExperimenterMessage(experimenterMessage);
 
-        Mockito.verify(deviceReplyProcessor).processExperimenterMessage(ArgumentMatchers.any());
+        verify(deviceReplyProcessor).processExperimenterMessage(any());
     }
 
     /**
@@ -124,10 +123,10 @@ public class OpenflowProtocolListenerFullImplTest {
     @Test
     public void testOnFlowRemovedMessage() {
         FlowRemovedMessage flowRemovedMessage = new FlowRemovedMessageBuilder()
-                .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build();
+                .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
         ofProtocolListener.onFlowRemovedMessage(flowRemovedMessage);
 
-        Mockito.verify(deviceReplyProcessor).processFlowRemovedMessage(any(FlowRemovedMessage.class));
+        verify(deviceReplyProcessor).processFlowRemovedMessage(any(FlowRemovedMessage.class));
     }
 
     /**
@@ -138,11 +137,11 @@ public class OpenflowProtocolListenerFullImplTest {
     @Test
     public void testOnHelloMessage() {
         HelloMessage helloMessage = new HelloMessageBuilder()
-                .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build();
+                .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
         ofProtocolListener.onHelloMessage(helloMessage);
 
-        Mockito.verify(connectionAdapter).getRemoteAddress();
-        Mockito.verify(connectionAdapter).disconnect();
+        verify(connectionAdapter).getRemoteAddress();
+        verify(connectionAdapter).disconnect();
     }
 
     /**
@@ -153,10 +152,10 @@ public class OpenflowProtocolListenerFullImplTest {
     @Test
     public void testOnPacketInMessage() {
         PacketInMessage packetInMessage = new PacketInMessageBuilder()
-                .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build();
+                .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
         ofProtocolListener.onPacketInMessage(packetInMessage);
 
-        Mockito.verify(deviceReplyProcessor).processPacketInMessage(any(PacketInMessage.class));
+        verify(deviceReplyProcessor).processPacketInMessage(any(PacketInMessage.class));
     }
 
     /**
@@ -167,10 +166,9 @@ public class OpenflowProtocolListenerFullImplTest {
     @Test
     public void testOnPortStatusMessage() {
         PortStatusMessage portStatusMessage = new PortStatusMessageBuilder()
-                .setVersion(OFConstants.OFP_VERSION_1_3).setXid(xid).build();
+                .setVersion(EncodeConstants.OF_VERSION_1_3).setXid(xid).build();
         ofProtocolListener.onPortStatusMessage(portStatusMessage);
 
-        Mockito.verify(deviceReplyProcessor).processPortStatusMessage(any(PortStatusMessage.class));
+        verify(deviceReplyProcessor).processPortStatusMessage(any(PortStatusMessage.class));
     }
-
 }