Search in sources :

Example 6 with NetconfBaseOps

use of org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps in project netconf by opendaylight.

the class NetconfDeviceWriteOnlyTxTest method testDiscardChangesNotSentWithoutCandidate.

@Test
public void testDiscardChangesNotSentWithoutCandidate() {
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode) null))).doReturn(FluentFutures.immediateFailedFluentFuture(new IllegalStateException("Failed tx"))).when(rpc).invokeRpc(any(QName.class), any(ContainerNode.class));
    final WriteRunningTx tx = new WriteRunningTx(id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchemaWithNotifications().getMountPointContext()), false);
    tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
    tx.commit();
    // 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(eq(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME), any(ContainerNode.class));
    inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME, NetconfBaseOps.getUnLockContent(NETCONF_RUNNING_QNAME));
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) NetconfBaseOps(org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps) InOrder(org.mockito.InOrder) QName(org.opendaylight.yangtools.yang.common.QName) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 7 with NetconfBaseOps

use of org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps in project netconf by opendaylight.

the class NetconfDeviceWriteOnlyTxTest method testFailedCommit.

@Test
public void testFailedCommit() throws Exception {
    final FluentFuture<DefaultDOMRpcResult> rpcErrorFuture = FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "a", "m")));
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode) null))).doReturn(rpcErrorFuture).when(rpc).invokeRpc(any(QName.class), any(ContainerNode.class));
    final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc, mock(MountPointContext.class)), false);
    try {
        tx.commit().get();
        fail("Submit should fail");
    } catch (final ExecutionException e) {
    // Intended
    }
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) NetconfBaseOps(org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps) QName(org.opendaylight.yangtools.yang.common.QName) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ExecutionException(java.util.concurrent.ExecutionException) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 8 with NetconfBaseOps

use of org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps in project netconf by opendaylight.

the class NetconfDeviceWriteOnlyTxTest method testDiscardChanges.

@Test
public void testDiscardChanges() throws InterruptedException {
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode) null))).when(rpc).invokeRpc(any(QName.class), isNull());
    final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc, mock(MountPointContext.class)), false);
    try {
        tx.commit().get();
    } catch (final ExecutionException 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(eq(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME), isNull());
        inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME, NetconfBaseOps.getUnLockContent(NETCONF_CANDIDATE_QNAME));
        return;
    }
    fail("Submit should fail");
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) NetconfBaseOps(org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps) InOrder(org.mockito.InOrder) QName(org.opendaylight.yangtools.yang.common.QName) ExecutionException(java.util.concurrent.ExecutionException) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 9 with NetconfBaseOps

use of org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps in project netconf by opendaylight.

the class ReadOnlyTxTest method testExists.

@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.NETCONF_GET_CONFIG_QNAME), any(ContainerNode.class));
    readOnlyTx.exists(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
    verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME), any(ContainerNode.class));
}
Also used : RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) NetconfBaseOps(org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps) InetSocketAddress(java.net.InetSocketAddress) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) Test(org.junit.Test)

Example 10 with NetconfBaseOps

use of org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps in project netconf by opendaylight.

the class ReadOnlyTxTest method testIdentifier.

@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());
}
Also used : RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) NetconfBaseOps(org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps) InetSocketAddress(java.net.InetSocketAddress) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) Test(org.junit.Test)

Aggregations

NetconfBaseOps (org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps)15 Test (org.junit.Test)11 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)9 QName (org.opendaylight.yangtools.yang.common.QName)8 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)8 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)7 RemoteDeviceId (org.opendaylight.netconf.sal.connect.util.RemoteDeviceId)7 InetSocketAddress (java.net.InetSocketAddress)4 MountPointContext (org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)4 ExecutionException (java.util.concurrent.ExecutionException)3 Before (org.junit.Before)3 EmptyMountPointContext (org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext)3 InOrder (org.mockito.InOrder)2 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)2 Objects.requireNonNull (java.util.Objects.requireNonNull)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)1