Merge "Bug 6050 - TcpSrcCodec is not maskable"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / util / MdSalRegistrationUtilsTest.java
1 /*
2  *
3  *  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
4  *  *
5  *  * This program and the accompanying materials are made available under the
6  *  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  *
9  *
10  */
11
12 package org.opendaylight.openflowplugin.impl.util;
13
14
15 import static org.mockito.Matchers.any;
16 import static org.mockito.Mockito.mock;
17 import static org.mockito.Mockito.times;
18 import static org.mockito.Mockito.verify;
19 import static org.mockito.Mockito.when;
20
21 import java.math.BigInteger;
22 import org.junit.Test;
23 import org.mockito.Matchers;
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.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
32 import org.opendaylight.yangtools.yang.binding.RpcService;
33
34 public class MdSalRegistrationUtilsTest {
35
36     /**
37      * Number of currently registrated services (can be changed)
38      * (RpcContext, DeviceContext)}
39      */
40     private static final int NUMBER_OF_RPC_SERVICE_REGISTRATION = 13;
41
42     @Test
43     public void registerServiceTest() {
44
45         final RpcContext mockedRpcContext = mock(RpcContext.class);
46         final DeviceContext mockedDeviceContext = mock(DeviceContext.class);
47         final ConnectionContext mockedConnectionContext = mock(ConnectionContext.class);
48
49         final DeviceState mockedDeviceState = mock(DeviceState.class);
50         final DeviceInfo mockedDeviceInfo = mock(DeviceInfo.class);
51         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
52         when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
53
54         final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
55         when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
56
57         final BigInteger mockedDataPathId = mock(BigInteger.class);
58         when(mockedFeatures.getDatapathId()).thenReturn(mockedDataPathId);
59         when(mockedDeviceInfo.getDatapathId()).thenReturn(mockedDataPathId);
60
61         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
62
63         final ExtensionConverterProvider extensionConverterProvider = mock(ExtensionConverterProvider.class);
64         MdSalRegistrationUtils.registerMasterServices(mockedRpcContext, mockedDeviceContext, OfpRole.BECOMEMASTER, extensionConverterProvider);
65         verify(mockedRpcContext, times(NUMBER_OF_RPC_SERVICE_REGISTRATION)).registerRpcServiceImplementation(
66                 Matchers.<Class<RpcService>> any(), any(RpcService.class));
67     }
68
69 }