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