Search in sources :

Example 11 with MdsalRestconfStrategy

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

the class PlainPatchDataTransactionUtilTest method testPatchLeafData.

@Test
public void testPatchLeafData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iidGap, schemaNodeForGap, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, leafGap);
    doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
    doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).merge(any(), any(), any(), any());
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
    PlainPatchDataTransactionUtil.patchData(payload, new MdsalRestconfStrategy(mockDataBroker), schema);
    verify(readWrite).merge(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
    PlainPatchDataTransactionUtil.patchData(payload, new NetconfRestconfStrategy(netconfService), schema);
    verify(netconfService).lock();
    verify(netconfService).merge(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData(), Optional.empty());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) 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)

Example 12 with MdsalRestconfStrategy

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

the class PostDataTransactionUtilTest method testPostListData.

@Test
public void testPostListData() {
    final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iidList, null, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildList);
    final MapNode data = (MapNode) payload.getData();
    final MapEntryNode entryNode = data.body().iterator().next();
    final NodeIdentifierWithPredicates identifier = entryNode.getIdentifier();
    final YangInstanceIdentifier node = iidList.node(identifier);
    doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
    doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node, entryNode);
    doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).merge(any(), any(), any(), any());
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).create(LogicalDatastoreType.CONFIGURATION, node, entryNode, Optional.empty());
    Response response = PostDataTransactionUtil.postData(uriInfo, payload, new MdsalRestconfStrategy(mockDataBroker), schema, WriteDataParams.empty());
    assertEquals(201, response.getStatus());
    assertThat(URLDecoder.decode(response.getLocation().toString(), StandardCharsets.UTF_8), containsString(identifier.getValue(identifier.keySet().iterator().next()).toString()));
    verify(readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
    verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, node, entryNode);
    response = PostDataTransactionUtil.postData(uriInfo, payload, new NetconfRestconfStrategy(netconfService), schema, WriteDataParams.empty());
    assertEquals(201, response.getStatus());
    assertThat(URLDecoder.decode(response.getLocation().toString(), StandardCharsets.UTF_8), containsString(identifier.getValue(identifier.keySet().iterator().next()).toString()));
    verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, node, entryNode, Optional.empty());
}
Also used : Response(javax.ws.rs.core.Response) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 13 with MdsalRestconfStrategy

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

the class PostDataTransactionUtilTest method testPostContainerData.

@Test
public void testPostContainerData() {
    final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, null, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
    doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    final NodeIdentifier identifier = ((ContainerNode) ((Collection<?>) payload.getData().body()).iterator().next()).getIdentifier();
    final YangInstanceIdentifier node = iid2.node(identifier);
    doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node.getParent(), payload.getData());
    doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).create(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
    Response response = PostDataTransactionUtil.postData(uriInfo, payload, new MdsalRestconfStrategy(mockDataBroker), schema, WriteDataParams.empty());
    assertEquals(201, response.getStatus());
    verify(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData());
    response = PostDataTransactionUtil.postData(uriInfo, payload, new NetconfRestconfStrategy(netconfService), schema, WriteDataParams.empty());
    assertEquals(201, response.getStatus());
    verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
}
Also used : Response(javax.ws.rs.core.Response) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Collection(java.util.Collection) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 14 with MdsalRestconfStrategy

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

the class PostDataTransactionUtilTest method testPostDataFail.

@Test
public void testPostDataFail() {
    final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, null, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
    doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    final NodeIdentifier identifier = ((ContainerNode) ((Collection<?>) payload.getData().body()).iterator().next()).getIdentifier();
    final YangInstanceIdentifier node = iid2.node(identifier);
    doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node.getParent(), payload.getData());
    final DOMException domException = new DOMException((short) 414, "Post request failed");
    doReturn(immediateFailedFluentFuture(domException)).when(readWrite).commit();
    doReturn(immediateFailedFluentFuture(domException)).when(netconfService).create(any(), any(), any(), any());
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).discardChanges();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).unlock();
    RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> PostDataTransactionUtil.postData(uriInfo, payload, new MdsalRestconfStrategy(mockDataBroker), schema, WriteDataParams.empty()));
    assertEquals(1, ex.getErrors().size());
    assertThat(ex.getErrors().get(0).getErrorInfo(), containsString(domException.getMessage()));
    verify(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData());
    ex = assertThrows(RestconfDocumentedException.class, () -> PostDataTransactionUtil.postData(uriInfo, payload, new NetconfRestconfStrategy(netconfService), schema, WriteDataParams.empty()));
    assertEquals(1, ex.getErrors().size());
    assertThat(ex.getErrors().get(0).getErrorInfo(), containsString(domException.getMessage()));
    verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
}
Also used : DOMException(org.w3c.dom.DOMException) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Collection(java.util.Collection) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 15 with MdsalRestconfStrategy

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

the class PutDataTransactionUtilTest method testPutContainerData.

@Test
public void testPutContainerData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, schemaNode2, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
    doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
    doReturn(read).when(mockDataBroker).newReadOnlyTransaction();
    doReturn(immediateFalseFluentFuture()).when(read).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData());
    doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
    PutDataTransactionUtil.putData(payload, schema, new MdsalRestconfStrategy(mockDataBroker), WriteDataParams.empty());
    verify(read).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData());
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) Test(org.junit.Test)

Aggregations

MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)17 Test (org.junit.Test)16 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)14 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)13 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)9 NormalizedNodePayload (org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload)9 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)6 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 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 RestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy)1