2 * Copyright © 2020 FRINX s.r.o. 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.ArgumentMatchers.eq;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.verify;
15 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME;
16 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_QNAME;
18 import com.google.common.util.concurrent.Futures;
19 import java.net.InetSocketAddress;
20 import java.util.List;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.mockito.Mock;
24 import org.mockito.junit.MockitoJUnitRunner;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
27 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceId;
28 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Rpcs;
29 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
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 FieldsAwareReadOnlyTxTest {
37 private Rpcs.Normalized rpc;
39 private ContainerNode mockedNode;
42 public void testReadWithFields() {
43 doReturn(Futures.immediateFuture(new DefaultDOMRpcResult(mockedNode))).when(rpc). invokeNetconf(any(), any());
45 final var netconfOps = new NetconfBaseOps(rpc, mock(MountPointContext.class));
46 try (var readOnlyTx = new FieldsAwareReadOnlyTx(netconfOps,
47 new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)))) {
49 readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty(),
50 List.of(YangInstanceIdentifier.empty()));
51 verify(rpc).invokeNetconf(eq(NETCONF_GET_CONFIG_QNAME), any());
53 readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
54 verify(rpc).invokeNetconf(eq(NETCONF_GET_QNAME), any());