Optimized imports
[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.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.StatisticsManagerControlService;
34
35 @RunWith(MockitoJUnitRunner.class)
36 public class OpenFlowPluginProviderImplTest {
37
38     @Mock
39     DataBroker dataBroker;
40
41     @Mock
42     RpcProviderRegistry rpcProviderRegistry;
43
44     @Mock
45     NotificationService notificationService;
46
47     @Mock
48     WriteTransaction writeTransaction;
49
50     @Mock
51     EntityOwnershipService entityOwnershipService;
52
53     @Mock
54     EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
55
56     @Mock
57     BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
58
59     @Mock
60     SwitchConnectionProvider switchConnectionProvider;
61
62     private static final long RPC_REQUESTS_QUOTA = 500;
63     private static final long GLOBAL_NOTIFICATION_QUOTA = 131072;
64
65     private OpenFlowPluginProviderImpl provider;
66
67     @Before
68     public void setUp() throws Exception {
69         when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
70         when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
71         when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration);
72         when(rpcProviderRegistry.addRpcImplementation(eq(StatisticsManagerControlService.class), any())).thenReturn(controlServiceRegistration);
73         when(switchConnectionProvider.startup()).thenReturn(Futures.immediateCheckedFuture(null));
74
75         provider = new OpenFlowPluginProviderImpl(RPC_REQUESTS_QUOTA, GLOBAL_NOTIFICATION_QUOTA);
76         provider.setDataBroker(dataBroker);
77         provider.setRpcProviderRegistry(rpcProviderRegistry);
78         provider.setNotificationProviderService(notificationService);
79         provider.setEntityOwnershipService(entityOwnershipService);
80         provider.setSwitchConnectionProviders(Lists.newArrayList(switchConnectionProvider));
81     }
82
83     @After
84     public void tearDown() throws Exception {
85
86     }
87
88     @Test
89     public void testInitializeAndClose() throws Exception {
90         provider.initialize();
91         verify(switchConnectionProvider).startup();
92
93         provider.close();
94         verify(entityOwnershipListenerRegistration, times(2)).close();
95     }
96 }