2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.impl.rpc;
10 import static org.mockito.Mockito.times;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.mockito.Matchers;
16 import org.mockito.Mock;
17 import org.mockito.Mockito;
18 import org.mockito.runners.MockitoJUnitRunner;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
21 import org.opendaylight.openflowplugin.api.OFConstants;
22 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
23 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
24 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
25 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
33 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
34 import org.opendaylight.yangtools.yang.binding.RpcService;
36 @RunWith(MockitoJUnitRunner.class)
37 public class RpcManagerImplTest {
39 private static final int AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC = 9;
41 private RpcManagerImpl rpcManager;
43 private ProviderContext rpcProviderRegistry;
45 private DeviceContext deviceContext;
47 private DeviceInitializationPhaseHandler deviceINitializationPhaseHandler;
49 private ConnectionContext connectionContext;
51 private BindingAwareBroker.RoutedRpcRegistration<RpcService> routedRpcRegistration;
53 private DeviceState deviceState;
54 private KeyedInstanceIdentifier<Node, NodeKey> nodePath;
58 nodePath = KeyedInstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow-junit:1")));
59 rpcManager = new RpcManagerImpl(rpcProviderRegistry, 5);
60 rpcManager.setDeviceInitializationPhaseHandler(deviceINitializationPhaseHandler);
61 FeaturesReply features = new GetFeaturesOutputBuilder()
62 .setVersion(OFConstants.OFP_VERSION_1_3)
64 Mockito.when(connectionContext.getFeatures()).thenReturn(features);
65 Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
66 Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
67 Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodePath);
71 public void testOnDeviceContextLevelUp() {
73 Mockito.when(rpcProviderRegistry.addRoutedRpcImplementation(
74 Matchers.<Class<RpcService>>any(), Matchers.any(RpcService.class)))
75 .thenReturn(routedRpcRegistration);
77 rpcManager.onDeviceContextLevelUp(deviceContext);
79 Mockito.verify(rpcProviderRegistry, times(AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC)).addRoutedRpcImplementation(
80 Matchers.<Class<RpcService>>any(), Matchers.any(RpcService.class));
81 Mockito.verify(routedRpcRegistration, times(AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC)).registerPath(
82 NodeContext.class, nodePath);
83 Mockito.verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceContext);