Search in sources :

Example 31 with InstanceIdentifierContext

use of org.opendaylight.restconf.common.context.InstanceIdentifierContext in project netconf by opendaylight.

the class RestconfDataServiceImplTest method testPatchData.

@Test
public void testPatchData() {
    final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iidBase, schemaNode, null, contextRef);
    final List<PatchEntity> entity = new ArrayList<>();
    final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(iidBase).node(containerPlayerQname).node(leafQname).build();
    entity.add(new PatchEntity("create data", CREATE, iidBase, buildBaseCont));
    entity.add(new PatchEntity("replace data", REPLACE, iidBase, buildBaseCont));
    entity.add(new PatchEntity("delete data", DELETE, iidleaf));
    final PatchContext patch = new PatchContext(iidContext, entity, "test patch id");
    doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
    doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidBase);
    doReturn(immediateTrueFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
    final PatchStatusContext status = dataService.patchData(patch, uriInfo);
    assertTrue(status.isOk());
    assertEquals(3, status.getEditCollection().size());
    assertEquals("replace data", status.getEditCollection().get(1).getEditId());
}
Also used : PatchStatusContext(org.opendaylight.restconf.common.patch.PatchStatusContext) PatchContext(org.opendaylight.restconf.common.patch.PatchContext) PatchEntity(org.opendaylight.restconf.common.patch.PatchEntity) ArrayList(java.util.ArrayList) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 32 with InstanceIdentifierContext

use of org.opendaylight.restconf.common.context.InstanceIdentifierContext in project netconf by opendaylight.

the class PatchDataTransactionUtilTest method testPatchDataReplaceMergeAndRemove.

@Test
public void testPatchDataReplaceMergeAndRemove() {
    final PatchEntity entityReplace = new PatchEntity("edit1", REPLACE, this.targetNodeMerge, this.buildArtistList);
    final PatchEntity entityMerge = new PatchEntity("edit2", MERGE, this.targetNodeMerge, this.buildArtistList);
    final PatchEntity entityRemove = new PatchEntity("edit3", REMOVE, this.targetNodeMerge);
    final List<PatchEntity> entities = new ArrayList<>();
    entities.add(entityReplace);
    entities.add(entityMerge);
    entities.add(entityRemove);
    final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(this.instanceIdMerge, null, null, this.refSchemaCtx);
    final PatchContext patchContext = new PatchContext(iidContext, entities, "patchRMRm");
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(this.netconfService).remove(LogicalDatastoreType.CONFIGURATION, targetNodeMerge);
    patch(patchContext, new MdsalRestconfStrategy(mockDataBroker), false);
    patch(patchContext, new NetconfRestconfStrategy(netconfService), false);
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) 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 33 with InstanceIdentifierContext

use of org.opendaylight.restconf.common.context.InstanceIdentifierContext in project netconf by opendaylight.

the class PlainPatchDataTransactionUtilTest method testPatchContainerData.

@Test
public void testPatchContainerData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iidJukebox, schemaNodeForJukebox, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, jukeboxContainerWithPlayer);
    doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
    doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).merge(any(), any(), any(), any());
    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).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 34 with InstanceIdentifierContext

use of org.opendaylight.restconf.common.context.InstanceIdentifierContext 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 35 with InstanceIdentifierContext

use of org.opendaylight.restconf.common.context.InstanceIdentifierContext 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)

Aggregations

InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)50 Test (org.junit.Test)29 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)28 NormalizedNodePayload (org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload)26 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)24 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)20 ArrayList (java.util.ArrayList)18 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)16 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)15 List (java.util.List)14 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)14 QName (org.opendaylight.yangtools.yang.common.QName)14 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)14 Provider (javax.ws.rs.ext.Provider)13 IOException (java.io.IOException)12 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)12 PatchContext (org.opendaylight.restconf.common.patch.PatchContext)12 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)12 StandardCharsets (java.nio.charset.StandardCharsets)11 WebApplicationException (javax.ws.rs.WebApplicationException)11