Search in sources :

Example 21 with PatchContext

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));
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) 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) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) 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 22 with PatchContext

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

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);
}
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 24 with PatchContext

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);
}
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 25 with PatchContext

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

Aggregations

PatchContext (org.opendaylight.restconf.common.patch.PatchContext)42 Test (org.junit.Test)36 InputStream (java.io.InputStream)31 PatchEntity (org.opendaylight.restconf.common.patch.PatchEntity)11 ArrayList (java.util.ArrayList)9 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)9 PatchStatusContext (org.opendaylight.restconf.common.patch.PatchStatusContext)7 AbstractBodyReaderTest (org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest)7 JsonBodyReaderTest (org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 IOException (java.io.IOException)4 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 URISyntaxException (java.net.URISyntaxException)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)3 Verify.verify (com.google.common.base.Verify.verify)2