Decompose RPC implementation classes
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / services / compatibility / AbstractCompatibleStatServiceTest.java
index fa05edea0edcb6447631c9aca9e9531e076daaf7..8cebb2958791bfa953410f508788e25d31f9baed 100644 (file)
@@ -5,24 +5,29 @@
  * 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.compatibility;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.ListenableFuture;
-import java.math.BigInteger;
-import java.util.Collections;
+import java.util.List;
 import java.util.concurrent.atomic.AtomicLong;
-import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Captor;
-import org.mockito.Matchers;
 import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
@@ -51,6 +56,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 /**
  * Test for {@link AbstractCompatibleStatService}.
@@ -80,41 +88,39 @@ public class AbstractCompatibleStatServiceTest extends AbstractStatsServiceTest
 
     @Override
     public void setUp() {
-        rqContext = new AbstractRequestContext<Object>(42L) {
+        rqContext = new AbstractRequestContext<>(Uint32.valueOf(42)) {
             @Override
             public void close() {
                 //NOOP
             }
         };
-        final Answer closeRequestFutureAnswer = new Answer() {
-            @Override
-            public Void answer(InvocationOnMock invocation) throws Throwable {
-                rqContext.setResult(rpcResult);
-                rqContext.close();
-                return null;
-            }
+        final Answer closeRequestFutureAnswer = invocation -> {
+            rqContext.setResult(rpcResult);
+            rqContext.close();
+            return null;
         };
 
-        Mockito.when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
-        Mockito.when(rqContextStack.<Object>createRequestContext()).thenReturn(rqContext);
-        Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
-        Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
-        Mockito.when(deviceInfo.getNodeId()).thenReturn(NODE_ID);
-        Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
-        Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting();
-        Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting(Matchers.any(EventIdentifier.class));
+        lenient().when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+        when(rqContextStack.createRequestContext()).thenReturn(rqContext);
+        lenient().when(deviceContext.getDeviceState()).thenReturn(deviceState);
+        when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
+        when(deviceInfo.getNodeId()).thenReturn(NODE_ID);
+        when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+        doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting(null);
+        lenient().doAnswer(closeRequestFutureAnswer).when(multiMsgCollector)
+                .endCollecting(any(EventIdentifier.class));
 
-        Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider)
-                .commitEntry(Matchers.eq(42L), requestInput.capture(), Matchers.any(FutureCallback.class));
+        doAnswer(answerVoidToCallback).when(outboundQueueProvider)
+                .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class));
 
-        Mockito.when(translatorLibrary.lookupTranslator(Matchers.any(TranslatorKey.class))).thenReturn(translator);
+        when(translatorLibrary.lookupTranslator(any(TranslatorKey.class))).thenReturn(translator);
 
-        service = AggregateFlowsInTableService.createWithOook(rqContextStack, deviceContext, new AtomicLong(20L));
+        service = new AggregateFlowsInTableService(rqContextStack, deviceContext, new AtomicLong(20L));
     }
 
     @Test
-    public void testGetOfVersion() throws Exception {
-        Assert.assertEquals(OFConstants.OFP_VERSION_1_3, service.getOfVersion().getVersion());
+    public void testGetOfVersion() {
+        assertEquals(OFConstants.OFP_VERSION_1_3, service.getOfVersion().getVersion());
     }
 
     @Test
@@ -122,39 +128,39 @@ public class AbstractCompatibleStatServiceTest extends AbstractStatsServiceTest
         GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input =
                 new GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder()
                         .setNode(createNodeRef("unitProt:123"))
-                        .setTableId(new TableId((short) 1))
+                        .setTableId(new TableId(Uint8.ONE))
                         .build();
 
-        rpcResult = RpcResultBuilder.<Object>success(Collections.singletonList(
+        rpcResult = RpcResultBuilder.<Object>success(List.of(
                 new MultipartReplyMessageBuilder()
-                        .setVersion(OFConstants.OFP_VERSION_1_3)
+                        .setVersion(EncodeConstants.OF_VERSION_1_3)
                         .setMultipartReplyBody(new MultipartReplyAggregateCaseBuilder()
                                 .setMultipartReplyAggregate(new MultipartReplyAggregateBuilder()
-                                        .setByteCount(BigInteger.valueOf(11L))
-                                        .setFlowCount(12L)
-                                        .setPacketCount(BigInteger.valueOf(13L))
+                                        .setByteCount(Uint64.valueOf(11))
+                                        .setFlowCount(Uint32.valueOf(12))
+                                        .setPacketCount(Uint64.valueOf(13))
                                         .build())
                                 .build())
                         .build()
         )).build();
 
         AggregatedFlowStatistics aggregatedStats = new AggregatedFlowStatisticsBuilder()
-                .setByteCount(new Counter64(BigInteger.valueOf(11L)))
-                .setFlowCount(new Counter32(12L))
-                .setPacketCount(new Counter64(BigInteger.valueOf(13L)))
+                .setByteCount(new Counter64(Uint64.valueOf(11)))
+                .setFlowCount(new Counter32(Uint32.valueOf(12)))
+                .setPacketCount(new Counter64(Uint64.valueOf(13)))
                 .build();
-        Mockito.when(translator.translate(Matchers.any(MultipartReply.class), Matchers.eq(deviceInfo), Matchers.any()))
+        when(translator.translate(any(MultipartReply.class), eq(deviceInfo), any()))
                 .thenReturn(aggregatedStats);
 
 
         ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> resultFuture =
                 service.handleAndNotify(input, notificationPublishService);
 
-        Assert.assertTrue(resultFuture.isDone());
-        final RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> rpcResult = resultFuture.get();
-        Assert.assertTrue(rpcResult.isSuccessful());
-        Assert.assertEquals(MultipartType.OFPMPAGGREGATE, requestInput.getValue().getType());
-        Mockito.verify(notificationPublishService, Mockito.timeout(500)).offerNotification(Matchers.any(AggregateFlowStatisticsUpdate.class));
+        assertTrue(resultFuture.isDone());
+        final RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> result = resultFuture.get();
+        assertTrue(result.isSuccessful());
+        assertEquals(MultipartType.OFPMPAGGREGATE, requestInput.getValue().getType());
+        verify(notificationPublishService, timeout(500))
+                .offerNotification(any(AggregateFlowStatisticsUpdate.class));
     }
-
 }