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.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.atLeastOnce;
12 import static org.mockito.Mockito.verify;
14 import java.util.concurrent.ConcurrentMap;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
22 import org.opendaylight.mdsal.binding.api.RpcProviderService;
23 import org.opendaylight.openflowplugin.api.OFConstants;
24 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
25 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
26 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
27 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
28 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
29 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
30 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
31 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint16Type;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfigBuilder;
39 import org.opendaylight.yangtools.concepts.ObjectRegistration;
40 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
41 import org.opendaylight.yangtools.yang.binding.RpcService;
43 @RunWith(MockitoJUnitRunner.class)
44 public class RpcManagerImplTest {
46 private static final int QUOTA_VALUE = 5;
47 private RpcManagerImpl rpcManager;
50 private RpcProviderService rpcProviderRegistry;
52 private DeviceContext deviceContext;
54 private ObjectRegistration<RpcService> routedRpcRegistration;
56 private DeviceState deviceState;
58 private ConnectionContext connectionContext;
60 private MessageSpy messageSpy;
62 private RpcContext removedContexts;
64 private ConcurrentMap<DeviceInfo, RpcContext> contexts;
66 private DeviceInfo deviceInfo;
68 private ExtensionConverterProvider extensionConverterProvider;
70 private ConvertorExecutor convertorExecutor;
72 private NotificationPublishService notificationPublishService;
74 private KeyedInstanceIdentifier<Node, NodeKey> nodePath;
76 private final NodeId nodeId = new NodeId("openflow-junit:1");
80 final NodeKey nodeKey = new NodeKey(nodeId);
81 rpcManager = new RpcManagerImpl(new OpenflowProviderConfigBuilder()
82 .setRpcRequestsQuota(new NonZeroUint16Type(QUOTA_VALUE))
83 .setIsStatisticsRpcEnabled(false)
85 rpcProviderRegistry, extensionConverterProvider, convertorExecutor, notificationPublishService);
87 FeaturesReply features = new GetFeaturesOutputBuilder()
88 .setVersion(OFConstants.OFP_VERSION_1_3)
91 Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
92 Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
93 Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
97 public void createContext() {
98 final RpcContext context = rpcManager.createContext(deviceContext);
99 assertEquals(deviceInfo, context.getDeviceInfo());
103 public void close() {
104 rpcManager.addRecordToContexts(deviceInfo,removedContexts);
106 verify(removedContexts,atLeastOnce()).close();