X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2Fsal%2Ftx%2FNetconfDeviceWriteOnlyTxTest.java;h=3a378ed427fb6def7846eebd84aefe5e529afd8e;hp=a37fade91578895ec98d209e101838b1adbcef5b;hb=373836d91e59e4d5cd783a9597deb6457f8f807e;hpb=83dfe301bf2a2b1eff6883a2af3282c95d5a752e diff --git a/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/sal/tx/NetconfDeviceWriteOnlyTxTest.java b/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/sal/tx/NetconfDeviceWriteOnlyTxTest.java index a37fade915..3a378ed427 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/sal/tx/NetconfDeviceWriteOnlyTxTest.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/sal/tx/NetconfDeviceWriteOnlyTxTest.java @@ -2,17 +2,20 @@ package org.opendaylight.controller.sal.connect.netconf.sal.tx; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.same; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.inOrder; -import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.DISCARD_CHANGES_RPC_CONTENT; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME; +import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_FILTER_QNAME; import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME; +import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.toPath; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import java.util.Collections; +import java.net.InetSocketAddress; import org.junit.Before; import org.junit.Test; import org.mockito.InOrder; @@ -20,57 +23,68 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer; -import org.opendaylight.controller.sal.connect.netconf.listener.NetconfSessionPreferences; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; +import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult; +import org.opendaylight.controller.sal.connect.netconf.NetconfDevice; import org.opendaylight.controller.sal.connect.netconf.util.NetconfBaseOps; import org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil; import org.opendaylight.controller.sal.connect.util.RemoteDeviceId; -import org.opendaylight.controller.sal.core.api.RpcImplementation; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.MapNode; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; public class NetconfDeviceWriteOnlyTxTest { - private final RemoteDeviceId id = new RemoteDeviceId("test-mount"); + private final RemoteDeviceId id = new RemoteDeviceId("test-mount", new InetSocketAddress(99)); @Mock - private RpcImplementation rpc; - @Mock - private DataNormalizer normalizer; + private DOMRpcService rpc; private YangInstanceIdentifier yangIId; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - ListenableFuture> successFuture = Futures.immediateFuture(RpcResultBuilder.success().build()); + final CheckedFuture successFuture = + Futures.immediateCheckedFuture(new DefaultDOMRpcResult(((NormalizedNode) null))); doReturn(successFuture) - .doReturn(Futures.>immediateFailedFuture(new IllegalStateException("Failed tx"))) + .doReturn(Futures.immediateFailedCheckedFuture(new IllegalStateException("Failed tx"))) .doReturn(successFuture) - .when(rpc).invokeRpc(any(QName.class), any(CompositeNode.class)); + .when(rpc).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class)); + + yangIId = YangInstanceIdentifier.builder().node(NetconfState.QNAME).build(); + } + + @Test + public void testIgnoreNonVisibleData() { + final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc, mock(SchemaContext.class)), + false, 60000L); + final MapNode emptyList = ImmutableNodes.mapNodeBuilder(NETCONF_FILTER_QNAME).build(); + tx.merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(NETCONF_FILTER_QNAME)), emptyList); + tx.put(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(NETCONF_FILTER_QNAME)), emptyList); - yangIId = YangInstanceIdentifier.builder().node(QName.create("namespace", "2012-12-12", "name")).build(); - doReturn(yangIId).when(normalizer).toLegacy(yangIId); + verify(rpc, atMost(1)).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class)); } @Test public void testDiscardChanges() { - final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc), normalizer, - NetconfSessionPreferences.fromStrings(Collections.emptySet())); + final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc, mock(SchemaContext.class)), + false, 60000L); final CheckedFuture submitFuture = tx.submit(); try { submitFuture.checkedGet(); } catch (final TransactionCommitFailedException e) { // verify discard changes was sent final InOrder inOrder = inOrder(rpc); - inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME, NetconfBaseOps.getLockContent(NETCONF_CANDIDATE_QNAME)); - inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME, NetconfMessageTransformUtil.COMMIT_RPC_CONTENT); - inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME, DISCARD_CHANGES_RPC_CONTENT); - inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME, NetconfBaseOps.getUnLockContent(NETCONF_CANDIDATE_QNAME)); + inOrder.verify(rpc).invokeRpc(toPath(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME), NetconfBaseOps.getLockContent(NETCONF_CANDIDATE_QNAME)); + inOrder.verify(rpc).invokeRpc(toPath(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME), NetconfMessageTransformUtil.COMMIT_RPC_CONTENT); + inOrder.verify(rpc).invokeRpc(eq(toPath(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME)), any(NormalizedNode.class)); + inOrder.verify(rpc).invokeRpc(toPath(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME), NetconfBaseOps.getUnLockContent(NETCONF_CANDIDATE_QNAME)); return; } @@ -79,20 +93,20 @@ public class NetconfDeviceWriteOnlyTxTest { @Test public void testDiscardChangesNotSentWithoutCandidate() { - doReturn(Futures.immediateFuture(RpcResultBuilder.success().build())) - .doReturn(Futures.>immediateFailedFuture(new IllegalStateException("Failed tx"))) - .when(rpc).invokeRpc(any(QName.class), any(CompositeNode.class)); + doReturn(Futures.immediateCheckedFuture(new DefaultDOMRpcResult(((NormalizedNode) null)))) + .doReturn(Futures.immediateFailedCheckedFuture(new IllegalStateException("Failed tx"))) + .when(rpc).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class)); - final WriteRunningTx tx = new WriteRunningTx(id, new NetconfBaseOps(rpc), normalizer, - NetconfSessionPreferences.fromStrings(Collections.emptySet())); + final WriteRunningTx tx = new WriteRunningTx(id, new NetconfBaseOps(rpc, NetconfDevice.INIT_SCHEMA_CTX), + false, 60000L); try { tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId); } catch (final Exception e) { // verify discard changes was sent final InOrder inOrder = inOrder(rpc); - inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME, NetconfBaseOps.getLockContent(NETCONF_RUNNING_QNAME)); - inOrder.verify(rpc).invokeRpc(same(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME), any(CompositeNode.class)); - inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME, NetconfBaseOps.getUnLockContent(NETCONF_RUNNING_QNAME)); + inOrder.verify(rpc).invokeRpc(toPath(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME), NetconfBaseOps.getLockContent(NETCONF_RUNNING_QNAME)); + inOrder.verify(rpc).invokeRpc(eq(toPath(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME)), any(NormalizedNode.class)); + inOrder.verify(rpc).invokeRpc(toPath(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME), NetconfBaseOps.getUnLockContent(NETCONF_RUNNING_QNAME)); return; }