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;
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;
35 @RunWith(MockitoJUnitRunner.class)
36 public class OpenFlowPluginProviderImplTest {
39 DataBroker dataBroker;
42 RpcProviderRegistry rpcProviderRegistry;
45 NotificationService notificationService;
48 WriteTransaction writeTransaction;
51 EntityOwnershipService entityOwnershipService;
54 EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
57 BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
60 SwitchConnectionProvider switchConnectionProvider;
62 private static final long RPC_REQUESTS_QUOTA = 500;
63 private static final long GLOBAL_NOTIFICATION_QUOTA = 131072;
65 private OpenFlowPluginProviderImpl provider;
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));
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));
84 public void tearDown() throws Exception {
89 public void testInitializeAndClose() throws Exception {
90 provider.initialize();
91 verify(switchConnectionProvider).startup();
94 verify(entityOwnershipListenerRegistration, times(2)).close();