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.client.mdsal.spi;
10 import static org.junit.Assert.assertNotEquals;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.verify;
16 import com.google.common.util.concurrent.Futures;
17 import java.net.InetSocketAddress;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Mock;
22 import org.mockito.Mockito;
23 import org.mockito.junit.MockitoJUnitRunner;
24 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
25 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
26 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
27 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceServices.Rpcs;
28 import org.opendaylight.netconf.client.mdsal.impl.NetconfBaseOps;
29 import org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil;
30 import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
31 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
32 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
34 @RunWith(MockitoJUnitRunner.StrictStubs.class)
35 public class ReadOnlyTxTest {
37 private Rpcs.Normalized rpc;
39 private ContainerNode mockedNode;
41 private NetconfBaseOps netconfOps;
45 doReturn(Futures.immediateFuture(new DefaultDOMRpcResult(mockedNode))).when(rpc).invokeNetconf(any(), any());
46 netconfOps = new NetconfBaseOps(rpc, mock(MountPointContext.class));
50 public void testRead() throws Exception {
52 new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)))) {
53 readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty());
54 verify(rpc).invokeNetconf(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME),
55 any(ContainerNode.class));
56 readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
57 verify(rpc).invokeNetconf(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME), any());
62 public void testExists() throws Exception {
64 new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)))) {
65 readOnlyTx.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty());
66 verify(rpc).invokeNetconf(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME), any());
67 readOnlyTx.exists(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
68 verify(rpc).invokeNetconf(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME), any());
73 public void testIdentifier() throws Exception {
74 try (var tx1 = new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)))) {
75 try (var tx2 = new ReadOnlyTx(netconfOps, new RemoteDeviceId("a",
76 new InetSocketAddress("localhost", 196)))) {
77 assertNotEquals(tx1.getIdentifier(), tx2.getIdentifier());