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 com.google.common.base.VerifyException;
11 import org.junit.Before;
12 import org.junit.Rule;
13 import org.junit.Test;
14 import org.junit.rules.ExpectedException;
15 import org.junit.runner.RunWith;
16 import org.mockito.Matchers;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
21 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
22 import org.opendaylight.openflowplugin.api.OFConstants;
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.DeviceManager;
26 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
27 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
28 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
29 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
30 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
31 import org.opendaylight.openflowplugin.impl.LifecycleConductorImpl;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
39 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
40 import org.opendaylight.yangtools.yang.binding.RpcService;
42 @RunWith(MockitoJUnitRunner.class)
43 public class RpcManagerImplTest {
45 private static final int QUOTA_VALUE = 5;
46 private RpcManagerImpl rpcManager;
49 private ProviderContext rpcProviderRegistry;
51 private DeviceContext deviceContext;
53 private DeviceInitializationPhaseHandler deviceINitializationPhaseHandler;
55 private DeviceState deviceState;
57 private MessageSpy mockMsgSpy;
59 private LifecycleConductor conductor;
62 public ExpectedException expectedException = ExpectedException.none();
64 private KeyedInstanceIdentifier<Node, NodeKey> nodePath;
66 private NodeId nodeId = new NodeId("openflow-junit:1");
70 final NodeKey nodeKey = new NodeKey(nodeId);
71 rpcManager = new RpcManagerImpl(rpcProviderRegistry, QUOTA_VALUE, conductor);
72 rpcManager.setDeviceInitializationPhaseHandler(deviceINitializationPhaseHandler);
73 Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
74 Mockito.when(deviceContext.getMessageSpy()).thenReturn(mockMsgSpy);
75 Mockito.when(deviceState.getNodeId()).thenReturn(nodeKey.getId());
76 Mockito.when(conductor.getDeviceContext(Mockito.<NodeId>any())).thenReturn(deviceContext);
80 public void onDeviceContextLevelUp() throws Exception {
81 rpcManager.onDeviceContextLevelUp(nodeId);
82 Mockito.verify(conductor).getDeviceContext(Mockito.<NodeId>any());
86 public void onDeviceContextLevelUpTwice() throws Exception {
87 rpcManager.onDeviceContextLevelUp(nodeId);
88 expectedException.expect(VerifyException.class);
89 rpcManager.onDeviceContextLevelUp(nodeId);