X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fstatistics%2Fservices%2Fdirect%2Fmultilayer%2FQueueDirectStatisticsServiceTest.java;h=5b62c7b4d6f13a951b5066029fe8769e835721dc;hb=3ee047a21cbd0754dabaab6d01708d5c20be80fd;hp=45706f117570aae4964ae6e09470833221e81031;hpb=b4f4b4b702e2ccd8a7c62fd2a5c184c5b1cbe665;p=openflowplugin.git diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/QueueDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/QueueDirectStatisticsServiceTest.java index 45706f1175..5b62c7b4d6 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/QueueDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/QueueDirectStatisticsServiceTest.java @@ -5,7 +5,6 @@ * 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; @@ -17,11 +16,10 @@ 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; @@ -37,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); lenient().when(input.getNode()).thenReturn(createNodeRef(NODE_ID)); - when(input.getQueueId()).thenReturn(new QueueId(QUEUE_NO)); + 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 = Collections.singletonList(queueStat); - final List input = Collections.singletonList(reply); + final List queueStats = List.of(queueStat); + final List 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 maps = Collections.singletonList(map); + final Map 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 maps = Collections.singletonList(map); + final Map 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()); } }