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.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
34 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
35 import org.opendaylight.yangtools.yang.binding.RpcService;
37 @RunWith(MockitoJUnitRunner.class)
38 public class RpcManagerImplTest {
40 private static final int AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC = 11;
42 private RpcManagerImpl rpcManager;
44 private ProviderContext rpcProviderRegistry;
46 private DeviceContext deviceContext;
48 private DeviceInitializationPhaseHandler deviceINitializationPhaseHandler;
50 private ConnectionContext connectionContext;
52 private BindingAwareBroker.RoutedRpcRegistration<RpcService> routedRpcRegistration;
54 private DeviceState deviceState;
56 private ItemLifeCycleRegistry itemLifeCycleRegistry;
58 private KeyedInstanceIdentifier<Node, NodeKey> nodePath;
62 nodePath = KeyedInstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow-junit:1")));
63 rpcManager = new RpcManagerImpl(rpcProviderRegistry, 5);
64 rpcManager.setDeviceInitializationPhaseHandler(deviceINitializationPhaseHandler);
65 FeaturesReply features = new GetFeaturesOutputBuilder()
66 .setVersion(OFConstants.OFP_VERSION_1_3)
68 Mockito.when(connectionContext.getFeatures()).thenReturn(features);
69 Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
70 Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
71 Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry);
72 Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodePath);
76 public void testOnDeviceContextLevelUp() {
78 Mockito.when(rpcProviderRegistry.addRoutedRpcImplementation(
79 Matchers.<Class<RpcService>>any(), Matchers.any(RpcService.class)))
80 .thenReturn(routedRpcRegistration);
82 rpcManager.onDeviceContextLevelUp(deviceContext);
84 Mockito.verify(rpcProviderRegistry, times(AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC)).addRoutedRpcImplementation(
85 Matchers.<Class<RpcService>>any(), Matchers.any(RpcService.class));
86 Mockito.verify(routedRpcRegistration, times(AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC)).registerPath(
87 NodeContext.class, nodePath);
88 Mockito.verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceContext);