OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / services / AbstractStatsServiceTest.java
index f794caddfb613b4687b171c6526aead85d6c6a51..66f59b01931e664a0f4d856510111f2044d1ec8b 100644 (file)
@@ -8,31 +8,34 @@
 
 package org.opendaylight.openflowplugin.impl.statistics.services;
 
+import static org.mockito.ArgumentMatchers.any;
+
 import com.google.common.util.concurrent.FutureCallback;
+import java.math.BigInteger;
 import org.junit.Before;
 import org.junit.runner.RunWith;
-import org.mockito.Matchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.mockito.stubbing.Answer;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
-import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
@@ -42,47 +45,54 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 @RunWith(MockitoJUnitRunner.class)
 public abstract class AbstractStatsServiceTest {
     @Mock
-    RequestContextStack rqContextStack;
+    protected RequestContextStack rqContextStack;
+    @Mock
+    protected DeviceContext deviceContext;
+    @Mock
+    protected ConnectionContext connectionContext;
+    @Mock
+    protected FeaturesReply features;
     @Mock
-    DeviceContext deviceContext;
+    private GetFeaturesOutput getFeaturesOutput;
     @Mock
-    ConnectionContext connectionContext;
+    protected MessageSpy messageSpy;
     @Mock
-    FeaturesReply features;
+    protected OutboundQueue outboundQueueProvider;
     @Mock
-    MessageSpy messageSpy;
+    protected MultiMsgCollector multiMsgCollector;
     @Mock
-    OutboundQueue outboundQueueProvider;
+    protected TranslatorLibrary translatorLibrary;
     @Mock
-    MultiMsgCollector multiMsgCollector;
+    protected DeviceState deviceState;
     @Mock
-    TranslatorLibrary translatorLibrary;
+    protected DeviceInfo deviceInfo;
 
-    final Answer<Void> answerVoidToCallback = new Answer<Void>() {
-        @Override
-        public Void answer(InvocationOnMock invocation) throws Throwable {
-            final FutureCallback<OfHeader> callback = (FutureCallback<OfHeader>) (invocation.getArguments()[2]);
-            callback.onSuccess(null);
-            return null;
-        }
-    };
 
-    /**
-     * default ctor
-     */
-    public AbstractStatsServiceTest() {
-        OpenflowPortsUtil.init();
-    }
+    public static final NodeId NODE_ID = new NodeId("unit-test-node:123");
+
+    protected final Answer<Void> answerVoidToCallback = invocation -> {
+        final FutureCallback<OfHeader> callback = (FutureCallback<OfHeader>) (invocation.getArguments()[2]);
+        callback.onSuccess(null);
+        return null;
+    };
 
     @Before
     public void init() throws Exception {
-        Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
+        Mockito.lenient().when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
         Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
-        Mockito.when(deviceContext.getMultiMsgCollector(Matchers.any(RequestContext.class))).thenReturn(multiMsgCollector);
-        Mockito.when(deviceContext.oook()).thenReturn(translatorLibrary);
-        Mockito.when(connectionContext.getFeatures()).thenReturn(features);
-        Mockito.when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
-        Mockito.when(features.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+        Mockito.lenient().when(deviceContext.getMultiMsgCollector(any(RequestContext.class)))
+                .thenReturn(multiMsgCollector);
+        Mockito.lenient().when(deviceContext.oook()).thenReturn(translatorLibrary);
+        Mockito.lenient().when(deviceContext.getDeviceState()).thenReturn(deviceState);
+        Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
+        Mockito.lenient().when(deviceInfo.getNodeId()).thenReturn(NODE_ID);
+        Mockito.lenient().when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+        Mockito.lenient().when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
+        Mockito.lenient().when(connectionContext.getFeatures()).thenReturn(features);
+        Mockito.lenient().when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
+        Mockito.lenient().when(features.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+        Mockito.lenient().when(getFeaturesOutput.getDatapathId()).thenReturn(BigInteger.valueOf(123L));
+        Mockito.lenient().when(getFeaturesOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
 
         setUp();
     }
@@ -91,7 +101,7 @@ public abstract class AbstractStatsServiceTest {
         //NOOP
     }
 
-    static NodeRef createNodeRef(String nodeIdValue) {
+    protected static NodeRef createNodeRef(String nodeIdValue) {
         InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, new NodeKey(new NodeId(nodeIdValue)));
         return new NodeRef(nodePath);