Coverage - ofp/impl/statistics/services
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / services / OpendaylightMeterStatisticsServiceImplTest.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 com.google.common.util.concurrent.FutureCallback;
12 import java.util.concurrent.Future;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.mockito.ArgumentCaptor;
16 import org.mockito.Captor;
17 import org.mockito.Matchers;
18 import org.mockito.Mockito;
19 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
20 import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInputBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInputBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
33
34 /**
35  * Test for {@link OpendaylightMeterStatisticsServiceImpl}
36  */
37 public class OpendaylightMeterStatisticsServiceImplTest extends AbstractStatsServiceTest {
38
39     @Captor
40     private ArgumentCaptor<MultipartRequestInput> requestInput;
41
42     private RequestContext<Object> rqContext;
43
44     private OpendaylightMeterStatisticsServiceImpl meterStatisticsService;
45
46     public void setUp() {
47         meterStatisticsService = new OpendaylightMeterStatisticsServiceImpl(rqContextStack, deviceContext);
48
49         rqContext = new AbstractRequestContext<Object>(42L) {
50             @Override
51             public void close() {
52                 //NOOP
53             }
54         };
55         Mockito.when(rqContextStack.<Object>createRequestContext()).thenReturn(rqContext);
56     }
57
58     @Test
59     public void testGetAllMeterConfigStatistics() throws Exception {
60         Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider)
61                 .commitEntry(Matchers.eq(42L), requestInput.capture(), Matchers.any(FutureCallback.class));
62
63         GetAllMeterConfigStatisticsInputBuilder input = new GetAllMeterConfigStatisticsInputBuilder()
64                 .setNode(createNodeRef("unitProt:123"));
65
66         final Future<RpcResult<GetAllMeterConfigStatisticsOutput>> resultFuture
67                 = meterStatisticsService.getAllMeterConfigStatistics(input.build());
68
69         Assert.assertTrue(resultFuture.isDone());
70         final RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = resultFuture.get();
71         Assert.assertTrue(rpcResult.isSuccessful());
72         Assert.assertEquals(MultipartType.OFPMPMETERCONFIG, requestInput.getValue().getType());
73     }
74
75     @Test
76     public void testGetAllMeterStatistics() throws Exception {
77         Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider)
78                 .commitEntry(Matchers.eq(42L), requestInput.capture(), Matchers.any(FutureCallback.class));
79
80         GetAllMeterStatisticsInputBuilder input = new GetAllMeterStatisticsInputBuilder()
81                 .setNode(createNodeRef("unitProt:123"));
82
83         final Future<RpcResult<GetAllMeterStatisticsOutput>> resultFuture
84                 = meterStatisticsService.getAllMeterStatistics(input.build());
85
86         Assert.assertTrue(resultFuture.isDone());
87         final RpcResult<GetAllMeterStatisticsOutput> rpcResult = resultFuture.get();
88         Assert.assertTrue(rpcResult.isSuccessful());
89         Assert.assertEquals(MultipartType.OFPMPMETER, requestInput.getValue().getType());
90     }
91
92     @Test
93     public void testGetMeterFeatures() throws Exception {
94         Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider)
95                 .commitEntry(Matchers.eq(42L), requestInput.capture(), Matchers.any(FutureCallback.class));
96
97         GetMeterFeaturesInputBuilder input = new GetMeterFeaturesInputBuilder()
98                 .setNode(createNodeRef("unitProt:123"));
99
100         final Future<RpcResult<GetMeterFeaturesOutput>> resultFuture
101                 = meterStatisticsService.getMeterFeatures(input.build());
102
103         Assert.assertTrue(resultFuture.isDone());
104         final RpcResult<GetMeterFeaturesOutput> rpcResult = resultFuture.get();
105         Assert.assertTrue(rpcResult.isSuccessful());
106         Assert.assertEquals(MultipartType.OFPMPMETERFEATURES, requestInput.getValue().getType());
107     }
108
109     @Test
110     public void testGetMeterStatistics() throws Exception {
111         Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider)
112                 .commitEntry(Matchers.eq(42L), requestInput.capture(), Matchers.any(FutureCallback.class));
113
114         GetMeterStatisticsInputBuilder input = new GetMeterStatisticsInputBuilder()
115                 .setNode(createNodeRef("unitProt:123"))
116                 .setMeterId(new MeterId(21L));
117
118         final Future<RpcResult<GetMeterStatisticsOutput>> resultFuture
119                 = meterStatisticsService.getMeterStatistics(input.build());
120
121         Assert.assertTrue(resultFuture.isDone());
122         final RpcResult<GetMeterStatisticsOutput> rpcResult = resultFuture.get();
123         Assert.assertTrue(rpcResult.isSuccessful());
124         Assert.assertEquals(MultipartType.OFPMPMETER, requestInput.getValue().getType());
125     }
126 }