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
8 package org.opendaylight.netconf.sal.connect.netconf.sal.tx;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.verify;
15 import java.net.InetSocketAddress;
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mock;
21 import org.mockito.Mockito;
22 import org.mockito.junit.MockitoJUnitRunner;
23 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
24 import org.opendaylight.mdsal.dom.api.DOMRpcService;
25 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
26 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
27 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
28 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
29 import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
30 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
31 import org.opendaylight.yangtools.yang.common.QName;
32 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
33 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
34 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
36 @RunWith(MockitoJUnitRunner.StrictStubs.class)
37 public class ReadOnlyTxTest {
39 private DOMRpcService rpc;
41 private NormalizedNode<?, ?> mockedNode;
45 doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(mockedNode))).when(rpc)
46 .invokeRpc(any(QName.class), any(ContainerNode.class));
50 public void testRead() throws Exception {
51 final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc, mock(MountPointContext.class));
53 final ReadOnlyTx readOnlyTx =
54 new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
56 readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty());
57 verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME),
58 any(ContainerNode.class));
59 readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
60 verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME), any(ContainerNode.class));
64 public void testExists() throws Exception {
65 final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc, mock(MountPointContext.class));
67 final ReadOnlyTx readOnlyTx =
68 new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
70 readOnlyTx.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty());
71 verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME),
72 any(ContainerNode.class));
73 readOnlyTx.exists(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
74 verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME), any(ContainerNode.class));
78 public void testIdentifier() throws Exception {
79 final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc, mock(MountPointContext.class));
80 final ReadOnlyTx tx1 =
81 new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
82 final ReadOnlyTx tx2 =
83 new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
84 Assert.assertNotEquals(tx1.getIdentifier(), tx2.getIdentifier());