Extract mastership blueprint service
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / OpenFlowPluginProviderImplTest.java
1 /*
2  * Copyright (c) 2016 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;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Matchers.eq;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.Mockito.when;
15
16 import com.google.common.collect.Lists;
17 import com.google.common.util.concurrent.Futures;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Mock;
22 import org.mockito.runners.MockitoJUnitRunner;
23 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
24 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
25 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
26 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
27 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
28 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
29 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
30 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
31 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
32 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty;
33 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
34 import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.StatisticsManagerControlService;
36
37 @RunWith(MockitoJUnitRunner.class)
38 public class OpenFlowPluginProviderImplTest {
39
40     @Mock
41     DataBroker dataBroker;
42
43     @Mock
44     RpcProviderRegistry rpcProviderRegistry;
45
46     @Mock
47     NotificationPublishService notificationPublishService;
48
49     @Mock
50     WriteTransaction writeTransaction;
51
52     @Mock
53     EntityOwnershipService entityOwnershipService;
54
55     @Mock
56     EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
57
58     @Mock
59     BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
60
61     @Mock
62     SwitchConnectionProvider switchConnectionProvider;
63
64     @Mock
65     ClusterSingletonServiceProvider clusterSingletonServiceProvider;
66
67     @Mock
68     ConfigurationService configurationService;
69
70     @Mock
71     MastershipChangeServiceManager mastershipChangeServiceManager;
72
73     private static final int RPC_REQUESTS_QUOTA = 500;
74     private static final long GLOBAL_NOTIFICATION_QUOTA = 131072;
75     private static final int THREAD_POOL_MIN_THREADS = 1;
76     private static final int THREAD_POOL_MAX_THREADS = 32000;
77     private static final long THREAD_POOL_TIMEOUT = 60;
78     private static final long BASIC_TIMER_DELAY = 1L;
79     private static final boolean USE_SINGLE_LAYER_SERIALIZATION = false;
80
81     private OpenFlowPluginProviderImpl provider;
82
83     @Before
84     public void setUp() throws Exception {
85         when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
86         when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
87         when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration);
88         when(rpcProviderRegistry.addRpcImplementation(eq(StatisticsManagerControlService.class), any())).thenReturn(controlServiceRegistration);
89         when(switchConnectionProvider.startup()).thenReturn(Futures.immediateCheckedFuture(null));
90         when(configurationService.getProperty(eq(ConfigurationProperty.USE_SINGLE_LAYER_SERIALIZATION.toString()), any())).thenReturn(USE_SINGLE_LAYER_SERIALIZATION);
91         when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString()), any())).thenReturn(THREAD_POOL_MIN_THREADS);
92         when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString()), any())).thenReturn(THREAD_POOL_MAX_THREADS);
93         when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_TIMEOUT.toString()), any())).thenReturn(THREAD_POOL_TIMEOUT);
94         when(configurationService.getProperty(eq(ConfigurationProperty.RPC_REQUESTS_QUOTA.toString()), any())).thenReturn(RPC_REQUESTS_QUOTA);
95         when(configurationService.getProperty(eq(ConfigurationProperty.GLOBAL_NOTIFICATION_QUOTA.toString()), any())).thenReturn(GLOBAL_NOTIFICATION_QUOTA);
96         when(configurationService.getProperty(eq(ConfigurationProperty.BASIC_TIMER_DELAY.toString()), any())).thenReturn(BASIC_TIMER_DELAY);
97
98         provider = new OpenFlowPluginProviderImpl(
99                 configurationService,
100                 Lists.newArrayList(switchConnectionProvider),
101                 dataBroker,
102                 rpcProviderRegistry,
103                 notificationPublishService,
104                 clusterSingletonServiceProvider,
105                 entityOwnershipService,
106                 mastershipChangeServiceManager);
107     }
108
109     @Test
110     public void testInitializeAndClose() throws Exception {
111         provider.initialize();
112         verify(switchConnectionProvider).startup();
113     }
114 }