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.Mockito.*;
12 import static org.junit.Assert.*;
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;
32 @RunWith(MockitoJUnitRunner.class)
33 public class OpenFlowPluginProviderImplTest {
36 DataBroker dataBroker;
39 RpcProviderRegistry rpcProviderRegistry;
42 NotificationService notificationService;
45 WriteTransaction writeTransaction;
48 EntityOwnershipService entityOwnershipService;
51 EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
54 BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
57 SwitchConnectionProvider switchConnectionProvider;
59 private static final long RPC_REQUESTS_QUOTA = 500;
60 private static final long GLOBAL_NOTIFICATION_QUOTA = 131072;
62 private OpenFlowPluginProviderImpl provider;
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));
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));
81 public void tearDown() throws Exception {
86 public void testInitializeAndClose() throws Exception {
87 provider.initialize();
88 verify(switchConnectionProvider).startup();
91 verify(entityOwnershipListenerRegistration, times(2)).close();