Merge "Fix issues related to checkstyle enforcement"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / rpc / ItemLifecycleListenerImplTest.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.mockito.Matchers.eq;
11 import static org.mockito.Mockito.verify;
12 import static org.mockito.Mockito.verifyNoMoreInteractions;
13
14 import org.junit.After;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mock;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
22 import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
23 import org.opendaylight.openflowplugin.impl.rpc.listener.ItemLifecycleListenerImpl;
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 @RunWith(MockitoJUnitRunner.class)
32 public class ItemLifecycleListenerImplTest {
33
34     @Mock
35     private DeviceContext deviceContext;
36
37     @Mock
38     private Node node;
39
40     private KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
41     private ItemLifecycleListener itemLifecycleListener;
42
43
44     @Before
45     public void setUp() {
46         final NodeId nodeId = new NodeId("openflow:1");
47         nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
48         itemLifecycleListener = new ItemLifecycleListenerImpl(deviceContext);
49     }
50
51     @After
52     public void tearDown() {
53         verifyNoMoreInteractions(deviceContext);
54     }
55
56     @Test
57     public void testOnAdded() throws Exception {
58         itemLifecycleListener.onAdded(nodeInstanceIdentifier, node);
59         verify(deviceContext)
60                 .writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), eq(nodeInstanceIdentifier), eq(node));
61         verify(deviceContext).submitTransaction();
62     }
63
64     @Test
65     public void testOnRemoved() throws Exception {
66         itemLifecycleListener.onRemoved(nodeInstanceIdentifier);
67         verify(deviceContext).addDeleteToTxChain(eq(LogicalDatastoreType.OPERATIONAL), eq(nodeInstanceIdentifier));
68         verify(deviceContext).submitTransaction();
69     }
70 }