cf0149cd79ffea230d337755f76834bdb7e5be30
[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 import java.math.BigInteger;
21 import org.junit.Test;
22 import org.mockito.Matchers;
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.DeviceState;
26 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
30 import org.opendaylight.yangtools.yang.binding.RpcService;
31
32 public class MdSalRegistrationUtilsTest {
33
34     /**
35      * Number of currently registrated services (can be changed)
36      * (RpcContext, DeviceContext)}
37      */
38     private static final int NUMBER_OF_RPC_SERVICE_REGISTRATION = 13;
39
40     @Test
41     public void registerServiceTest() {
42
43         final RpcContext mockedRpcContext = mock(RpcContext.class);
44         final DeviceContext mockedDeviceContext = mock(DeviceContext.class);
45         final ConnectionContext mockedConnectionContext = mock(ConnectionContext.class);
46
47         final DeviceState mockedDeviceState = mock(DeviceState.class);
48         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
49
50         final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
51         when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
52
53         final GetFeaturesOutput mockedFeaturesOutput = mock(GetFeaturesOutput.class);
54         when(mockedDeviceState.getFeatures()).thenReturn(mockedFeaturesOutput);
55
56         final BigInteger mockedDataPathId = mock(BigInteger.class);
57         when(mockedFeatures.getDatapathId()).thenReturn(mockedDataPathId);
58         when(mockedFeaturesOutput.getDatapathId()).thenReturn(mockedDataPathId);
59
60         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
61         MdSalRegistrationUtils.registerMasterServices(mockedRpcContext, mockedDeviceContext, OfpRole.BECOMEMASTER);
62         verify(mockedRpcContext, times(NUMBER_OF_RPC_SERVICE_REGISTRATION)).registerRpcServiceImplementation(
63                 Matchers.<Class<RpcService>> any(), any(RpcService.class));
64     }
65
66 }