Decompose RPC implementation classes
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / services / direct / multilayer / QueueDirectStatisticsServiceTest.java
index e57f79408353772ed2138f28394241fde4d12e55..5b62c7b4d6f13a951b5066029fe8769e835721dc 100644 (file)
@@ -5,22 +5,21 @@
  * 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.multilayer;
 
 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.Collections;
 import java.util.List;
+import java.util.Map;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+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.opendaylight.direct.statistics.rev160511.GetQueueStatisticsInput;
@@ -36,89 +35,96 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueue;
 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.QueueIdAndStatisticsMapKey;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
 
 public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest {
-    static final Long QUEUE_NO = 1L;
-    private QueueDirectStatisticsService service;
+    private MultiGetQueueStatistics service;
 
     @Override
-    public void setUp() throws Exception {
-        service = new QueueDirectStatisticsService(requestContextStack,
-                                                   deviceContext,
-                                                   convertorManager,
-                                                   multipartWriterProvider);
+    public void setUp() {
+        service = new MultiGetQueueStatistics(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));
-        when(input.getQueueId()).thenReturn(new QueueId(QUEUE_NO));
+        lenient().when(input.getNode()).thenReturn(createNodeRef(NODE_ID));
+        when(input.getQueueId()).thenReturn(new QueueId(Uint32.ONE));
         when(input.getNodeConnectorId()).thenReturn(new NodeConnectorId(NODE_ID + ":" + PORT_NO));
 
         final MultipartRequestQueueCase body = (MultipartRequestQueueCase) ((MultipartRequestInput) service
-            .buildRequest(new Xid(42L), input))
+            .buildRequest(new Xid(Uint32.valueOf(42)), input))
             .getMultipartRequestBody();
 
         final MultipartRequestQueue queue = body.getMultipartRequestQueue();
 
         assertEquals(PORT_NO, queue.getPortNo());
-        assertEquals(QUEUE_NO, queue.getQueueId());
+        assertEquals(Uint32.ONE, queue.getQueueId());
     }
 
     @Override
-    public void testBuildReply() throws Exception {
+    public void testBuildReply() {
         final MultipartReply reply = mock(MultipartReply.class);
         final MultipartReplyQueueCase queueCase = mock(MultipartReplyQueueCase.class);
         final MultipartReplyQueue queue = mock(MultipartReplyQueue.class);
         final QueueStats queueStat = mock(QueueStats.class);
-        final List<QueueStats> queueStats = Collections.singletonList(queueStat);
-        final List<MultipartReply> input = Collections.singletonList(reply);
+        final List<QueueStats> queueStats = List.of(queueStat);
+        final List<MultipartReply> input = List.of(reply);
 
         when(queue.getQueueStats()).thenReturn(queueStats);
+        when(queue.nonnullQueueStats()).thenCallRealMethod();
         when(queueCase.getMultipartReplyQueue()).thenReturn(queue);
         when(reply.getMultipartReplyBody()).thenReturn(queueCase);
 
         when(queueStat.getPortNo()).thenReturn(PORT_NO);
-        when(queueStat.getQueueId()).thenReturn(QUEUE_NO);
-        when(queueStat.getTxBytes()).thenReturn(BigInteger.ONE);
-        when(queueStat.getTxErrors()).thenReturn(BigInteger.ONE);
-        when(queueStat.getTxPackets()).thenReturn(BigInteger.ONE);
+        when(queueStat.getQueueId()).thenReturn(Uint32.ONE);
+        when(queueStat.getTxBytes()).thenReturn(Uint64.ONE);
+        when(queueStat.getTxErrors()).thenReturn(Uint64.ONE);
+        when(queueStat.getTxPackets()).thenReturn(Uint64.ONE);
+        when(queueStat.getDurationSec()).thenReturn(Uint32.ZERO);
+        when(queueStat.getDurationNsec()).thenReturn(Uint32.ZERO);
 
         final GetQueueStatisticsOutput output = service.buildReply(input, true);
-        assertTrue(output.getQueueIdAndStatisticsMap().size() > 0);
+        assertTrue(output.nonnullQueueIdAndStatisticsMap().size() > 0);
 
-        final QueueIdAndStatisticsMap map = output.getQueueIdAndStatisticsMap().get(0);
-        assertEquals(map.getQueueId().getValue(), QUEUE_NO);
+        final QueueIdAndStatisticsMap map = output.nonnullQueueIdAndStatisticsMap().values().iterator().next();
+        assertEquals(map.getQueueId().getValue(), Uint32.ONE);
         assertEquals(map.getNodeConnectorId(), nodeConnectorId);
     }
 
     @Test
-    public void testStoreStatisticsBarePortNo() throws Exception {
+    public void testStoreStatisticsBarePortNo() {
         final QueueIdAndStatisticsMap map = mock(QueueIdAndStatisticsMap.class);
-        when(map.getQueueId()).thenReturn(new QueueId(QUEUE_NO));
+        when(map.getQueueId()).thenReturn(new QueueId(Uint32.ONE));
         when(map.getNodeConnectorId()).thenReturn(new NodeConnectorId("1"));
+        when(map.key()).thenReturn(new QueueIdAndStatisticsMapKey(new NodeConnectorId("1"), new QueueId(Uint32.ONE)));
 
-        final List<QueueIdAndStatisticsMap> maps = Collections.singletonList(map);
+        final Map<QueueIdAndStatisticsMapKey, QueueIdAndStatisticsMap> maps = BindingMap.of(map);
         final GetQueueStatisticsOutput output = mock(GetQueueStatisticsOutput.class);
-        when(output.getQueueIdAndStatisticsMap()).thenReturn(maps);
+        when(output.nonnullQueueIdAndStatisticsMap()).thenReturn(maps);
 
-        multipartWriterProvider.lookup(MultipartType.OFPMPQUEUE).get().write(output, true);
+        multipartWriterProvider.lookup(MultipartType.OFPMPQUEUE).orElseThrow().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.getQueueId()).thenReturn(new QueueId(Uint32.ONE));
         when(map.getNodeConnectorId()).thenReturn(new NodeConnectorId("openflow:1:1"));
+        when(map.key()).thenReturn(new QueueIdAndStatisticsMapKey(new NodeConnectorId("openflow:1:1"),
+            new QueueId(Uint32.ONE)));
 
-        final List<QueueIdAndStatisticsMap> maps = Collections.singletonList(map);
+        final Map<QueueIdAndStatisticsMapKey, QueueIdAndStatisticsMap> maps = BindingMap.of(map);
         final GetQueueStatisticsOutput output = mock(GetQueueStatisticsOutput.class);
-        when(output.getQueueIdAndStatisticsMap()).thenReturn(maps);
+        when(output.nonnullQueueIdAndStatisticsMap()).thenReturn(maps);
 
-        multipartWriterProvider.lookup(MultipartType.OFPMPQUEUE).get().write(output, true);
+        multipartWriterProvider.lookup(MultipartType.OFPMPQUEUE).orElseThrow().write(output, true);
         verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
     }
 }