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=a37fade91578895ec98d209e101838b1adbcef5b;hp=a65e426d5998542a4f2220092178cfec3a12d07c;hb=3997099eb61b0f2adc47f7a85952c324e9de223f;hpb=475d28f717bae92b2cc10b0589131771fcc62242 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 a65e426d59..a37fade915 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 @@ -1,22 +1,28 @@ package org.opendaylight.controller.sal.connect.netconf.sal.tx; -import static junit.framework.Assert.fail; +import static org.junit.Assert.fail; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.same; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.inOrder; import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.DISCARD_CHANGES_RPC_CONTENT; +import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME; +import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME; 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 org.junit.Before; import org.junit.Test; +import org.mockito.InOrder; 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.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; @@ -40,8 +46,11 @@ public class NetconfDeviceWriteOnlyTxTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - doReturn(Futures.>immediateFailedFuture(new IllegalStateException("Failed tx"))) - .doReturn(Futures.immediateFuture(RpcResultBuilder.success().build())) + ListenableFuture> successFuture = Futures.immediateFuture(RpcResultBuilder.success().build()); + + doReturn(successFuture) + .doReturn(Futures.>immediateFailedFuture(new IllegalStateException("Failed tx"))) + .doReturn(successFuture) .when(rpc).invokeRpc(any(QName.class), any(CompositeNode.class)); yangIId = YangInstanceIdentifier.builder().node(QName.create("namespace", "2012-12-12", "name")).build(); @@ -49,31 +58,45 @@ public class NetconfDeviceWriteOnlyTxTest { } @Test - public void testDiscardCahnges() { - final NetconfDeviceWriteOnlyTx tx = new NetconfDeviceWriteOnlyTx(id, rpc, normalizer, true, true); + public void testDiscardChanges() { + final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc), normalizer, + NetconfSessionPreferences.fromStrings(Collections.emptySet())); final CheckedFuture submitFuture = tx.submit(); try { submitFuture.checkedGet(); } catch (final TransactionCommitFailedException e) { // verify discard changes was sent - verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME, DISCARD_CHANGES_RPC_CONTENT); + 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)); return; } fail("Submit should fail"); } - @Test - public void testDiscardCahngesNotSentWithoutCandidate() { + 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)); - final NetconfDeviceWriteOnlyTx tx = new NetconfDeviceWriteOnlyTx(id, rpc, normalizer, false, true); - tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId); - verify(rpc).invokeRpc(eq(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME), any(CompositeNode.class)); - verifyNoMoreInteractions(rpc); + final WriteRunningTx tx = new WriteRunningTx(id, new NetconfBaseOps(rpc), normalizer, + NetconfSessionPreferences.fromStrings(Collections.emptySet())); + 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)); + return; + } + + fail("Delete should fail"); } }