Make sure RequestContext has a constant XID
[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.assertNotNull;
11 import static org.junit.Assert.assertNull;
12 import static org.mockito.Mockito.when;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.Mock;
17 import org.mockito.runners.MockitoJUnitRunner;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
19 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
20 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
21 import org.opendaylight.openflowplugin.impl.rpc.RpcContextImpl;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
28
29 /**
30  * @author joe
31  */
32 @RunWith(MockitoJUnitRunner.class)
33 public class RpcContextImplTest {
34
35     @Mock
36     private BindingAwareBroker.ProviderContext mockedRpcProviderRegistry;
37     @Mock
38     private DeviceState deviceState;
39     @Mock
40     private DeviceContext deviceContext;
41     @Mock
42     private MessageSpy messageSpy;
43
44     private KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
45
46     @Before
47     public void setup() {
48         NodeId nodeId = new NodeId("openflow:1");
49         nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
50
51         when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
52         when(deviceContext.getDeviceState()).thenReturn(deviceState);
53     }
54
55     @Test
56     public void invokeRpcTest() {
57
58     }
59
60     @Test
61     public void testStoreOrFail() throws Exception {
62         final RpcContext rpcContext = new RpcContextImpl(messageSpy, mockedRpcProviderRegistry, deviceContext, 100);
63         RequestContext requestContext = rpcContext.createRequestContext();
64         assertNotNull(requestContext);
65
66     }
67
68     @Test
69     public void testStoreOrFailThatFails() throws Exception {
70         final RpcContext rpcContext = new RpcContextImpl(messageSpy, mockedRpcProviderRegistry, deviceContext, 0);
71         RequestContext requestContext = rpcContext.createRequestContext();
72         assertNull(requestContext);
73     }
74 }