2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.impl.statistics.services;
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.impl.rpc.AbstractRequestContext;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInputBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
34 * Test for {@link OpendaylightFlowStatisticsServiceImpl}
36 public class OpendaylightFlowStatisticsServiceImpl1Test extends AbstractStatsServiceTest {
39 private ArgumentCaptor<MultipartRequestInput> requestInput;
41 private AbstractRequestContext<Object> rqContext;
43 private OpendaylightFlowStatisticsServiceImpl flowStatisticsService;
47 flowStatisticsService = new OpendaylightFlowStatisticsServiceImpl(rqContextStack, deviceContext);
49 rqContext = new AbstractRequestContext<Object>(42L) {
55 Mockito.when(rqContextStack.<Object>createRequestContext()).thenReturn(rqContext);
59 public void testGetAggregateFlowStatisticsFromFlowTableForAllFlows() throws Exception {
60 Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider)
61 .commitEntry(Matchers.eq(42L), requestInput.capture(), Matchers.any(FutureCallback.class));
63 GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder input = new GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder()
64 .setNode(createNodeRef("unitProt:123"))
65 .setTableId(new TableId((short) 1));
67 final Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> resultFuture
68 = flowStatisticsService.getAggregateFlowStatisticsFromFlowTableForAllFlows(input.build());
70 Assert.assertTrue(resultFuture.isDone());
71 final RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> rpcResult = resultFuture.get();
72 Assert.assertTrue(rpcResult.isSuccessful());
73 Assert.assertEquals(MultipartType.OFPMPAGGREGATE, requestInput.getValue().getType());
77 public void testGetAllFlowStatisticsFromFlowTable() throws Exception {
78 Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider)
79 .commitEntry(Matchers.eq(42L), requestInput.capture(), Matchers.any(FutureCallback.class));
81 GetAllFlowStatisticsFromFlowTableInputBuilder input = new GetAllFlowStatisticsFromFlowTableInputBuilder()
82 .setNode(createNodeRef("unitProt:123"))
83 .setTableId(new TableId((short) 1));
85 final Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> resultFuture
86 = flowStatisticsService.getAllFlowStatisticsFromFlowTable(input.build());
88 Assert.assertTrue(resultFuture.isDone());
89 final RpcResult<GetAllFlowStatisticsFromFlowTableOutput> rpcResult = resultFuture.get();
90 Assert.assertTrue(rpcResult.isSuccessful());
91 Assert.assertEquals(MultipartType.OFPMPFLOW, requestInput.getValue().getType());
95 public void testGetAllFlowsStatisticsFromAllFlowTables() throws Exception {
96 Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider)
97 .commitEntry(Matchers.eq(42L), requestInput.capture(), Matchers.any(FutureCallback.class));
99 GetAllFlowsStatisticsFromAllFlowTablesInputBuilder input = new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder()
100 .setNode(createNodeRef("unitProt:123"));
102 final Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> resultFuture
103 = flowStatisticsService.getAllFlowsStatisticsFromAllFlowTables(input.build());
105 Assert.assertTrue(resultFuture.isDone());
106 final RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput> rpcResult = resultFuture.get();
107 Assert.assertTrue(rpcResult.isSuccessful());
108 Assert.assertEquals(MultipartType.OFPMPFLOW, requestInput.getValue().getType());
112 public void testGetFlowStatisticsFromFlowTable() throws Exception {
113 Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider)
114 .commitEntry(Matchers.eq(42L), requestInput.capture(), Matchers.any(FutureCallback.class));
116 GetFlowStatisticsFromFlowTableInputBuilder input = new GetFlowStatisticsFromFlowTableInputBuilder()
117 .setNode(createNodeRef("unitProt:123"))
120 final Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> resultFuture
121 = flowStatisticsService.getFlowStatisticsFromFlowTable(input.build());
123 Assert.assertTrue(resultFuture.isDone());
124 final RpcResult<GetFlowStatisticsFromFlowTableOutput> rpcResult = resultFuture.get();
125 Assert.assertTrue(rpcResult.isSuccessful());
126 Assert.assertEquals(MultipartType.OFPMPFLOW, requestInput.getValue().getType());