Search in sources :

Example 21 with InstanceIdentifierContext

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

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

the class PutDataTransactionUtilTest method testPutCreateLeafData.

@Test
public void testPutCreateLeafData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildLeaf);
    doReturn(immediateFluentFuture(Optional.empty())).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) Test(org.junit.Test)

Example 23 with InstanceIdentifierContext

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

the class PutDataTransactionUtilTest method testValidTopLevelNodeNameWrongTopIdentifier.

@Test
public void testValidTopLevelNodeNameWrongTopIdentifier() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildLeaf);
    // FIXME: more asserts
    assertThrows(RestconfDocumentedException.class, () -> RestconfDataServiceImpl.validTopLevelNodeName(iid.getAncestor(1), payload));
}
Also used : 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 24 with InstanceIdentifierContext

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

the class PutDataTransactionUtilTest method testPutReplaceListData.

@Test
public void testPutReplaceListData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, schemaNode2, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseContWithList);
    doReturn(immediateFluentFuture(Optional.of(mock(NormalizedNode.class)))).when(netconfService).getConfig(iid2);
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
    PutDataTransactionUtil.putData(payload, schema, new NetconfRestconfStrategy(netconfService), WriteDataParams.empty());
    verify(netconfService).getConfig(iid2);
    verify(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid2, 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 25 with InstanceIdentifierContext

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

the class NormalizedNodeXmlBodyWriter method writeNormalizedNode.

private static void writeNormalizedNode(final XMLStreamWriter xmlWriter, final InstanceIdentifierContext<?> pathContext, NormalizedNode data, @Nullable final Integer depth) throws IOException {
    final RestconfNormalizedNodeWriter nnWriter;
    final EffectiveModelContext schemaCtx = pathContext.getSchemaContext();
    if (pathContext.getSchemaNode() instanceof SchemaContext) {
        nnWriter = createNormalizedNodeWriter(xmlWriter, schemaCtx, SchemaPath.ROOT, depth);
        if (data instanceof DOMSourceAnyxmlNode) {
            try {
                writeElements(xmlWriter, nnWriter, (ContainerNode) NetconfUtil.transformDOMSourceToNormalizedNode(schemaCtx, ((DOMSourceAnyxmlNode) data).body()).getResult());
            } catch (XMLStreamException | URISyntaxException | SAXException e) {
                throw new IOException("Cannot write anyxml", e);
            }
        } else {
            writeElements(xmlWriter, nnWriter, (ContainerNode) data);
        }
    } else if (pathContext.getSchemaNode() instanceof RpcDefinition) {
        final RpcDefinition rpc = (RpcDefinition) pathContext.getSchemaNode();
        final SchemaPath path = SchemaPath.of(Absolute.of(rpc.getQName(), rpc.getOutput().getQName()));
        nnWriter = createNormalizedNodeWriter(xmlWriter, schemaCtx, path, depth);
        writeElements(xmlWriter, nnWriter, (ContainerNode) data);
    } else {
        final List<QName> qNames = pathContext.getInstanceIdentifier().getPathArguments().stream().filter(arg -> !(arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates)).filter(arg -> !(arg instanceof YangInstanceIdentifier.AugmentationIdentifier)).map(PathArgument::getNodeType).collect(Collectors.toList());
        final SchemaPath path = SchemaPath.of(Absolute.of(qNames)).getParent();
        nnWriter = createNormalizedNodeWriter(xmlWriter, schemaCtx, path, depth);
        if (data instanceof MapEntryNode) {
            // Restconf allows returning one list item. We need to wrap it
            // in map node in order to serialize it properly
            data = ImmutableNodes.mapNodeBuilder(data.getIdentifier().getNodeType()).addChild((MapEntryNode) data).build();
        }
        nnWriter.write(data);
    }
    nnWriter.flush();
}
Also used : SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) Produces(javax.ws.rs.Produces) Provider(javax.ws.rs.ext.Provider) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) URISyntaxException(java.net.URISyntaxException) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) Draft02(org.opendaylight.netconf.sal.rest.api.Draft02) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) NetconfUtil(org.opendaylight.netconf.util.NetconfUtil) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) MediaType(javax.ws.rs.core.MediaType) Nullable(org.eclipse.jdt.annotation.Nullable) XMLStreamException(javax.xml.stream.XMLStreamException) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XMLConstants(javax.xml.XMLConstants) RestconfService(org.opendaylight.netconf.sal.rest.api.RestconfService) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) OutputStream(java.io.OutputStream) RestconfNormalizedNodeWriter(org.opendaylight.netconf.sal.rest.api.RestconfNormalizedNodeWriter) IOException(java.io.IOException) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) QName(org.opendaylight.yangtools.yang.common.QName) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError) XMLStreamNormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.codec.xml.XMLStreamNormalizedNodeStreamWriter) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) List(java.util.List) IndentingXMLStreamWriter(javanet.staxutils.IndentingXMLStreamWriter) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) Type(java.lang.reflect.Type) NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) ImmutableNodes(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes) SAXException(org.xml.sax.SAXException) Annotation(java.lang.annotation.Annotation) Entry(java.util.Map.Entry) WebApplicationException(javax.ws.rs.WebApplicationException) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) RestconfNormalizedNodeWriter(org.opendaylight.netconf.sal.rest.api.RestconfNormalizedNodeWriter) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) SAXException(org.xml.sax.SAXException) XMLStreamException(javax.xml.stream.XMLStreamException) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) List(java.util.List) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

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