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