Remove unused routedRpcRegistration
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / services / OpendaylightPortStatisticsServiceImplTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.impl.statistics.services;
10
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.ArgumentMatchers.eq;
13
14 import com.google.common.util.concurrent.FutureCallback;
15 import java.util.Collections;
16 import java.util.concurrent.Future;
17 import java.util.concurrent.atomic.AtomicLong;
18 import org.junit.After;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.mockito.ArgumentCaptor;
22 import org.mockito.ArgumentMatchers;
23 import org.mockito.Captor;
24 import org.mockito.Mockito;
25 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStatsBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStatsBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInputBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInputBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput;
37 import org.opendaylight.yangtools.yang.common.RpcResult;
38 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
39 import org.opendaylight.yangtools.yang.common.Uint32;
40 import org.opendaylight.yangtools.yang.common.Uint64;
41
42 /**
43  * Test for {@link OpendaylightPortStatisticsServiceImpl}.
44  */
45 public class OpendaylightPortStatisticsServiceImplTest extends AbstractSingleStatsServiceTest {
46
47     @Captor
48     private ArgumentCaptor<MultipartRequestInput> requestInput;
49
50     private OpendaylightPortStatisticsServiceImpl portStatisticsService;
51
52     @Override
53     public void setUp() {
54         portStatisticsService = new OpendaylightPortStatisticsServiceImpl(rqContextStack, deviceContext,
55                 new AtomicLong(), notificationPublishService);
56
57         Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider)
58                 .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class));
59     }
60
61     @After
62     public void tearDown() {
63         Mockito.verify(notificationPublishService).offerNotification(ArgumentMatchers.any());
64     }
65
66     @Test
67     public void testGetAllNodeConnectorsStatistics() throws Exception {
68         GetAllNodeConnectorsStatisticsInputBuilder input = new GetAllNodeConnectorsStatisticsInputBuilder()
69                 .setNode(createNodeRef("unitProt:123"));
70
71         rpcResult = buildPortStatisticsReply();
72
73         final Future<RpcResult<GetAllNodeConnectorsStatisticsOutput>> resultFuture
74                 = portStatisticsService.getAllNodeConnectorsStatistics(input.build());
75
76         Assert.assertTrue(resultFuture.isDone());
77         final RpcResult<GetAllNodeConnectorsStatisticsOutput> rpcResult = resultFuture.get();
78         Assert.assertTrue(rpcResult.isSuccessful());
79         Assert.assertEquals(MultipartType.OFPMPPORTSTATS, requestInput.getValue().getType());
80     }
81
82     private static RpcResult<Object> buildPortStatisticsReply() {
83         return RpcResultBuilder.<Object>success(Collections.singletonList(
84                 new MultipartReplyMessageBuilder()
85                         .setVersion(EncodeConstants.OF_VERSION_1_3)
86                         .setMultipartReplyBody(new MultipartReplyPortStatsCaseBuilder()
87                                 .setMultipartReplyPortStats(new MultipartReplyPortStatsBuilder()
88                                         .setPortStats(Collections.singletonList(new PortStatsBuilder()
89                                                 .setDurationSec(Uint32.valueOf(90))
90                                                 .setDurationNsec(Uint32.valueOf(91))
91                                                 .setCollisions(Uint64.valueOf(92))
92                                                 .setPortNo(Uint32.valueOf(93))
93                                                 .setRxBytes(Uint64.valueOf(94))
94                                                 .setRxCrcErr(Uint64.valueOf(95))
95                                                 .setRxDropped(Uint64.valueOf(96))
96                                                 .setRxFrameErr(Uint64.valueOf(97))
97                                                 .setRxErrors(Uint64.valueOf(98))
98                                                 .setRxOverErr(Uint64.valueOf(99))
99                                                 .setRxPackets(Uint64.valueOf(100))
100                                                 .setTxBytes(Uint64.valueOf(94))
101                                                 .setTxDropped(Uint64.valueOf(96))
102                                                 .setTxErrors(Uint64.valueOf(98))
103                                                 .setTxPackets(Uint64.valueOf(98))
104                                                 .build()))
105                                         .build())
106                                 .build())
107                         .build()
108         )).build();
109     }
110
111     @Test
112     public void testGetNodeConnectorStatistics() throws Exception {
113         GetNodeConnectorStatisticsInputBuilder input = new GetNodeConnectorStatisticsInputBuilder()
114                 .setNode(createNodeRef("unitProt:123"))
115                 .setNodeConnectorId(new NodeConnectorId("unitProt:123:321"));
116
117         rpcResult = buildPortStatisticsReply();
118
119         final Future<RpcResult<GetNodeConnectorStatisticsOutput>> resultFuture
120                 = portStatisticsService.getNodeConnectorStatistics(input.build());
121
122         Assert.assertTrue(resultFuture.isDone());
123         final RpcResult<GetNodeConnectorStatisticsOutput> rpcResult = resultFuture.get();
124         Assert.assertTrue(rpcResult.isSuccessful());
125         Assert.assertEquals(MultipartType.OFPMPPORTSTATS, requestInput.getValue().getType());
126     }
127 }