Search in sources :

Example 16 with InstanceIdentifierContext

use of org.opendaylight.restconf.common.context.InstanceIdentifierContext in project netconf by opendaylight.

the class PutDataTransactionUtilTest method testPutReplaceLeafData.

@Test
public void testPutReplaceLeafData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildLeaf);
    doReturn(immediateFluentFuture(Optional.of(mock(NormalizedNode.class)))).when(netconfService).getConfig(iid);
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid, payload.getData(), Optional.empty());
    PutDataTransactionUtil.putData(payload, schema, new NetconfRestconfStrategy(netconfService), WriteDataParams.empty());
    verify(netconfService).getConfig(iid);
    verify(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid, payload.getData(), Optional.empty());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 17 with InstanceIdentifierContext

use of org.opendaylight.restconf.common.context.InstanceIdentifierContext in project netconf by opendaylight.

the class PutDataTransactionUtilTest method testPutListData.

@Test
public void testPutListData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, schemaNode2, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseContWithList);
    doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
    doReturn(read).when(mockDataBroker).newReadOnlyTransaction();
    doReturn(immediateFalseFluentFuture()).when(read).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData());
    doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
    PutDataTransactionUtil.putData(payload, schema, new MdsalRestconfStrategy(mockDataBroker), WriteDataParams.empty());
    verify(read).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData());
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) Test(org.junit.Test)

Example 18 with InstanceIdentifierContext

use of org.opendaylight.restconf.common.context.InstanceIdentifierContext 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 19 with InstanceIdentifierContext

use of org.opendaylight.restconf.common.context.InstanceIdentifierContext in project netconf by opendaylight.

the class RestconfDataServiceImplTest method testPutData.

@Test
public void testPutData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iidBase, schemaNode, null, contextRef);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
    doReturn(immediateTrueFluentFuture()).when(read).exists(LogicalDatastoreType.CONFIGURATION, iidBase);
    doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, iidBase, payload.getData());
    final Response response = dataService.putData(null, payload, uriInfo);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) Test(org.junit.Test)

Example 20 with InstanceIdentifierContext

use of org.opendaylight.restconf.common.context.InstanceIdentifierContext 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)

Aggregations

InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)50 Test (org.junit.Test)29 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)28 NormalizedNodePayload (org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload)26 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)24 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)20 ArrayList (java.util.ArrayList)18 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)16 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)15 List (java.util.List)14 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)14 QName (org.opendaylight.yangtools.yang.common.QName)14 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)14 Provider (javax.ws.rs.ext.Provider)13 IOException (java.io.IOException)12 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)12 PatchContext (org.opendaylight.restconf.common.patch.PatchContext)12 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)12 StandardCharsets (java.nio.charset.StandardCharsets)11 WebApplicationException (javax.ws.rs.WebApplicationException)11