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