ee0efbd500237c180459d8aad2808b7543bfe85a
[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.times;
14 import static org.mockito.Mockito.verify;
15 import static org.mockito.Mockito.when;
16
17 import com.google.common.collect.Lists;
18 import com.google.common.util.concurrent.Futures;
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.mockito.Mock;
24 import org.mockito.runners.MockitoJUnitRunner;
25 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
26 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
27 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
28 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
29 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
30 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
31 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
32 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
33 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.StatisticsManagerControlService;
35
36 @RunWith(MockitoJUnitRunner.class)
37 public class OpenFlowPluginProviderImplTest {
38
39     @Mock
40     DataBroker dataBroker;
41
42     @Mock
43     RpcProviderRegistry rpcProviderRegistry;
44
45     @Mock
46     NotificationService notificationService;
47
48     @Mock
49     WriteTransaction writeTransaction;
50
51     @Mock
52     EntityOwnershipService entityOwnershipService;
53
54     @Mock
55     EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
56
57     @Mock
58     BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
59
60     @Mock
61     SwitchConnectionProvider switchConnectionProvider;
62
63     @Mock
64     ClusterSingletonServiceProvider clusterSingletonServiceProvider;
65
66     private static final long RPC_REQUESTS_QUOTA = 500;
67     private static final long GLOBAL_NOTIFICATION_QUOTA = 131072;
68     private static final int THREAD_POOL_MIN_THREADS = 1;
69     private static final int THREAD_POOL_MAX_THREADS = 32000;
70     private static final long THREAD_POOL_TIMEOUT = 60;
71
72     private OpenFlowPluginProviderImpl provider;
73
74     @Before
75     public void setUp() throws Exception {
76         when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
77         when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
78         when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration);
79         when(rpcProviderRegistry.addRpcImplementation(eq(StatisticsManagerControlService.class), any())).thenReturn(controlServiceRegistration);
80         when(switchConnectionProvider.startup()).thenReturn(Futures.immediateCheckedFuture(null));
81
82         provider = new OpenFlowPluginProviderImpl(
83                 RPC_REQUESTS_QUOTA,
84                 GLOBAL_NOTIFICATION_QUOTA,
85                 THREAD_POOL_MIN_THREADS,
86                 THREAD_POOL_MAX_THREADS,
87                 THREAD_POOL_TIMEOUT);
88
89         provider.setDataBroker(dataBroker);
90         provider.setRpcProviderRegistry(rpcProviderRegistry);
91         provider.setNotificationProviderService(notificationService);
92         provider.setEntityOwnershipService(entityOwnershipService);
93         provider.setSwitchConnectionProviders(Lists.newArrayList(switchConnectionProvider));
94         provider.setClusteringSingletonServicesProvider(clusterSingletonServiceProvider);
95     }
96
97     @After
98     public void tearDown() throws Exception {
99
100     }
101
102     @Test
103     public void testInitializeAndClose() throws Exception {
104         provider.initialize();
105         verify(switchConnectionProvider).startup();
106     }
107 }