Merge "BUG-2627: do not duplicate descriptions"
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / test / java / org / opendaylight / controller / sal / connect / netconf / sal / NetconfDeviceTopologyAdapterTest.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
9 package org.opendaylight.controller.sal.connect.netconf.sal;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
16
17 import com.google.common.util.concurrent.Futures;
18 import java.net.InetSocketAddress;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
24 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
25 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
26 import org.opendaylight.controller.sal.connect.netconf.listener.NetconfDeviceCapabilities;
27 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30
31 public class NetconfDeviceTopologyAdapterTest {
32
33     private RemoteDeviceId id = new RemoteDeviceId("test", new InetSocketAddress("localhost", 22));
34
35     @Mock
36     private DataBroker broker;
37     @Mock
38     private WriteTransaction writeTx;
39     @Mock
40     private Node data;
41
42     private String txIdent = "test transaction";
43
44     @Before
45     public void setUp() throws Exception {
46         MockitoAnnotations.initMocks(this);
47         doReturn(writeTx).when(broker).newWriteOnlyTransaction();
48         doNothing().when(writeTx).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
49         doNothing().when(writeTx).merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
50
51         doReturn(txIdent).when(writeTx).getIdentifier();
52     }
53
54     @Test
55     public void testFailedDevice() throws Exception {
56         doReturn(Futures.immediateCheckedFuture(null)).when(writeTx).submit();
57
58         NetconfDeviceTopologyAdapter adapter = new NetconfDeviceTopologyAdapter(id, broker);
59         adapter.setDeviceAsFailed(null);
60
61         verify(broker, times(2)).newWriteOnlyTransaction();
62         verify(writeTx, times(3)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
63     }
64
65     @Test
66     public void testDeviceUpdate() throws Exception {
67         doReturn(Futures.immediateCheckedFuture(null)).when(writeTx).submit();
68
69         NetconfDeviceTopologyAdapter adapter = new NetconfDeviceTopologyAdapter(id, broker);
70         adapter.updateDeviceData(true, new NetconfDeviceCapabilities());
71
72         verify(broker, times(2)).newWriteOnlyTransaction();
73         verify(writeTx, times(3)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
74     }
75
76 }