Specialize RPC input/output
[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
35 @RunWith(MockitoJUnitRunner.StrictStubs.class)
36 public class FieldsAwareReadOnlyTxTest {
37     @Mock
38     private DOMRpcService rpc;
39     @Mock
40     private ContainerNode mockedNode;
41
42     @Test
43     public void testReadWithFields() {
44         doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(mockedNode))).when(rpc)
45             .invokeRpc(any(QName.class), any(ContainerNode.class));
46
47         final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc, mock(MountPointContext.class));
48         try (FieldsAwareReadOnlyTx readOnlyTx = new FieldsAwareReadOnlyTx(netconfOps,
49                 new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)))) {
50
51             readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty(),
52                 List.of(YangInstanceIdentifier.empty()));
53             verify(rpc).invokeRpc(eq(NETCONF_GET_CONFIG_QNAME), any(ContainerNode.class));
54
55             readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
56             verify(rpc).invokeRpc(eq(NETCONF_GET_QNAME), any(ContainerNode.class));
57         }
58     }
59 }