Merge "OPNFLWPLUG-1076 Migrate lldp-speaker, forwardingrules-sync and arbitratorrecon...
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / services / direct / singlelayer / QueueDirectStatisticsServiceTest.java
index 4e32c092db2545c564ceaaee2eb779570bef86fc..bb50e72972727e04b1d31025d8199acfa9bdb609 100644 (file)
@@ -5,22 +5,22 @@
  * 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.statistics.services.direct.singlelayer;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.math.BigInteger;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.junit.Test;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractDirectStatisticsServiceTest;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64;
@@ -36,26 +36,30 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.multipart.request.multipart.request.body.MultipartRequestQueueStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMapBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
 public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest {
-    static final Long QUEUE_NO = 1L;
+    static final Uint32 QUEUE_NO = Uint32.ONE;
     private QueueDirectStatisticsService service;
 
     @Override
-    public void setUp() throws Exception {
-        service = new QueueDirectStatisticsService(requestContextStack, deviceContext, convertorManager, multipartWriterProvider);
+    public void setUp() {
+        service = new QueueDirectStatisticsService(requestContextStack,
+                                                   deviceContext,
+                                                   convertorManager,
+                                                   multipartWriterProvider);
     }
 
     @Override
-    public void testBuildRequestBody() throws Exception {
+    public void testBuildRequestBody() {
         final GetQueueStatisticsInput input = mock(GetQueueStatisticsInput.class);
 
-        when(input.getNode()).thenReturn(createNodeRef(NODE_ID));
+        lenient().when(input.getNode()).thenReturn(createNodeRef(NODE_ID));
         when(input.getQueueId()).thenReturn(new QueueId(QUEUE_NO));
         when(input.getNodeConnectorId()).thenReturn(nodeConnectorId);
 
         final MultipartRequestQueueStats body = (MultipartRequestQueueStats) ((MultipartRequest) service
-            .buildRequest(new Xid(42L), input))
+            .buildRequest(new Xid(Uint32.valueOf(42L)), input))
             .getMultipartRequestBody();
 
         assertEquals(nodeConnectorId, body.getNodeConnectorId());
@@ -63,7 +67,7 @@ public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsSe
     }
 
     @Override
-    public void testBuildReply() throws Exception {
+    public void testBuildReply() {
         final QueueIdAndStatisticsMap queueStats = new QueueIdAndStatisticsMapBuilder()
                 .setQueueId(new QueueId(QUEUE_NO))
                 .setNodeConnectorId(new NodeConnectorId(PORT_NO.toString()))
@@ -87,12 +91,27 @@ public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsSe
         assertEquals(map.getNodeConnectorId().getValue(), PORT_NO.toString());
     }
 
+    @Test
+    public void testStoreStatisticsBarePortNo() {
+        final QueueIdAndStatisticsMap map = mock(QueueIdAndStatisticsMap.class);
+        when(map.getQueueId()).thenReturn(new QueueId(QUEUE_NO));
+        when(map.getNodeConnectorId()).thenReturn(new NodeConnectorId("1"));
+
+        final List<QueueIdAndStatisticsMap> maps = Collections.singletonList(map);
+        final GetQueueStatisticsOutput output = mock(GetQueueStatisticsOutput.class);
+        when(output.getQueueIdAndStatisticsMap()).thenReturn(maps);
+
+        multipartWriterProvider.lookup(MultipartType.OFPMPQUEUE).get().write(output, true);
+        verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
+    }
+
     @Override
-    public void testStoreStatistics() throws Exception {
+    public void testStoreStatistics() {
         final QueueIdAndStatisticsMap map = mock(QueueIdAndStatisticsMap.class);
         when(map.getQueueId()).thenReturn(new QueueId(QUEUE_NO));
+        when(map.getNodeConnectorId()).thenReturn(new NodeConnectorId("openflow:1:1"));
 
-        final List<QueueIdAndStatisticsMap> maps = Arrays.asList(map);
+        final List<QueueIdAndStatisticsMap> maps = Collections.singletonList(map);
         final GetQueueStatisticsOutput output = mock(GetQueueStatisticsOutput.class);
         when(output.getQueueIdAndStatisticsMap()).thenReturn(maps);