61cf8deae50b648996661a3b3dd37aa6b5998779
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / StatisticsContextImplParamTest.java
1 /*
2  *
3  *  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
4  *  *
5  *  * This program and the accompanying materials are made available under the
6  *  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  *
9  *
10  */
11
12 package org.opendaylight.openflowplugin.impl.statistics;
13
14 import static com.google.common.util.concurrent.Futures.immediateFuture;
15 import static org.junit.Assert.assertTrue;
16 import static org.junit.Assert.fail;
17 import static org.mockito.Matchers.any;
18 import static org.mockito.Mockito.mock;
19 import static org.mockito.Mockito.when;
20
21 import com.google.common.util.concurrent.ListenableFuture;
22 import java.util.Arrays;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.concurrent.ExecutionException;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.Parameterized;
29 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
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.MultipartReply;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
33 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
34
35 @RunWith(Parameterized.class)
36 public class StatisticsContextImplParamTest extends StatisticsContextImpMockInitiation {
37
38
39     public StatisticsContextImplParamTest(boolean isTable, boolean isFlow, boolean isGroup, boolean isMeter, boolean isPort,
40                                           boolean isQueue) {
41         super();
42         this.isTable = isTable;
43         this.isFlow = isFlow;
44         this.isGroup = isGroup;
45         this.isMeter = isMeter;
46         this.isPort = isPort;
47         this.isQueue = isQueue;
48     }
49
50     @Parameterized.Parameters(name = "{index}")
51     public static Iterable<Object[]> data1() {
52         return Arrays.asList(new Object[][]{
53                 {false, true, false, false, false, false},
54                 {true, false, false, false, false, false},
55                 {false, false, true, false, false, false},
56                 {false, false, false, true, false, false},
57                 {false, false, false, false, true, false},
58                 {false, false, false, false, false, true},
59         });
60     }
61
62
63
64
65     @Test
66     public void gatherDynamicDataTest() {
67
68         StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceContext);
69
70         ListenableFuture<RpcResult<List<MultipartReply>>> rpcResult = immediateFuture(RpcResultBuilder.success(Collections.<MultipartReply>emptyList()).build());
71         when(mockedStatisticsGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
72                 .class))).thenReturn(rpcResult);
73         when(mockedStatisticsOnFlyGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
74                 .class))).thenReturn(rpcResult);
75
76         statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService);
77         statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService);
78
79         ListenableFuture<Boolean> futureResult = statisticsContext.gatherDynamicData();
80
81         try {
82             assertTrue(futureResult.get());
83         } catch (InterruptedException | ExecutionException e) {
84             fail("Exception wasn't expected.");
85         }
86
87     }
88
89 }