*/
package org.opendaylight.netconf.sal.connect.netconf.sal.tx;
+import static org.junit.Assert.assertNotEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import com.google.common.util.concurrent.Futures;
import java.net.InetSocketAddress;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceId;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Rpcs;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
-import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
-import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class ReadOnlyTxTest {
@Mock
- private DOMRpcService rpc;
+ private Rpcs.Normalized rpc;
@Mock
- private NormalizedNode<?, ?> mockedNode;
+ private ContainerNode mockedNode;
+
+ private NetconfBaseOps netconfOps;
@Before
public void setUp() {
- doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(mockedNode))).when(rpc)
- .invokeRpc(any(SchemaPath.class), any(ContainerNode.class));
+ doReturn(Futures.immediateFuture(new DefaultDOMRpcResult(mockedNode))).when(rpc).invokeNetconf(any(), any());
+ netconfOps = new NetconfBaseOps(rpc, mock(MountPointContext.class));
}
@Test
public void testRead() throws Exception {
- final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc, mock(MountPointContext.class));
-
- final ReadOnlyTx readOnlyTx =
- new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
-
- readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty());
- verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.toPath(
- NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME)), any(ContainerNode.class));
- readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
- verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.toPath(
- NetconfMessageTransformUtil.NETCONF_GET_QNAME)), any(ContainerNode.class));
+ try (var readOnlyTx =
+ new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)))) {
+ readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty());
+ verify(rpc).invokeNetconf(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME),
+ any(ContainerNode.class));
+ readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
+ verify(rpc).invokeNetconf(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME), any());
+ }
}
@Test
public void testExists() throws Exception {
- final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc, mock(MountPointContext.class));
-
- final ReadOnlyTx readOnlyTx =
- new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
-
- readOnlyTx.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty());
- verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.toPath(
- NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME)), any(ContainerNode.class));
- readOnlyTx.exists(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
- verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.toPath(
- NetconfMessageTransformUtil.NETCONF_GET_QNAME)), any(ContainerNode.class));
+ try (var readOnlyTx =
+ new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)))) {
+ readOnlyTx.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty());
+ verify(rpc).invokeNetconf(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME), any());
+ readOnlyTx.exists(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
+ verify(rpc).invokeNetconf(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME), any());
+ }
}
@Test
public void testIdentifier() throws Exception {
- final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc, mock(MountPointContext.class));
- final ReadOnlyTx tx1 =
- new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
- final ReadOnlyTx tx2 =
- new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
- Assert.assertNotEquals(tx1.getIdentifier(), tx2.getIdentifier());
+ try (var tx1 = new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)))) {
+ try (var tx2 = new ReadOnlyTx(netconfOps, new RemoteDeviceId("a",
+ new InetSocketAddress("localhost", 196)))) {
+ assertNotEquals(tx1.getIdentifier(), tx2.getIdentifier());
+ }
+ }
}
}
\ No newline at end of file