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.Matchers.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.Matchers;
21 import org.mockito.Mock;
22 import org.mockito.runners.MockitoJUnitRunner;
23 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
24 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
25 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
26 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
27 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
28 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
29 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
30 import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightFlowStatisticsServiceImpl;
31 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
32 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
35 import org.opendaylight.yangtools.yang.binding.RpcService;
37 @RunWith(MockitoJUnitRunner.class)
38 public class MdSalRegistrationUtilsTest {
41 * Number of currently registrated services (can be changed)
42 * (RpcContext, DeviceContext)}.
44 private static final int NUMBER_OF_RPC_SERVICE_REGISTRATION = 15;
45 private static final int NUMBER_OF_STAT_COMPAT_RPC_SERVICE_REGISTRATION = 5;
48 private RpcContext mockedRpcContext;
50 private DeviceContext mockedDeviceContext;
52 private ConnectionContext mockedConnectionContext;
54 private DeviceState mockedDeviceState;
56 private DeviceInfo mockedDeviceInfo;
58 private FeaturesReply mockedFeatures;
60 private BigInteger mockedDataPathId;
62 private ExtensionConverterProvider extensionConverterProvider;
64 private NotificationPublishService notificationPublishService;
66 private ConvertorManager convertorManager;
69 public void setUp() throws Exception {
70 convertorManager = ConvertorManagerFactory.createDefaultManager();
71 when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
72 when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
73 when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
74 when(mockedFeatures.getDatapathId()).thenReturn(mockedDataPathId);
75 when(mockedDeviceInfo.getDatapathId()).thenReturn(mockedDataPathId);
76 when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
80 public void registerServiceTest() {
81 MdSalRegistrationUtils.registerServices(mockedRpcContext,
83 extensionConverterProvider,
85 verify(mockedRpcContext, times(NUMBER_OF_RPC_SERVICE_REGISTRATION)).registerRpcServiceImplementation(
86 Matchers.any(), any(RpcService.class));
90 public void registerStatCompatibilityServices() throws Exception {
91 final OpendaylightFlowStatisticsService flowStatService = OpendaylightFlowStatisticsServiceImpl
92 .createWithOook(mockedRpcContext, mockedDeviceContext, convertorManager);
94 when(mockedRpcContext.lookupRpcService(OpendaylightFlowStatisticsService.class)).thenReturn(
96 MdSalRegistrationUtils.registerStatCompatibilityServices(mockedRpcContext,
98 notificationPublishService,
100 verify(mockedRpcContext, times(NUMBER_OF_STAT_COMPAT_RPC_SERVICE_REGISTRATION))
101 .registerRpcServiceImplementation(Matchers.any(), any(RpcService.class));