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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations