Merge "Drop the odlparent.netty property"
[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.Matchers.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.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;
36
37 @RunWith(MockitoJUnitRunner.class)
38 public class MdSalRegistrationUtilsTest {
39
40     /**
41      * Number of currently registrated services (can be changed)
42      * (RpcContext, DeviceContext)}.
43      */
44     private static final int NUMBER_OF_RPC_SERVICE_REGISTRATION = 15;
45     private static final int NUMBER_OF_STAT_COMPAT_RPC_SERVICE_REGISTRATION = 5;
46
47     @Mock
48     private RpcContext mockedRpcContext;
49     @Mock
50     private DeviceContext mockedDeviceContext;
51     @Mock
52     private ConnectionContext mockedConnectionContext;
53     @Mock
54     private DeviceState mockedDeviceState;
55     @Mock
56     private DeviceInfo mockedDeviceInfo;
57     @Mock
58     private FeaturesReply mockedFeatures;
59     @Mock
60     private BigInteger mockedDataPathId;
61     @Mock
62     private ExtensionConverterProvider extensionConverterProvider;
63     @Mock
64     private NotificationPublishService notificationPublishService;
65
66     private ConvertorManager convertorManager;
67
68     @Before
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);
77     }
78
79     @Test
80     public void registerServiceTest() {
81         MdSalRegistrationUtils.registerServices(mockedRpcContext,
82                                                 mockedDeviceContext,
83                                                 extensionConverterProvider,
84                                                 convertorManager);
85         verify(mockedRpcContext, times(NUMBER_OF_RPC_SERVICE_REGISTRATION)).registerRpcServiceImplementation(
86                 Matchers.any(), any(RpcService.class));
87     }
88
89     @Test
90     public void registerStatCompatibilityServices() throws Exception {
91         final OpendaylightFlowStatisticsService flowStatService = OpendaylightFlowStatisticsServiceImpl
92                 .createWithOook(mockedRpcContext, mockedDeviceContext, convertorManager);
93
94         when(mockedRpcContext.lookupRpcService(OpendaylightFlowStatisticsService.class)).thenReturn(
95                 flowStatService);
96         MdSalRegistrationUtils.registerStatCompatibilityServices(mockedRpcContext,
97                                                                  mockedDeviceContext,
98                                                                  notificationPublishService,
99                                                                  convertorManager);
100         verify(mockedRpcContext, times(NUMBER_OF_STAT_COMPAT_RPC_SERVICE_REGISTRATION))
101                 .registerRpcServiceImplementation(Matchers.any(), any(RpcService.class));
102     }
103
104 }