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;
11 import static com.google.common.util.concurrent.Futures.immediateFuture;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import static org.mockito.Matchers.any;
15 import static org.mockito.Mockito.when;
17 import com.google.common.util.concurrent.ListenableFuture;
18 import java.util.Arrays;
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.concurrent.ExecutionException;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.junit.runners.Parameterized;
25 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
26 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProviderFactory;
27 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
28 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
34 @RunWith(Parameterized.class)
35 public class StatisticsContextImplParamTest extends StatisticsContextImpMockInitiation {
38 public StatisticsContextImplParamTest(final boolean isTable, final boolean isFlow, final boolean isGroup, final boolean isMeter, final boolean isPort,
39 final boolean isQueue) {
41 this.isTable = isTable;
43 this.isGroup = isGroup;
44 this.isMeter = isMeter;
46 this.isQueue = isQueue;
49 @Parameterized.Parameters(name = "{index}")
50 public static Iterable<Object[]> data1() {
51 return Arrays.asList(new Object[][]{
52 {false, true, false, false, false, false},
53 {true, false, false, false, false, false},
54 {false, false, true, false, false, false},
55 {false, false, false, true, false, false},
56 {false, false, false, false, true, false},
57 {false, false, false, false, false, true},
65 public void gatherDynamicDataTest() {
67 when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
69 final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
70 final StatisticsContextImpl<MultipartReply> statisticsContext = new StatisticsContextImpl<MultipartReply>(
71 true, mockedDeviceContext ,convertorManager, mockedStatisticsManager,
72 MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext),
75 final ListenableFuture<RpcResult<List<MultipartReply>>> rpcResult = immediateFuture(RpcResultBuilder.success(Collections.<MultipartReply>emptyList()).build());
76 when(mockedStatisticsGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
77 .class))).thenReturn(rpcResult);
78 when(mockedStatisticsOnFlyGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
79 .class))).thenReturn(rpcResult);
81 statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService);
82 statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService);
84 final ListenableFuture<Boolean> futureResult = statisticsContext.gatherDynamicData();
87 assertTrue(futureResult.get());
88 } catch (InterruptedException | ExecutionException e) {
89 fail("Exception wasn't expected.");