RpcContext doesn't hold referrence to DeviceContext anymore
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / api / openflow / device / RpcContextImplTest.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.api.openflow.device;
9
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;
14
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;
34
35 /**
36  * @author joe
37  */
38 @RunWith(MockitoJUnitRunner.class)
39 public class RpcContextImplTest {
40
41     @Mock
42     private BindingAwareBroker.ProviderContext mockedRpcProviderRegistry;
43
44     @Mock
45     private DeviceContext deviceContext;
46
47     private RpcContext rpcContext;
48
49     private static final String QUEUE_IS_FULL = "Device's request queue is full.";
50
51     @Before
52     public void setup() {
53         NodeId nodeId = new NodeId("openflow:1");
54         KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
55
56         rpcContext = new RpcContextImpl(mockedRpcProviderRegistry, nodeInstanceIdentifier);
57     }
58
59     @Test
60     public void invokeRpcTest() {
61
62     }
63
64     @Test
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());
71     }
72
73     @Test
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());
85     }
86
87 }