Modernize codebase
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / services / direct / multilayer / NodeConnectorDirectStatisticsServiceTest.java
index 321be4b1e6f91bb07ba6cf989a1a8dc33c6d169e..e6e5f962ae84db3bf41a507131972b9231231eeb 100644 (file)
@@ -16,9 +16,8 @@ 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.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractDirectStatisticsServiceTest;
@@ -33,6 +32,10 @@ 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.MultipartRequestPortStatsCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMapKey;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
 
 public class NodeConnectorDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest {
     private PortDirectStatisticsService service;
@@ -53,7 +56,7 @@ public class NodeConnectorDirectStatisticsServiceTest extends AbstractDirectStat
         when(input.getNodeConnectorId()).thenReturn(nodeConnectorId);
 
         final MultipartRequestPortStatsCase body = (MultipartRequestPortStatsCase) ((MultipartRequestInput)service
-            .buildRequest(new Xid(42L), input))
+            .buildRequest(new Xid(Uint32.valueOf(42)), input))
             .getMultipartRequestBody();
 
         final MultipartRequestPortStats nodeConnector = body.getMultipartRequestPortStats();
@@ -67,31 +70,32 @@ public class NodeConnectorDirectStatisticsServiceTest extends AbstractDirectStat
         final MultipartReplyPortStatsCase nodeConnectorCase = mock(MultipartReplyPortStatsCase.class);
         final MultipartReplyPortStats nodeConnector = mock(MultipartReplyPortStats.class);
         final PortStats nodeConnectorStat = mock(PortStats.class);
-        final List<PortStats> nodeConnectorStats = Collections.singletonList(nodeConnectorStat);
-        final List<MultipartReply> input = Collections.singletonList(reply);
+        final List<PortStats> nodeConnectorStats = List.of(nodeConnectorStat);
+        final List<MultipartReply> input = List.of(reply);
 
         when(nodeConnector.getPortStats()).thenReturn(nodeConnectorStats);
+        when(nodeConnector.nonnullPortStats()).thenCallRealMethod();
         when(nodeConnectorCase.getMultipartReplyPortStats()).thenReturn(nodeConnector);
         when(reply.getMultipartReplyBody()).thenReturn(nodeConnectorCase);
 
         when(nodeConnectorStat.getPortNo()).thenReturn(PORT_NO);
-        when(nodeConnectorStat.getTxBytes()).thenReturn(BigInteger.ONE);
-        when(nodeConnectorStat.getCollisions()).thenReturn(BigInteger.ONE);
-        when(nodeConnectorStat.getRxBytes()).thenReturn(BigInteger.ONE);
-        when(nodeConnectorStat.getRxCrcErr()).thenReturn(BigInteger.ONE);
-        when(nodeConnectorStat.getRxDropped()).thenReturn(BigInteger.ONE);
-        when(nodeConnectorStat.getRxErrors()).thenReturn(BigInteger.ONE);
-        when(nodeConnectorStat.getRxFrameErr()).thenReturn(BigInteger.ONE);
-        when(nodeConnectorStat.getRxOverErr()).thenReturn(BigInteger.ONE);
-        when(nodeConnectorStat.getRxPackets()).thenReturn(BigInteger.ONE);
-        when(nodeConnectorStat.getTxDropped()).thenReturn(BigInteger.ONE);
-        when(nodeConnectorStat.getTxErrors()).thenReturn(BigInteger.ONE);
+        when(nodeConnectorStat.getTxBytes()).thenReturn(Uint64.ONE);
+        when(nodeConnectorStat.getCollisions()).thenReturn(Uint64.ONE);
+        when(nodeConnectorStat.getRxBytes()).thenReturn(Uint64.ONE);
+        when(nodeConnectorStat.getRxCrcErr()).thenReturn(Uint64.ONE);
+        when(nodeConnectorStat.getRxDropped()).thenReturn(Uint64.ONE);
+        when(nodeConnectorStat.getRxErrors()).thenReturn(Uint64.ONE);
+        when(nodeConnectorStat.getRxFrameErr()).thenReturn(Uint64.ONE);
+        when(nodeConnectorStat.getRxOverErr()).thenReturn(Uint64.ONE);
+        when(nodeConnectorStat.getRxPackets()).thenReturn(Uint64.ONE);
+        when(nodeConnectorStat.getTxDropped()).thenReturn(Uint64.ONE);
+        when(nodeConnectorStat.getTxErrors()).thenReturn(Uint64.ONE);
 
         final GetNodeConnectorStatisticsOutput output = service.buildReply(input, true);
-        assertTrue(output.getNodeConnectorStatisticsAndPortNumberMap().size() > 0);
+        assertTrue(output.nonnullNodeConnectorStatisticsAndPortNumberMap().size() > 0);
 
         final NodeConnectorStatisticsAndPortNumberMap stats =
-                output.getNodeConnectorStatisticsAndPortNumberMap().get(0);
+                output.nonnullNodeConnectorStatisticsAndPortNumberMap().values().iterator().next();
 
         assertEquals(stats.getNodeConnectorId(), nodeConnectorId);
     }
@@ -99,13 +103,15 @@ public class NodeConnectorDirectStatisticsServiceTest extends AbstractDirectStat
     @Override
     public void testStoreStatistics() {
         final NodeConnectorStatisticsAndPortNumberMap stat = mock(NodeConnectorStatisticsAndPortNumberMap.class);
+        when(stat.key()).thenReturn(new NodeConnectorStatisticsAndPortNumberMapKey(nodeConnectorId));
         when(stat.getNodeConnectorId()).thenReturn(nodeConnectorId);
 
-        final List<NodeConnectorStatisticsAndPortNumberMap> stats = Collections.singletonList(stat);
+        final Map<NodeConnectorStatisticsAndPortNumberMapKey, NodeConnectorStatisticsAndPortNumberMap> stats
+                = BindingMap.of(stat);
         final GetNodeConnectorStatisticsOutput output = mock(GetNodeConnectorStatisticsOutput.class);
-        when(output.getNodeConnectorStatisticsAndPortNumberMap()).thenReturn(stats);
+        when(output.nonnullNodeConnectorStatisticsAndPortNumberMap()).thenReturn(stats);
 
-        multipartWriterProvider.lookup(MultipartType.OFPMPPORTSTATS).get().write(output, true);
+        multipartWriterProvider.lookup(MultipartType.OFPMPPORTSTATS).orElseThrow().write(output, true);
         verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
     }
 }