Search in sources :

Example 6 with NetconfRestconfStrategy

use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy in project netconf by opendaylight.

the class PutDataTransactionUtilTest method testPutReplaceLeafData.

@Test
public void testPutReplaceLeafData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildLeaf);
    doReturn(immediateFluentFuture(Optional.of(mock(NormalizedNode.class)))).when(netconfService).getConfig(iid);
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid, payload.getData(), Optional.empty());
    PutDataTransactionUtil.putData(payload, schema, new NetconfRestconfStrategy(netconfService), WriteDataParams.empty());
    verify(netconfService).getConfig(iid);
    verify(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid, payload.getData(), Optional.empty());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 7 with NetconfRestconfStrategy

use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy in project netconf by opendaylight.

the class DeleteDataTransactionUtilTest method deleteDataNegativeTest.

/**
 * Negative test for DELETE operation when data to delete does not exist. Error DATA_MISSING is expected.
 */
@Test
public void deleteDataNegativeTest() {
    // assert that data to delete does NOT exist
    when(readWrite.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty())).thenReturn(immediateFalseFluentFuture());
    final NetconfDocumentedException exception = new NetconfDocumentedException("id", ErrorType.RPC, ErrorTag.DATA_MISSING, ErrorSeverity.ERROR);
    final SettableFuture<? extends CommitInfo> ret = SettableFuture.create();
    ret.setException(new TransactionCommitFailedException(String.format("Commit of transaction %s failed", this), exception));
    doReturn(ret).when(this.netconfService).commit();
    // test and assert error
    deleteFail(new MdsalRestconfStrategy(mockDataBroker));
    deleteFail(new NetconfRestconfStrategy(netconfService));
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) Test(org.junit.Test)

Example 8 with NetconfRestconfStrategy

use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy in project netconf by opendaylight.

the class DeleteDataTransactionUtilTest method deleteData.

/**
 * Test of successful DELETE operation.
 */
@Test
public void deleteData() {
    // assert that data to delete exists
    when(readWrite.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty())).thenReturn(immediateTrueFluentFuture());
    // test
    delete(new MdsalRestconfStrategy(mockDataBroker));
    delete(new NetconfRestconfStrategy(netconfService));
}
Also used : MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) Test(org.junit.Test)

Example 9 with NetconfRestconfStrategy

use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy in project netconf by opendaylight.

the class PatchDataTransactionUtilTest method testPatchMergePutContainer.

@Test
public void testPatchMergePutContainer() {
    final PatchEntity entityMerge = new PatchEntity("edit1", MERGE, this.instanceIdContainer, this.buildBaseContainerForTests);
    final List<PatchEntity> entities = new ArrayList<>();
    entities.add(entityMerge);
    final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(this.instanceIdCreateAndDelete, null, null, this.refSchemaCtx);
    final PatchContext patchContext = new PatchContext(iidContext, entities, "patchM");
    patch(patchContext, new MdsalRestconfStrategy(mockDataBroker), false);
    patch(patchContext, new NetconfRestconfStrategy(netconfService), false);
}
Also used : PatchContext(org.opendaylight.restconf.common.patch.PatchContext) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) PatchEntity(org.opendaylight.restconf.common.patch.PatchEntity) ArrayList(java.util.ArrayList) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) Test(org.junit.Test)

Example 10 with NetconfRestconfStrategy

use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy in project netconf by opendaylight.

the class PutDataTransactionUtilTest method testPutCreateLeafData.

@Test
public void testPutCreateLeafData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildLeaf);
    doReturn(immediateFluentFuture(Optional.empty())).when(netconfService).getConfig(iid);
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid, payload.getData(), Optional.empty());
    PutDataTransactionUtil.putData(payload, schema, new NetconfRestconfStrategy(netconfService), WriteDataParams.empty());
    verify(netconfService).getConfig(iid);
    verify(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid, payload.getData(), Optional.empty());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) Test(org.junit.Test)

Aggregations

NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)20 Test (org.junit.Test)19 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)16 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)15 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)14 NormalizedNodePayload (org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload)12 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)9 ArrayList (java.util.ArrayList)4 PatchContext (org.opendaylight.restconf.common.patch.PatchContext)4 PatchEntity (org.opendaylight.restconf.common.patch.PatchEntity)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 Collection (java.util.Collection)2 Response (javax.ws.rs.core.Response)2 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)2 NetconfDocumentedException (org.opendaylight.netconf.api.NetconfDocumentedException)2 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)2 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)2 Before (org.junit.Before)1 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)1