Merge "Bug 5577 Retry mechanism"
[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
11 import static org.mockito.Matchers.eq;
12 import static org.mockito.Mockito.verify;
13 import static org.mockito.Mockito.verifyNoMoreInteractions;
14
15 import org.junit.After;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.runners.MockitoJUnitRunner;
21 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
22 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
23 import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
24 import org.opendaylight.openflowplugin.impl.rpc.listener.ItemLifecycleListenerImpl;
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 @RunWith(MockitoJUnitRunner.class)
33 public class ItemLifecycleListenerImplTest {
34
35     @Mock
36     private DeviceContext deviceContext;
37
38     @Mock
39     private Node node;
40
41     private KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
42     private ItemLifecycleListener itemLifecycleListener;
43
44
45     @Before
46     public void setUp() {
47         final NodeId nodeId = new NodeId("openflow:1");
48         nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
49         itemLifecycleListener = new ItemLifecycleListenerImpl(deviceContext);
50     }
51
52     @After
53     public void tearDown() {
54         verifyNoMoreInteractions(deviceContext);
55     }
56
57     @Test
58     public void testOnAdded() throws Exception {
59         itemLifecycleListener.onAdded(nodeInstanceIdentifier, node);
60         verify(deviceContext).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 }