Search in sources :

Example 6 with PatchEntity

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

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);
}
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 8 with PatchEntity

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);
}
Also used : 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 9 with PatchEntity

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());
}
Also used : PatchContext(org.opendaylight.restconf.common.patch.PatchContext) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) PatchEntity(org.opendaylight.restconf.common.patch.PatchEntity) JsonReader(com.google.gson.stream.JsonReader) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 10 with PatchEntity

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

Aggregations

PatchEntity (org.opendaylight.restconf.common.patch.PatchEntity)13 ArrayList (java.util.ArrayList)11 PatchContext (org.opendaylight.restconf.common.patch.PatchContext)11 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)9 Test (org.junit.Test)7 PatchStatusContext (org.opendaylight.restconf.common.patch.PatchStatusContext)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)4 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)4 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)4 InputStream (java.io.InputStream)3 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)3 PatchEditOperation (org.opendaylight.restconf.common.patch.PatchEditOperation)3 Verify.verify (com.google.common.base.Verify.verify)2 Verify.verifyNotNull (com.google.common.base.Verify.verifyNotNull)2 ImmutableList (com.google.common.collect.ImmutableList)2 JsonReader (com.google.gson.stream.JsonReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 URISyntaxException (java.net.URISyntaxException)2