Merge "Bug 5596 Cleaning lifecycle conductor"
[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.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
27 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
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.MultipartReply;
30 import org.opendaylight.yangtools.yang.common.RpcResult;
31 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
32
33 @RunWith(Parameterized.class)
34 public class StatisticsContextImplParamTest extends StatisticsContextImpMockInitiation {
35
36
37     public StatisticsContextImplParamTest(final boolean isTable, final boolean isFlow, final boolean isGroup, final boolean isMeter, final boolean isPort,
38                                           final boolean isQueue) {
39         super();
40         this.isTable = isTable;
41         this.isFlow = isFlow;
42         this.isGroup = isGroup;
43         this.isMeter = isMeter;
44         this.isPort = isPort;
45         this.isQueue = isQueue;
46     }
47
48     @Parameterized.Parameters(name = "{index}")
49     public static Iterable<Object[]> data1() {
50         return Arrays.asList(new Object[][]{
51                 {false, true, false, false, false, false},
52                 {true, false, false, false, false, false},
53                 {false, false, true, false, false, false},
54                 {false, false, false, true, false, false},
55                 {false, false, false, false, true, false},
56                 {false, false, false, false, false, true},
57         });
58     }
59
60
61
62
63     @Test
64     public void gatherDynamicDataTest() {
65
66         when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
67         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
68
69         final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
70         final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, lifecycleService ,convertorManager, mockedStatisticsManager);
71
72         final ListenableFuture<RpcResult<List<MultipartReply>>> rpcResult = immediateFuture(RpcResultBuilder.success(Collections.<MultipartReply>emptyList()).build());
73         when(mockedStatisticsGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
74                 .class))).thenReturn(rpcResult);
75         when(mockedStatisticsOnFlyGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
76                 .class))).thenReturn(rpcResult);
77
78         statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService);
79         statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService);
80
81         final ListenableFuture<Boolean> futureResult = statisticsContext.gatherDynamicData();
82
83         try {
84             assertTrue(futureResult.get());
85         } catch (InterruptedException | ExecutionException e) {
86             fail("Exception wasn't expected.");
87         }
88
89     }
90
91 }