Implement subtree filtering using fields
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / sal / tx / FieldsAwareReadOnlyTxTest.java
1 /*
2  * Copyright © 2020 FRINX s.r.o. 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 package org.opendaylight.netconf.sal.connect.netconf.sal.tx;
9
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;
17
18 import java.net.InetSocketAddress;
19 import java.util.List;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.Mock;
23 import org.mockito.junit.MockitoJUnitRunner;
24 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
25 import org.opendaylight.mdsal.dom.api.DOMRpcService;
26 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
27 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
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;
35
36 @RunWith(MockitoJUnitRunner.StrictStubs.class)
37 public class FieldsAwareReadOnlyTxTest {
38     @Mock
39     private DOMRpcService rpc;
40     @Mock
41     private NormalizedNode<?, ?> mockedNode;
42
43     @Test
44     public void testReadWithFields() {
45         doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(mockedNode))).when(rpc)
46             .invokeRpc(any(QName.class), any(ContainerNode.class));
47
48         final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc, mock(MountPointContext.class));
49         try (FieldsAwareReadOnlyTx readOnlyTx = new FieldsAwareReadOnlyTx(netconfOps,
50                 new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)))) {
51
52             readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty(),
53                 List.of(YangInstanceIdentifier.empty()));
54             verify(rpc).invokeRpc(eq(NETCONF_GET_CONFIG_QNAME), any(ContainerNode.class));
55
56             readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
57             verify(rpc).invokeRpc(eq(NETCONF_GET_QNAME), any(ContainerNode.class));
58         }
59     }
60 }