Merge "BUG-4148: Improving the logging levels, adding more information wherever required"
[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.md.sal.binding.api.NotificationPublishService;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
20 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
21 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
22 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
23 import org.opendaylight.openflowplugin.api.openflow.device.XidSequencer;
24 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
25 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
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
33 /**
34  * @author joe
35  */
36 @RunWith(MockitoJUnitRunner.class)
37 public class RpcContextImplTest {
38
39     @Mock
40     private BindingAwareBroker.ProviderContext rpcProviderRegistry;
41     @Mock
42     private DeviceState deviceState;
43     @Mock
44     private XidSequencer xidSequencer;
45     @Mock
46     private MessageSpy messageSpy;
47
48     private KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
49
50     @Before
51     public void setup() {
52         final NodeId nodeId = new NodeId("openflow:1");
53         nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
54     }
55
56     @Test
57     public void testStoreOrFail() throws Exception {
58         try (final RpcContext rpcContext = new RpcContextImpl(rpcProviderRegistry, xidSequencer,
59                 messageSpy, 100, nodeInstanceIdentifier)) {
60             final RequestContext<?> requestContext = rpcContext.createRequestContext();
61             assertNotNull(requestContext);
62         }
63     }
64
65     @Test
66     public void testStoreOrFailThatFails() throws Exception {
67         try (final RpcContext rpcContext = new RpcContextImpl(rpcProviderRegistry, xidSequencer,
68                 messageSpy, 0, nodeInstanceIdentifier)) {
69             final RequestContext<?> requestContext = rpcContext.createRequestContext();
70             assertNull(requestContext);
71         }
72     }
73 }