5eeb696049cd0333f98d71fc9ea354291fa64424
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / StatisticsContextImplParamTest.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;
10
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;
16
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.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
28 import org.opendaylight.yangtools.yang.common.RpcResult;
29 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
30
31 @RunWith(Parameterized.class)
32 public class StatisticsContextImplParamTest extends StatisticsContextImpMockInitiation {
33
34
35     public StatisticsContextImplParamTest(final boolean isTable, final boolean isFlow, final boolean isGroup, final boolean isMeter, final boolean isPort,
36                                           final boolean isQueue) {
37         super();
38         this.isTable = isTable;
39         this.isFlow = isFlow;
40         this.isGroup = isGroup;
41         this.isMeter = isMeter;
42         this.isPort = isPort;
43         this.isQueue = isQueue;
44     }
45
46     @Parameterized.Parameters(name = "{index}")
47     public static Iterable<Object[]> data1() {
48         return Arrays.asList(new Object[][]{
49                 {false, true, false, false, false, false},
50                 {true, false, false, false, false, false},
51                 {false, false, true, false, false, false},
52                 {false, false, false, true, false, false},
53                 {false, false, false, false, true, false},
54                 {false, false, false, false, false, true},
55         });
56     }
57
58
59
60
61     @Test
62     public void gatherDynamicDataTest() {
63
64
65         final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, mockConductor);
66
67         final ListenableFuture<RpcResult<List<MultipartReply>>> rpcResult = immediateFuture(RpcResultBuilder.success(Collections.<MultipartReply>emptyList()).build());
68         when(mockedStatisticsGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
69                 .class))).thenReturn(rpcResult);
70         when(mockedStatisticsOnFlyGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
71                 .class))).thenReturn(rpcResult);
72
73         statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService);
74         statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService);
75
76         final ListenableFuture<Boolean> futureResult = statisticsContext.gatherDynamicData();
77
78         try {
79             assertTrue(futureResult.get());
80         } catch (InterruptedException | ExecutionException e) {
81             fail("Exception wasn't expected.");
82         }
83
84     }
85
86 }