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.atLeastOnce;
11 import static org.mockito.Mockito.verify;
13 import java.util.concurrent.ConcurrentMap;
14 import org.junit.Before;
15 import org.junit.Rule;
16 import org.junit.Test;
17 import org.junit.rules.ExpectedException;
18 import org.junit.runner.RunWith;
19 import org.mockito.Matchers;
20 import org.mockito.Mock;
21 import org.mockito.Mockito;
22 import org.mockito.runners.MockitoJUnitRunner;
23 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
24 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
25 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
26 import org.opendaylight.openflowplugin.api.OFConstants;
27 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
28 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
29 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
30 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
31 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
32 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
33 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
34 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
35 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint16Type;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfigBuilder;
44 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
45 import org.opendaylight.yangtools.yang.binding.RpcService;
48 @RunWith(MockitoJUnitRunner.class)
49 public class RpcManagerImplTest {
51 private static final int QUOTA_VALUE = 5;
52 private RpcManagerImpl rpcManager;
55 private ProviderContext rpcProviderRegistry;
57 private DeviceContext deviceContext;
59 private BindingAwareBroker.RoutedRpcRegistration<RpcService> routedRpcRegistration;
61 private DeviceState deviceState;
63 private ConnectionContext connectionContext;
65 private ItemLifeCycleRegistry itemLifeCycleRegistry;
67 private MessageSpy messageSpy;
69 private RpcContext removedContexts;
71 private ConcurrentMap<DeviceInfo, RpcContext> contexts;
73 private DeviceInfo deviceInfo;
75 private ExtensionConverterProvider extensionConverterProvider;
77 private ConvertorExecutor convertorExecutor;
79 private NotificationPublishService notificationPublishService;
82 public ExpectedException expectedException = ExpectedException.none();
84 private KeyedInstanceIdentifier<Node, NodeKey> nodePath;
86 private NodeId nodeId = new NodeId("openflow-junit:1");
90 final NodeKey nodeKey = new NodeKey(nodeId);
91 rpcManager = new RpcManagerImpl(new OpenflowProviderConfigBuilder()
92 .setRpcRequestsQuota(new NonZeroUint16Type(QUOTA_VALUE))
93 .build(), rpcProviderRegistry, extensionConverterProvider, convertorExecutor, notificationPublishService);
95 GetFeaturesOutput featuresOutput = new GetFeaturesOutputBuilder()
96 .setVersion(OFConstants.OFP_VERSION_1_3)
99 FeaturesReply features = featuresOutput;
101 Mockito.when(connectionContext.getFeatures()).thenReturn(features);
102 Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
103 Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
104 Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry);
105 Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
106 Mockito.when(connectionContext.getFeatures()).thenReturn(features);
107 Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
108 Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
109 Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry);
110 Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
111 Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
112 Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeKey.getId());
113 Mockito.when(rpcProviderRegistry.addRoutedRpcImplementation(
114 Matchers.any(), Matchers.any(RpcService.class)))
115 .thenReturn(routedRpcRegistration);
116 Mockito.when(contexts.remove(deviceInfo)).thenReturn(removedContexts);
120 public void close() {
121 rpcManager.addRecordToContexts(deviceInfo,removedContexts);
123 verify(removedContexts,atLeastOnce()).close();