Migrate openflowplugim-impl tests to uint types
[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.ArgumentMatchers.any;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
16 import static org.mockito.Mockito.when;
17
18 import com.google.common.util.concurrent.ListenableFuture;
19 import com.google.common.util.concurrent.MoreExecutors;
20 import java.util.Arrays;
21 import java.util.Collections;
22 import java.util.List;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.junit.runners.Parameterized;
27 import org.mockito.Mock;
28 import org.mockito.Mockito;
29 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
30 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProviderFactory;
31 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
32 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint32Type;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig;
37 import org.opendaylight.yangtools.yang.common.RpcResult;
38 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
39 import org.opendaylight.yangtools.yang.common.Uint32;
40
41 @RunWith(Parameterized.class)
42 public class StatisticsContextImplParamTest extends StatisticsContextImpMockInitiation {
43
44     @Mock
45     private final OpenflowProviderConfig config = mock(OpenflowProviderConfig.class);
46
47     public StatisticsContextImplParamTest(final boolean isTable, final boolean isFlow,
48                                           final boolean isGroup, final boolean isMeter,
49                                           final boolean isPort, final boolean isQueue) {
50         super();
51         this.isTable = isTable;
52         this.isFlow = isFlow;
53         this.isGroup = isGroup;
54         this.isMeter = isMeter;
55         this.isPort = isPort;
56         this.isQueue = isQueue;
57     }
58
59     @Parameterized.Parameters(name = "{index}")
60     public static Iterable<Object[]> data1() {
61         return Arrays.asList(new Object[][]{
62                 {false, true, false, false, false, false},
63                 {true, false, false, false, false, false},
64                 {false, false, true, false, false, false},
65                 {false, false, false, true, false, false},
66                 {false, false, false, false, true, false},
67                 {false, false, false, false, false, true},
68         });
69     }
70
71     @Before
72     public void setUp() {
73         Mockito.when(config.isIsTableStatisticsPollingOn()).thenReturn(true);
74         Mockito.when(config.isIsFlowStatisticsPollingOn()).thenReturn(true);
75         Mockito.when(config.isIsGroupStatisticsPollingOn()).thenReturn(true);
76         Mockito.when(config.isIsMeterStatisticsPollingOn()).thenReturn(true);
77         Mockito.when(config.isIsPortStatisticsPollingOn()).thenReturn(true);
78         Mockito.when(config.isIsQueueStatisticsPollingOn()).thenReturn(true);
79         Mockito.when(config.getBasicTimerDelay()).thenReturn(new NonZeroUint32Type(Uint32.valueOf(3000)));
80         Mockito.when(config.getMaximumTimerDelay()).thenReturn(new NonZeroUint32Type(Uint32.valueOf(50000)));
81     }
82
83     @Test
84     public void gatherDynamicDataTest() {
85
86         when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(Boolean.TRUE);
87         when(mockedDeviceState.isFlowStatisticsAvailable()).thenReturn(Boolean.TRUE);
88         when(mockedDeviceState.isGroupAvailable()).thenReturn(Boolean.TRUE);
89         when(mockedDeviceState.isMetersAvailable()).thenReturn(Boolean.TRUE);
90         when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(Boolean.TRUE);
91         when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(Boolean.TRUE);
92         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
93
94         final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
95         final StatisticsContextImpl<MultipartReply> statisticsContext = new StatisticsContextImpl<>(
96                 mockedDeviceContext, convertorManager,
97                 MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext),
98                 MoreExecutors.newDirectExecutorService(),
99                 config,
100                 true,
101                 false);
102
103         final ListenableFuture<RpcResult<List<MultipartReply>>> rpcResult = immediateFuture(RpcResultBuilder
104                 .success(Collections.<MultipartReply>emptyList()).build());
105         when(mockedStatisticsGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
106                 .class))).thenReturn(rpcResult);
107         when(mockedStatisticsOnFlyGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
108                 .class))).thenReturn(rpcResult);
109
110         statisticsContext.registerMastershipWatcher(mockedMastershipWatcher);
111         statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService);
112         statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService);
113         statisticsContext.initializeDevice();
114
115         verify(mockedStatisticsGatheringService, times(7))
116                 .getStatisticsOfType(any(EventIdentifier.class), any(MultipartType.class));
117         verify(mockedStatisticsOnFlyGatheringService)
118                 .getStatisticsOfType(any(EventIdentifier.class), any(MultipartType.class));
119     }
120
121 }