use of org.opendaylight.restconf.common.patch.PatchEntity 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.PatchEntity 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.PatchEntity 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.PatchEntity 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());
}
use of org.opendaylight.restconf.common.patch.PatchEntity 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());
}
Aggregations