Merge "Quick fix RPCs and DevicCtx.close"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / util / MdSalRegistratorUtilsTest.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.Mockito.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.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
24 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
25 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
28 import org.opendaylight.yangtools.yang.binding.RpcService;
29
30 public class MdSalRegistratorUtilsTest {
31
32     /**
33      * Number of currently registrated services (can be changed) in {@link MdSalRegistratorUtils#registerMasterServices
34      * (RpcContext, DeviceContext)}
35      */
36     private static final int NUMBER_OF_RPC_SERVICE_REGISTRATION = 11;
37
38     @Test
39     public void registerServiceTest() {
40
41         final RpcContext mockedRpcContext = mock(RpcContext.class);
42         final DeviceContext mockedDeviceContext = mock(DeviceContext.class);
43         final ConnectionContext mockedConnectionContext = mock(ConnectionContext.class);
44
45         final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
46         when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
47
48         final BigInteger mockedDataPathId = mock(BigInteger.class);
49         when(mockedFeatures.getDatapathId()).thenReturn(mockedDataPathId);
50
51         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
52         MdSalRegistratorUtils.registerMasterServices(mockedRpcContext,mockedDeviceContext, OfpRole.BECOMEMASTER);
53         verify(mockedRpcContext, times(NUMBER_OF_RPC_SERVICE_REGISTRATION)).registerRpcServiceImplementation(any
54                         (RpcService.class.getClass()), any(RpcService.class));
55     }
56
57 }