2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.sal.connect.netconf.sal;
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;
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;
31 public class NetconfDeviceTopologyAdapterTest {
33 private RemoteDeviceId id = new RemoteDeviceId("test", new InetSocketAddress("localhost", 22));
36 private DataBroker broker;
38 private WriteTransaction writeTx;
42 private String txIdent = "test transaction";
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));
51 doReturn(txIdent).when(writeTx).getIdentifier();
55 public void testFailedDevice() throws Exception {
56 doReturn(Futures.immediateCheckedFuture(null)).when(writeTx).submit();
58 NetconfDeviceTopologyAdapter adapter = new NetconfDeviceTopologyAdapter(id, broker);
59 adapter.setDeviceAsFailed(null);
61 verify(broker, times(2)).newWriteOnlyTransaction();
62 verify(writeTx, times(3)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
66 public void testDeviceUpdate() throws Exception {
67 doReturn(Futures.immediateCheckedFuture(null)).when(writeTx).submit();
69 NetconfDeviceTopologyAdapter adapter = new NetconfDeviceTopologyAdapter(id, broker);
70 adapter.updateDeviceData(true, new NetconfDeviceCapabilities());
72 verify(broker, times(2)).newWriteOnlyTransaction();
73 verify(writeTx, times(3)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));