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.api.openflow.device;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
15 import java.util.Iterator;
16 import java.util.concurrent.Future;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mock;
21 import org.mockito.runners.MockitoJUnitRunner;
22 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
23 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
24 import org.opendaylight.openflowplugin.impl.rpc.RpcContextImpl;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
32 import org.opendaylight.yangtools.yang.common.RpcError;
33 import org.opendaylight.yangtools.yang.common.RpcResult;
38 @RunWith(MockitoJUnitRunner.class)
39 public class RpcContextImplTest {
42 private BindingAwareBroker.ProviderContext mockedRpcProviderRegistry;
45 private DeviceContext deviceContext;
47 private RpcContext rpcContext;
49 private static final String QUEUE_IS_FULL = "Device's request queue is full.";
53 NodeId nodeId = new NodeId("openflow:1");
54 KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
56 rpcContext = new RpcContextImpl(mockedRpcProviderRegistry, nodeInstanceIdentifier);
60 public void invokeRpcTest() {
65 public void testStoreOrFail() throws Exception {
66 RequestContext requestContext = rpcContext.createRequestContext();
67 rpcContext.setRequestContextQuota(100);
68 Future<RpcResult<UpdateFlowOutput>> resultFuture = rpcContext.storeOrFail(requestContext);
69 assertNotNull(resultFuture);
70 assertFalse(resultFuture.isDone());
74 public void testStoreOrFailThatFails() throws Exception {
75 RequestContext requestContext = rpcContext.createRequestContext();
76 rpcContext.setRequestContextQuota(0);
77 Future<RpcResult<UpdateFlowOutput>> resultFuture = rpcContext.storeOrFail(requestContext);
78 assertNotNull(resultFuture);
79 assertTrue(resultFuture.isDone());
80 RpcResult<UpdateFlowOutput> updateFlowOutputRpcResult = resultFuture.get();
81 assertNotNull(updateFlowOutputRpcResult);
82 assertEquals(1, updateFlowOutputRpcResult.getErrors().size());
83 Iterator<RpcError> iterator = updateFlowOutputRpcResult.getErrors().iterator();
84 assertEquals(QUEUE_IS_FULL, iterator.next().getMessage());