2 * Copyright (c) 2015 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.util;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.times;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.Mockito.when;
16 import java.math.BigInteger;
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.NotificationPublishService;
23 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
24 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
25 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
26 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
27 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
28 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
29 import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightFlowStatisticsServiceImpl;
30 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
31 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
34 import org.opendaylight.yangtools.yang.binding.RpcService;
36 @RunWith(MockitoJUnitRunner.class)
37 public class MdSalRegistrationUtilsTest {
40 * Number of currently registrated services (can be changed)
41 * (RpcContext, DeviceContext)}.
43 private static final int NUMBER_OF_RPC_SERVICE_REGISTRATION = 16;
44 private static final int NUMBER_OF_STAT_COMPAT_RPC_SERVICE_REGISTRATION = 5;
47 private RpcContext mockedRpcContext;
49 private DeviceContext mockedDeviceContext;
51 private ConnectionContext mockedConnectionContext;
53 private DeviceState mockedDeviceState;
55 private DeviceInfo mockedDeviceInfo;
57 private FeaturesReply mockedFeatures;
59 private BigInteger mockedDataPathId;
61 private ExtensionConverterProvider extensionConverterProvider;
63 private NotificationPublishService notificationPublishService;
65 private ConvertorManager convertorManager;
68 public void setUp() throws Exception {
69 convertorManager = ConvertorManagerFactory.createDefaultManager();
70 when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
71 when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
72 when(mockedDeviceInfo.getDatapathId()).thenReturn(mockedDataPathId);
73 when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
77 public void registerServiceTest() {
78 MdSalRegistrationUtils.registerServices(mockedRpcContext,
80 extensionConverterProvider,
82 verify(mockedRpcContext, times(NUMBER_OF_RPC_SERVICE_REGISTRATION)).registerRpcServiceImplementation(
83 any(), any(RpcService.class));
87 public void registerStatCompatibilityServices() throws Exception {
88 final OpendaylightFlowStatisticsService flowStatService = OpendaylightFlowStatisticsServiceImpl
89 .createWithOook(mockedRpcContext, mockedDeviceContext, convertorManager);
91 when(mockedRpcContext.lookupRpcService(OpendaylightFlowStatisticsService.class)).thenReturn(
93 MdSalRegistrationUtils.registerStatCompatibilityServices(mockedRpcContext,
95 notificationPublishService,
97 verify(mockedRpcContext, times(NUMBER_OF_STAT_COMPAT_RPC_SERVICE_REGISTRATION))
98 .registerRpcServiceImplementation(any(), any(RpcService.class));