Switch to MD-SAL APIs
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / util / MdSalRegistrationUtilsTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.impl.util;
10
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;
15
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.junit.MockitoJUnitRunner;
22 import org.opendaylight.mdsal.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;
35
36 @RunWith(MockitoJUnitRunner.class)
37 public class MdSalRegistrationUtilsTest {
38
39     /**
40      * Number of currently registrated services (can be changed)
41      * (RpcContext, DeviceContext)}.
42      */
43     private static final int NUMBER_OF_RPC_SERVICE_REGISTRATION = 16;
44     private static final int NUMBER_OF_STAT_COMPAT_RPC_SERVICE_REGISTRATION = 5;
45
46     @Mock
47     private RpcContext mockedRpcContext;
48     @Mock
49     private DeviceContext mockedDeviceContext;
50     @Mock
51     private ConnectionContext mockedConnectionContext;
52     @Mock
53     private DeviceState mockedDeviceState;
54     @Mock
55     private DeviceInfo mockedDeviceInfo;
56     @Mock
57     private FeaturesReply mockedFeatures;
58     @Mock
59     private BigInteger mockedDataPathId;
60     @Mock
61     private ExtensionConverterProvider extensionConverterProvider;
62     @Mock
63     private NotificationPublishService notificationPublishService;
64
65     private ConvertorManager convertorManager;
66
67     @Before
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);
74     }
75
76     @Test
77     public void registerServiceTest() {
78         MdSalRegistrationUtils.registerServices(mockedRpcContext,
79                                                 mockedDeviceContext,
80                                                 extensionConverterProvider,
81                                                 convertorManager);
82         verify(mockedRpcContext, times(NUMBER_OF_RPC_SERVICE_REGISTRATION)).registerRpcServiceImplementation(
83                 any(), any(RpcService.class));
84     }
85
86     @Test
87     public void registerStatCompatibilityServices() throws Exception {
88         final OpendaylightFlowStatisticsService flowStatService = OpendaylightFlowStatisticsServiceImpl
89                 .createWithOook(mockedRpcContext, mockedDeviceContext, convertorManager);
90
91         when(mockedRpcContext.lookupRpcService(OpendaylightFlowStatisticsService.class)).thenReturn(
92                 flowStatService);
93         MdSalRegistrationUtils.registerStatCompatibilityServices(mockedRpcContext,
94                                                                  mockedDeviceContext,
95                                                                  notificationPublishService,
96                                                                  convertorManager);
97         verify(mockedRpcContext, times(NUMBER_OF_STAT_COMPAT_RPC_SERVICE_REGISTRATION))
98                 .registerRpcServiceImplementation(any(), any(RpcService.class));
99     }
100
101 }