2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.impl;
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;
34 @RunWith(MockitoJUnitRunner.class)
35 public class OpenFlowPluginProviderImplTest {
38 DataBroker dataBroker;
41 RpcProviderRegistry rpcProviderRegistry;
44 NotificationService notificationService;
47 WriteTransaction writeTransaction;
50 EntityOwnershipService entityOwnershipService;
53 EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
56 BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
59 SwitchConnectionProvider switchConnectionProvider;
61 private static final long RPC_REQUESTS_QUOTA = 500;
62 private static final long GLOBAL_NOTIFICATION_QUOTA = 131072;
64 private OpenFlowPluginProviderImpl provider;
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));
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));
83 public void tearDown() throws Exception {
88 public void testInitializeAndClose() throws Exception {
89 provider.initialize();
90 verify(switchConnectionProvider).startup();
93 verify(entityOwnershipListenerRegistration, times(2)).close();