Search in sources :

Example 1 with NetconfBaseOps

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

the class FieldsAwareReadOnlyTxTest method testReadWithFields.

@Test
public void testReadWithFields() {
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(mockedNode))).when(rpc).invokeRpc(any(QName.class), any(ContainerNode.class));
    final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc, mock(MountPointContext.class));
    try (FieldsAwareReadOnlyTx readOnlyTx = new FieldsAwareReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)))) {
        readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty(), List.of(YangInstanceIdentifier.empty()));
        verify(rpc).invokeRpc(eq(NETCONF_GET_CONFIG_QNAME), any(ContainerNode.class));
        readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
        verify(rpc).invokeRpc(eq(NETCONF_GET_QNAME), any(ContainerNode.class));
    }
}
Also used : RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) NetconfBaseOps(org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps) QName(org.opendaylight.yangtools.yang.common.QName) 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 2 with NetconfBaseOps

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

the class NetconfDeviceWriteOnlyTxTest method testListenerFailure.

@Test
public void testListenerFailure() throws Exception {
    final IllegalStateException cause = new IllegalStateException("Failed tx");
    doReturn(FluentFutures.immediateFailedFluentFuture(cause)).when(rpc).invokeRpc(any(QName.class), any(ContainerNode.class));
    final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchema().getMountPointContext()), false);
    final TxListener listener = mock(TxListener.class);
    tx.addListener(listener);
    tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
    tx.commit();
    final ArgumentCaptor<Exception> excCaptor = ArgumentCaptor.forClass(Exception.class);
    verify(listener).onTransactionSubmitted(tx);
    verify(listener).onTransactionFailed(eq(tx), excCaptor.capture());
    Assert.assertEquals(cause, excCaptor.getValue().getCause().getCause());
    verify(listener, never()).onTransactionSuccessful(tx);
    verify(listener, never()).onTransactionCancelled(tx);
}
Also used : 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) ExecutionException(java.util.concurrent.ExecutionException) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 3 with NetconfBaseOps

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

the class NetconfDeviceWriteOnlyTxTest method testIgnoreNonVisibleData.

@Test
public void testIgnoreNonVisibleData() {
    final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc, mock(MountPointContext.class)), false);
    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);
    verify(rpc, atMost(1)).invokeRpc(any(QName.class), any(ContainerNode.class));
}
Also used : 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) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 4 with NetconfBaseOps

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

the class NetconfDeviceWriteOnlyTxTest method testListenerSuccess.

@Test
public void testListenerSuccess() throws Exception {
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode) null))).when(rpc).invokeRpc(any(QName.class), any(ContainerNode.class));
    final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchema().getMountPointContext()), false);
    final TxListener listener = mock(TxListener.class);
    tx.addListener(listener);
    tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
    tx.commit();
    verify(listener).onTransactionSubmitted(tx);
    verify(listener).onTransactionSuccessful(tx);
    verify(listener, never()).onTransactionFailed(eq(tx), any());
    verify(listener, never()).onTransactionCancelled(tx);
}
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) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 5 with NetconfBaseOps

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

the class NetconfDeviceWriteOnlyTxTest method testListenerCancellation.

@Test
public void testListenerCancellation() throws Exception {
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode) null))).when(rpc).invokeRpc(any(QName.class), isNull());
    final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchema().getMountPointContext()), false);
    final TxListener listener = mock(TxListener.class);
    tx.addListener(listener);
    tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
    tx.cancel();
    verify(listener).onTransactionCancelled(tx);
    verify(listener, never()).onTransactionSubmitted(tx);
    verify(listener, never()).onTransactionSuccessful(tx);
    verify(listener, never()).onTransactionFailed(eq(tx), any());
}
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) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) 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