Merge "BUG-2188: To populate the port_number of switches - yang model"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / rpc / 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.impl.rpc;
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.device.DeviceContext;
20 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
21 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
22 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
23 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
30
31 /**
32  * @author joe
33  */
34 @RunWith(MockitoJUnitRunner.class)
35 public class RpcContextImplTest {
36
37     @Mock
38     private BindingAwareBroker.ProviderContext mockedRpcProviderRegistry;
39     @Mock
40     private DeviceState deviceState;
41     @Mock
42     private DeviceContext deviceContext;
43     @Mock
44     private MessageSpy messageSpy;
45
46     private KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
47
48     @Before
49     public void setup() {
50         NodeId nodeId = new NodeId("openflow:1");
51         nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
52
53         when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
54         when(deviceContext.getDeviceState()).thenReturn(deviceState);
55     }
56
57     @Test
58     public void invokeRpcTest() {
59
60     }
61
62     @Test
63     public void testStoreOrFail() throws Exception {
64         try (final RpcContext rpcContext = new RpcContextImpl(messageSpy, mockedRpcProviderRegistry, deviceContext, 100)) {
65             RequestContext<?> requestContext = rpcContext.createRequestContext();
66             assertNotNull(requestContext);
67         }
68     }
69
70     @Test
71     public void testStoreOrFailThatFails() throws Exception {
72         try (final RpcContext rpcContext = new RpcContextImpl(messageSpy, mockedRpcProviderRegistry, deviceContext, 0)) {
73             RequestContext<?> requestContext = rpcContext.createRequestContext();
74             assertNull(requestContext);
75         }
76     }
77 }