Changed NetconfDeviceDatastoreAdapter and NetconfDeviceTopologyAdapter to use Transac...
[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.BindingTransactionChain;
24 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
25 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
26 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
27 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
28 import org.opendaylight.controller.sal.connect.netconf.listener.NetconfDeviceCapabilities;
29 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32
33 public class NetconfDeviceTopologyAdapterTest {
34
35     private RemoteDeviceId id = new RemoteDeviceId("test", new InetSocketAddress("localhost", 22));
36
37     @Mock
38     private DataBroker broker;
39     @Mock
40     private WriteTransaction writeTx;
41     @Mock
42     private BindingTransactionChain txChain;
43     @Mock
44     private Node data;
45
46     private String txIdent = "test transaction";
47
48     @Before
49     public void setUp() throws Exception {
50         MockitoAnnotations.initMocks(this);
51         doReturn(txChain).when(broker).createTransactionChain(any(TransactionChainListener.class));
52         doReturn(writeTx).when(txChain).newWriteOnlyTransaction();
53         doNothing().when(writeTx).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
54         doNothing().when(writeTx).merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
55
56         doReturn(txIdent).when(writeTx).getIdentifier();
57     }
58
59     @Test
60     public void testFailedDevice() throws Exception {
61         doReturn(Futures.immediateCheckedFuture(null)).when(writeTx).submit();
62
63         NetconfDeviceTopologyAdapter adapter = new NetconfDeviceTopologyAdapter(id, broker);
64         adapter.setDeviceAsFailed(null);
65
66         verify(txChain, times(2)).newWriteOnlyTransaction();
67         verify(writeTx, times(3)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
68     }
69
70     @Test
71     public void testDeviceUpdate() throws Exception {
72         doReturn(Futures.immediateCheckedFuture(null)).when(writeTx).submit();
73
74         NetconfDeviceTopologyAdapter adapter = new NetconfDeviceTopologyAdapter(id, broker);
75         adapter.updateDeviceData(true, new NetconfDeviceCapabilities());
76
77         verify(txChain, times(2)).newWriteOnlyTransaction();
78         verify(writeTx, times(3)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
79     }
80
81 }