Merge "Cleanup"
[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.mockito.Matchers.any;
13 import static org.mockito.Mockito.times;
14 import static org.mockito.Mockito.verify;
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 org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.junit.runners.Parameterized;
24 import org.mockito.Matchers;
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;
33
34 @RunWith(Parameterized.class)
35 public class StatisticsContextImplParamTest extends StatisticsContextImpMockInitiation {
36
37
38     public StatisticsContextImplParamTest(final boolean isTable, final boolean isFlow,
39                                           final boolean isGroup, final boolean isMeter,
40                                           final boolean isPort, final 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     @Test
63     public void gatherDynamicDataTest() throws InterruptedException {
64
65         when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(Boolean.TRUE);
66         when(mockedDeviceState.isFlowStatisticsAvailable()).thenReturn(Boolean.TRUE);
67         when(mockedDeviceState.isGroupAvailable()).thenReturn(Boolean.TRUE);
68         when(mockedDeviceState.isMetersAvailable()).thenReturn(Boolean.TRUE);
69         when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(Boolean.TRUE);
70         when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(Boolean.TRUE);
71         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
72
73         final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
74         final StatisticsContextImpl<MultipartReply> statisticsContext = new StatisticsContextImpl<>(
75                 mockedDeviceContext, convertorManager,
76                 MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext),
77                 true, false, 3000, 50000);
78
79         final ListenableFuture<RpcResult<List<MultipartReply>>> rpcResult = immediateFuture(RpcResultBuilder
80                 .success(Collections.<MultipartReply>emptyList()).build());
81         when(mockedStatisticsGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
82                 .class))).thenReturn(rpcResult);
83         when(mockedStatisticsOnFlyGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
84                 .class))).thenReturn(rpcResult);
85
86         statisticsContext.registerMastershipWatcher(mockedMastershipWatcher);
87         statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService);
88         statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService);
89         statisticsContext.instantiateServiceInstance();
90
91         verify(mockedStatisticsGatheringService, times(7))
92                 .getStatisticsOfType(Matchers.any(EventIdentifier.class), Matchers.any(MultipartType.class));
93         verify(mockedStatisticsOnFlyGatheringService)
94                 .getStatisticsOfType(Matchers.any(EventIdentifier.class), Matchers.any(MultipartType.class));
95     }
96
97 }