use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.
the class PatchDataTransactionUtilTest method deleteNonexistentDataTest.
@Test
public void deleteNonexistentDataTest() {
doReturn(immediateFalseFluentFuture()).when(this.rwTransaction).exists(LogicalDatastoreType.CONFIGURATION, this.targetNodeForCreateAndDelete);
final NetconfDocumentedException exception = new NetconfDocumentedException("id", ErrorType.RPC, ErrorTag.DATA_MISSING, ErrorSeverity.ERROR);
final SettableFuture<? extends DOMRpcResult> ret = SettableFuture.create();
ret.setException(new TransactionCommitFailedException(String.format("Commit of transaction %s failed", this), exception));
doReturn(ret).when(this.netconfService).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(this.netconfService).delete(LogicalDatastoreType.CONFIGURATION, this.targetNodeForCreateAndDelete);
final PatchEntity entityDelete = new PatchEntity("edit", DELETE, this.targetNodeForCreateAndDelete);
final List<PatchEntity> entities = new ArrayList<>();
entities.add(entityDelete);
final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(this.instanceIdCreateAndDelete, null, null, this.refSchemaCtx);
final PatchContext patchContext = new PatchContext(iidContext, entities, "patchD");
deleteMdsal(patchContext, new MdsalRestconfStrategy(mockDataBroker));
deleteNetconf(patchContext, new NetconfRestconfStrategy(netconfService));
}
use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.
the class RestconfDataServiceImplTest method testPatchDataMountPoint.
@Test
public void testPatchDataMountPoint() throws Exception {
final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iidBase, schemaNode, mountPoint, 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());
assertNull(status.getGlobalErrors());
}
use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.
the class RestconfDataServiceImplTest method testPatchDataDeleteNotExist.
@Test
public void testPatchDataDeleteNotExist() {
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("remove data", REMOVE, iidleaf));
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(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
doReturn(true).when(readWrite).cancel();
final PatchStatusContext status = dataService.patchData(patch, uriInfo);
assertFalse(status.isOk());
assertEquals(3, status.getEditCollection().size());
assertTrue(status.getEditCollection().get(0).isOk());
assertTrue(status.getEditCollection().get(1).isOk());
assertFalse(status.getEditCollection().get(2).isOk());
assertFalse(status.getEditCollection().get(2).getEditErrors().isEmpty());
final String errorMessage = status.getEditCollection().get(2).getEditErrors().get(0).getErrorMessage();
assertEquals("Data does not exist", errorMessage);
}
use of org.opendaylight.restconf.common.patch.PatchContext 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);
}
use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.
the class JsonToPatchBodyReader method readFrom.
private PatchContext readFrom(final InstanceIdentifierContext<?> path, final InputStream entityStream) throws IOException {
final Optional<InputStream> nonEmptyInputStreamOptional = RestUtil.isInputStreamEmpty(entityStream);
if (nonEmptyInputStreamOptional.isEmpty()) {
return new PatchContext(path, null, null);
}
final JsonReader jsonReader = new JsonReader(new InputStreamReader(nonEmptyInputStreamOptional.get(), StandardCharsets.UTF_8));
AtomicReference<String> patchId = new AtomicReference<>();
final List<PatchEntity> resultList = read(jsonReader, path, patchId);
jsonReader.close();
return new PatchContext(path, resultList, patchId.get());
}
Aggregations