From f592c25a4ebfab56abb5a4f5fbeb1e5ce1d9c26d Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 7 Apr 2024 14:54:36 +0200 Subject: [PATCH] Introduce restconf.server.api.HttpGetResource HttpGetResource is a useful tool which forces all implementations to behave in the same manner. We want httpGet() to return a FormattableBody, which we achieve here for both OperationsResource and YangLibraryVersionResource. The latter also gives a useful utility in NormalizedFormattableBody, which captures the essence of NormalizedNodePayload sans special handling. JIRA: NETCONF-773 Change-Id: I48f2c7dec979639c3466024677a36a89919281b7 Signed-off-by: Robert Varga --- .../nb/jaxrs/FormattableBodyCallback.java | 27 ++++++ .../restconf/nb/jaxrs/JaxRsRestconf.java | 21 +---- .../ParameterAwareNormalizedNodeWriter.java | 17 +++- .../transactions/MdsalRestconfStrategy.java | 9 +- .../rests/transactions/RestconfStrategy.java | 13 ++- .../server/api/DatabindFormattableBody.java | 50 ++++++++++ .../api/DatabindPathFormattableBody.java | 41 ++++++++ .../restconf/server/api/RestconfServer.java | 2 +- .../server/mdsal/MdsalRestconfServer.java | 19 ++-- .../DefaultYangLibraryVersionResource.java | 37 -------- ...source.java => FailedHttpGetResource.java} | 14 ++- .../restconf/server/spi/HttpGetResource.java | 25 +++++ .../server/spi/NormalizedFormattableBody.java | 93 +++++++++++++++++++ .../server/spi/OperationOutputBody.java | 32 +++---- .../server/spi/OperationsResource.java | 16 ++-- .../spi/YangLibraryVersionResource.java | 51 +++++++--- .../RestconfYangLibraryVersionGetTest.java | 14 +-- ...terAwareNormalizedNodeWriterDepthTest.java | 20 ++-- ...areNormalizedNodeWriterParametersTest.java | 4 +- 19 files changed, 371 insertions(+), 134 deletions(-) create mode 100644 restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/FormattableBodyCallback.java create mode 100644 restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DatabindFormattableBody.java create mode 100644 restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DatabindPathFormattableBody.java delete mode 100644 restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/DefaultYangLibraryVersionResource.java rename restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/{FailedYangLibraryVersionResource.java => FailedHttpGetResource.java} (61%) create mode 100644 restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/HttpGetResource.java create mode 100644 restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/NormalizedFormattableBody.java diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/FormattableBodyCallback.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/FormattableBodyCallback.java new file mode 100644 index 0000000000..045875293f --- /dev/null +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/FormattableBodyCallback.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.restconf.nb.jaxrs; + +import javax.ws.rs.container.AsyncResponse; +import javax.ws.rs.core.Response; +import org.opendaylight.restconf.api.FormattableBody; +import org.opendaylight.restconf.common.errors.RestconfDocumentedException; + +/** + * A {@link JaxRsRestconfCallback} producing a {@link FormattableBody}. + */ +final class FormattableBodyCallback extends JaxRsRestconfCallback { + FormattableBodyCallback(final AsyncResponse ar) { + super(ar); + } + + @Override + Response transform(final FormattableBody result) throws RestconfDocumentedException { + return Response.ok().entity(result).build(); + } +} diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java index 4a56692bb2..69803105dc 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java @@ -45,7 +45,6 @@ import javax.ws.rs.ext.ParamConverterProvider; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.restconf.api.ApiPath; -import org.opendaylight.restconf.api.FormattableBody; import org.opendaylight.restconf.api.MediaTypes; import org.opendaylight.restconf.api.QueryParameters; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; @@ -646,7 +645,7 @@ public final class JaxRsRestconf implements ParamConverterProvider { MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON }) public void operationsGET(@Suspended final AsyncResponse ar) { - completeOperationsGet(server.operationsGET(), ar); + server.operationsGET().addCallback(new FormattableBodyCallback(ar)); } /** @@ -662,16 +661,7 @@ public final class JaxRsRestconf implements ParamConverterProvider { MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON }) public void operationsGET(@PathParam("operation") final ApiPath operation, @Suspended final AsyncResponse ar) { - completeOperationsGet(server.operationsGET(operation), ar); - } - - private static void completeOperationsGet(final RestconfFuture future, final AsyncResponse ar) { - future.addCallback(new JaxRsRestconfCallback(ar) { - @Override - Response transform(final FormattableBody result) { - return Response.ok().entity(result).build(); - } - }); + server.operationsGET(operation).addCallback(new FormattableBodyCallback(ar)); } /** @@ -761,12 +751,7 @@ public final class JaxRsRestconf implements ParamConverterProvider { MediaType.TEXT_XML }) public void yangLibraryVersionGET(@Suspended final AsyncResponse ar) { - server.yangLibraryVersionGET().addCallback(new JaxRsRestconfCallback(ar) { - @Override - Response transform(final NormalizedNodePayload result) { - return Response.ok().entity(result).build(); - } - }); + server.yangLibraryVersionGET().addCallback(new FormattableBodyCallback(ar)); } // FIXME: References to these resources are generated by our yang-library implementation. That means: diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriter.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriter.java index 21eec1321c..ba06afacc8 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriter.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriter.java @@ -17,6 +17,7 @@ import java.util.Map.Entry; import java.util.Set; import javax.xml.transform.dom.DOMSource; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.restconf.api.query.DepthParam; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.api.RestconfNormalizedNodeWriter; import org.opendaylight.yangtools.yang.common.Ordering; @@ -66,6 +67,18 @@ public class ParameterAwareNormalizedNodeWriter implements RestconfNormalizedNod return writer; } + /** + * Create a new writer backed by a {@link NormalizedNodeStreamWriter}. + * + * @param writer Back-end writer + * @param maxDepth Maximal depth to write + * @return A new instance. + */ + public static @NonNull ParameterAwareNormalizedNodeWriter forStreamWriter(final NormalizedNodeStreamWriter writer, + final @Nullable DepthParam maxDepth) { + return forStreamWriter(writer, true, maxDepth, null); + } + /** * Create a new writer backed by a {@link NormalizedNodeStreamWriter}. * @@ -74,8 +87,8 @@ public class ParameterAwareNormalizedNodeWriter implements RestconfNormalizedNod * @param fields Selected child nodes to write * @return A new instance. */ - public static @NonNull ParameterAwareNormalizedNodeWriter forStreamWriter( - final NormalizedNodeStreamWriter writer, final DepthParam maxDepth, final List> fields) { + public static @NonNull ParameterAwareNormalizedNodeWriter forStreamWriter(final NormalizedNodeStreamWriter writer, + final @Nullable DepthParam maxDepth, final List> fields) { return forStreamWriter(writer, true, maxDepth, fields); } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfStrategy.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfStrategy.java index 313a9e9ac8..6ee59fc26d 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfStrategy.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfStrategy.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Optional; import java.util.Set; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; @@ -31,19 +32,20 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.mdsal.dom.api.DOMRpcService; import org.opendaylight.mdsal.dom.api.DOMSchemaService.YangTextSourceExtension; import org.opendaylight.mdsal.dom.api.DOMTransactionChain; +import org.opendaylight.restconf.api.FormattableBody; import org.opendaylight.restconf.api.query.FieldsParam; import org.opendaylight.restconf.api.query.FieldsParam.NodeSelector; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfFuture; import org.opendaylight.restconf.common.errors.SettableRestconfFuture; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.ParameterAwareNormalizedNodeWriter; -import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.restconf.nb.rfc8040.legacy.WriterParameters; import org.opendaylight.restconf.server.api.DataGetParams; import org.opendaylight.restconf.server.api.DataGetResult; import org.opendaylight.restconf.server.api.DatabindContext; import org.opendaylight.restconf.server.api.DatabindPath.Data; import org.opendaylight.restconf.server.api.QueryParams; +import org.opendaylight.restconf.server.spi.HttpGetResource; import org.opendaylight.restconf.server.spi.RpcImplementation; import org.opendaylight.restconf.server.spi.YangLibraryVersionResource; import org.opendaylight.yangtools.yang.common.Empty; @@ -64,7 +66,7 @@ import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; * @see DOMDataTreeReadWriteTransaction */ public final class MdsalRestconfStrategy extends RestconfStrategy { - private final @NonNull YangLibraryVersionResource yangLibraryVersion; + private final @NonNull HttpGetResource yangLibraryVersion; private final @NonNull DOMDataBroker dataBroker; public MdsalRestconfStrategy(final DatabindContext databind, final DOMDataBroker dataBroker, @@ -76,7 +78,8 @@ public final class MdsalRestconfStrategy extends RestconfStrategy { yangLibraryVersion = YangLibraryVersionResource.of(databind); } - public @NonNull RestconfFuture yangLibraryVersionGET(final QueryParams params) { + @NonNullByDefault + public RestconfFuture yangLibraryVersionGET(final QueryParams params) { return yangLibraryVersion.httpGET(params); } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfStrategy.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfStrategy.java index 56b8b7e62b..2f8329f9e3 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfStrategy.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfStrategy.java @@ -91,6 +91,7 @@ import org.opendaylight.restconf.server.api.ResourceBody; import org.opendaylight.restconf.server.spi.ApiPathCanonizer; import org.opendaylight.restconf.server.spi.ApiPathNormalizer; import org.opendaylight.restconf.server.spi.DefaultResourceContext; +import org.opendaylight.restconf.server.spi.HttpGetResource; import org.opendaylight.restconf.server.spi.OperationInput; import org.opendaylight.restconf.server.spi.OperationOutputBody; import org.opendaylight.restconf.server.spi.OperationsResource; @@ -186,7 +187,7 @@ public abstract class RestconfStrategy { private final DOMMountPointService mountPointService; private final DOMActionService actionService; private final DOMRpcService rpcService; - private final OperationsResource operations; + private final HttpGetResource operations; RestconfStrategy(final DatabindContext databind, final ImmutableMap localRpcs, final @Nullable DOMRpcService rpcService, final @Nullable DOMActionService actionService, @@ -1255,12 +1256,14 @@ public abstract class RestconfStrategy { y -> builder.addChild((T) prepareData(y.getValue(), stateMap.get(y.getKey())))); } - public @NonNull RestconfFuture operationsGET() { - return operations.httpGET(); + @NonNullByDefault + public RestconfFuture operationsGET(final QueryParams params) { + return operations.httpGET(params); } - public @NonNull RestconfFuture operationsGET(final ApiPath apiPath) { - return operations.httpGET(apiPath); + @NonNullByDefault + public RestconfFuture operationsGET(final ApiPath apiPath, final QueryParams params) { + return operations.httpGET(apiPath, params); } public @NonNull RestconfFuture operationsPOST(final URI restconfURI, final ApiPath apiPath, diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DatabindFormattableBody.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DatabindFormattableBody.java new file mode 100644 index 0000000000..71daa7645e --- /dev/null +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DatabindFormattableBody.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.restconf.server.api; + +import static java.util.Objects.requireNonNull; + +import java.io.IOException; +import java.io.OutputStream; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.opendaylight.restconf.api.FormatParameters; +import org.opendaylight.restconf.api.FormattableBody; + +/** + * A {@link FormattableBody} which has an attached {@link DatabindContext}. + */ +@NonNullByDefault +public abstract class DatabindFormattableBody extends FormattableBody implements DatabindAware { + private final DatabindContext databind; + + protected DatabindFormattableBody(final FormatParameters format, final DatabindContext databind) { + super(format); + this.databind = requireNonNull(databind); + } + + @Override + public final DatabindContext databind() { + return databind; + } + + @Override + protected final void formatToJSON(final OutputStream out, final FormatParameters format) throws IOException { + formatToJSON(out, format, databind()); + } + + protected abstract void formatToJSON(OutputStream out, FormatParameters format, DatabindContext databind) + throws IOException; + + @Override + protected final void formatToXML(final OutputStream out, final FormatParameters format) throws IOException { + formatToXML(out, format, databind()); + } + + protected abstract void formatToXML(OutputStream out, FormatParameters format, DatabindContext databind) + throws IOException; +} diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DatabindPathFormattableBody.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DatabindPathFormattableBody.java new file mode 100644 index 0000000000..2a09b34f61 --- /dev/null +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DatabindPathFormattableBody.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.restconf.server.api; + +import static java.util.Objects.requireNonNull; + +import com.google.common.base.MoreObjects.ToStringHelper; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.restconf.api.FormatParameters; +import org.opendaylight.restconf.api.FormattableBody; + +/** + * A {@link FormattableBody} which has an attached {@link DatabindPath}. + */ +@NonNullByDefault +public abstract class DatabindPathFormattableBody

extends FormattableBody { + private final @NonNull P path; + + protected DatabindPathFormattableBody(final FormatParameters format, final P path) { + super(format); + this.path = requireNonNull(path); + } + + public final P path() { + return path; + } + + @Override + protected ToStringHelper addToStringAttributes(final ToStringHelper helper) { + return super.addToStringAttributes(helper.add("path", path).add("body", bodyAttribute())); + } + + protected abstract @Nullable Object bodyAttribute(); +} diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/RestconfServer.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/RestconfServer.java index bbfce15d30..0586fd20e5 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/RestconfServer.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/RestconfServer.java @@ -167,7 +167,7 @@ public interface RestconfServer { */ // FIXME: this is a simple encoding-variadic return, similar to how OperationsContent is handled use a common // construct for both cases -- in this case it carries a yang.common.Revision - RestconfFuture yangLibraryVersionGET(); + RestconfFuture yangLibraryVersionGET(); RestconfFuture modulesYangGET(String fileName, @Nullable String revision); diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/MdsalRestconfServer.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/MdsalRestconfServer.java index a7692c50bc..8045a00c4a 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/MdsalRestconfServer.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/MdsalRestconfServer.java @@ -34,7 +34,6 @@ import org.opendaylight.restconf.api.QueryParameters; import org.opendaylight.restconf.api.query.PrettyPrintParam; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfFuture; -import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy; import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy; import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy.StrategyAndTail; @@ -97,7 +96,7 @@ public final class MdsalRestconfServer implements RestconfServer, AutoCloseable private final @NonNull DOMDataBroker dataBroker; private final @Nullable DOMRpcService rpcService; private final @Nullable DOMActionService actionService; - private final @NonNull PrettyPrintParam prettyPrint; + private final @NonNull QueryParams emptyQueryParams; @SuppressFBWarnings(value = "URF_UNREAD_FIELD", justification = "https://github.com/spotbugs/spotbugs/issues/2749") private volatile MdsalRestconfStrategy localStrategy; @@ -111,7 +110,7 @@ public final class MdsalRestconfServer implements RestconfServer, AutoCloseable this.rpcService = requireNonNull(rpcService); this.actionService = requireNonNull(actionService); this.mountPointService = requireNonNull(mountPointService); - this.prettyPrint = requireNonNull(prettyPrint); + emptyQueryParams = new QueryParams(QueryParameters.of(), prettyPrint); this.localRpcs = Maps.uniqueIndex(localRpcs, RpcImplementation::qname); localStrategy = createLocalStrategy(databindProvider.currentDatabind()); @@ -177,7 +176,7 @@ public final class MdsalRestconfServer implements RestconfServer, AutoCloseable } private @NonNull QueryParams queryParams(final @NonNull QueryParameters params) { - return new QueryParams(params, prettyPrint); + return params.isEmpty() ? emptyQueryParams : new QueryParams(params, emptyQueryParams.prettyPrint()); } @Override @@ -354,7 +353,7 @@ public final class MdsalRestconfServer implements RestconfServer, AutoCloseable @Override public RestconfFuture operationsGET() { - return localStrategy().operationsGET(); + return localStrategy().operationsGET(emptyQueryParams); } @Override @@ -365,7 +364,11 @@ public final class MdsalRestconfServer implements RestconfServer, AutoCloseable } catch (RestconfDocumentedException e) { return RestconfFuture.failed(e); } - return strategyAndTail.strategy().operationsGET(strategyAndTail.tail()); + + final var strategy = strategyAndTail.strategy(); + final var tail = strategyAndTail.tail(); + return tail.steps().isEmpty() ? strategy.operationsGET(emptyQueryParams) + : strategy.operationsGET(tail, emptyQueryParams); } @Override @@ -382,7 +385,7 @@ public final class MdsalRestconfServer implements RestconfServer, AutoCloseable } @Override - public RestconfFuture yangLibraryVersionGET() { - return localStrategy().yangLibraryVersionGET(queryParams(QueryParameters.of())); + public RestconfFuture yangLibraryVersionGET() { + return localStrategy().yangLibraryVersionGET(emptyQueryParams); } } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/DefaultYangLibraryVersionResource.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/DefaultYangLibraryVersionResource.java deleted file mode 100644 index 00f4967f0c..0000000000 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/DefaultYangLibraryVersionResource.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.restconf.server.spi; - -import static java.util.Objects.requireNonNull; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.opendaylight.restconf.common.errors.RestconfFuture; -import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; -import org.opendaylight.restconf.nb.rfc8040.legacy.WriterParameters; -import org.opendaylight.restconf.server.api.QueryParams; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.restconf.Restconf; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; -import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference; - -@NonNullByDefault -record DefaultYangLibraryVersionResource(Inference leafInference, LeafNode leaf) - implements YangLibraryVersionResource { - static final QName YANG_LIBRARY_VERSION = QName.create(Restconf.QNAME, "yang-library-version").intern(); - - DefaultYangLibraryVersionResource { - requireNonNull(leafInference); - requireNonNull(leaf); - } - - @Override - public RestconfFuture httpGET(final QueryParams params) { - return RestconfFuture.of(new NormalizedNodePayload(leafInference, leaf, - WriterParameters.of(params.prettyPrint(), null))); - } -} \ No newline at end of file diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/FailedYangLibraryVersionResource.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/FailedHttpGetResource.java similarity index 61% rename from restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/FailedYangLibraryVersionResource.java rename to restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/FailedHttpGetResource.java index e8e09319bd..09cabde2fa 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/FailedYangLibraryVersionResource.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/FailedHttpGetResource.java @@ -10,19 +10,25 @@ package org.opendaylight.restconf.server.spi; import static java.util.Objects.requireNonNull; import org.eclipse.jdt.annotation.NonNullByDefault; +import org.opendaylight.restconf.api.ApiPath; +import org.opendaylight.restconf.api.FormattableBody; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfFuture; -import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.restconf.server.api.QueryParams; @NonNullByDefault -record FailedYangLibraryVersionResource(RestconfDocumentedException cause) implements YangLibraryVersionResource { - FailedYangLibraryVersionResource { +public record FailedHttpGetResource(RestconfDocumentedException cause) implements HttpGetResource { + public FailedHttpGetResource { requireNonNull(cause); } @Override - public RestconfFuture httpGET(final QueryParams params) { + public RestconfFuture httpGET(final QueryParams params) { return RestconfFuture.failed(cause); } + + @Override + public RestconfFuture httpGET(final ApiPath apiPath, final QueryParams params) { + throw new UnsupportedOperationException(); + } } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/HttpGetResource.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/HttpGetResource.java new file mode 100644 index 0000000000..a616a0a629 --- /dev/null +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/HttpGetResource.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.restconf.server.spi; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.opendaylight.restconf.api.ApiPath; +import org.opendaylight.restconf.api.FormattableBody; +import org.opendaylight.restconf.common.errors.RestconfFuture; +import org.opendaylight.restconf.server.api.QueryParams; + +/** + * A resource which supports HTTP GET and produces a {@link FormattableBody}. + */ +@NonNullByDefault +public interface HttpGetResource { + + RestconfFuture httpGET(QueryParams params); + + RestconfFuture httpGET(ApiPath apiPath, QueryParams params); +} diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/NormalizedFormattableBody.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/NormalizedFormattableBody.java new file mode 100644 index 0000000000..2088ed7a7e --- /dev/null +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/NormalizedFormattableBody.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.restconf.server.spi; + +import static com.google.common.base.Verify.verify; +import static java.util.Objects.requireNonNull; + +import com.google.common.base.MoreObjects.ToStringHelper; +import java.io.IOException; +import java.io.OutputStream; +import javax.xml.stream.XMLStreamException; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.opendaylight.restconf.api.FormatParameters; +import org.opendaylight.restconf.api.FormattableBody; +import org.opendaylight.restconf.server.api.DatabindContext; +import org.opendaylight.restconf.server.api.DatabindFormattableBody; +import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; +import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; +import org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamWriter; +import org.opendaylight.yangtools.yang.data.codec.xml.XMLStreamNormalizedNodeStreamWriter; +import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement; +import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference; + +/** + * A {@link FormattableBody} representing a data resource. + */ +@NonNullByDefault +public final class NormalizedFormattableBody extends DatabindFormattableBody { + private final Inference parent; + private final N data; + + public NormalizedFormattableBody(final FormatParameters format, final DatabindContext databind, + final Inference parent, final N data) { + super(format, databind); + this.parent = requireNonNull(parent); + this.data = requireNonNull(data); + // RESTCONF allows returning one list item. We need to wrap it in map node in order to serialize it properly, + // which is where the notion of "parent Inference" may be confusing. We mean + // 'inference to the parent NormalizedNode', which for *EntryNode ends up the corresponding statement + if (data instanceof MapEntryNode) { + verifyParent(parent, ListEffectiveStatement.class, data); + } else if (data instanceof LeafSetEntryNode) { + verifyParent(parent, LeafListEffectiveStatement.class, data); + } + } + + private static void verifyParent(final Inference inference, + final Class> expectedStmt, final NormalizedNode data) { + // Let's not bother with niceties of error report -- if we trip here, the caller is doing the wrong + final var qname = expectedStmt.cast(inference.toSchemaInferenceStack().currentStatement()).argument(); + verify(qname.equals(data.name().getNodeType())); + } + + @Override + protected void formatToJSON(final OutputStream out, final FormatParameters format, final DatabindContext databind) + throws IOException { + writeTo(JSONNormalizedNodeStreamWriter.createExclusiveWriter(databind.jsonCodecs(), parent, null, + FormattableBodySupport.createJsonWriter(out, format))); + } + + @Override + protected void formatToXML(final OutputStream out, final FormatParameters format, final DatabindContext databind) + throws IOException { + final var xmlWriter = FormattableBodySupport.createXmlWriter(out, format); + writeTo(XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, parent)); + try { + xmlWriter.close(); + } catch (XMLStreamException e) { + throw new IOException("Failed to write data", e); + } + } + + @Override + protected ToStringHelper addToStringAttributes(final ToStringHelper helper) { + return super.addToStringAttributes(helper.add("body", data.prettyTree())); + } + + private void writeTo(final NormalizedNodeStreamWriter streamWriter) throws IOException { + try (var writer = NormalizedNodeWriter.forStreamWriter(streamWriter)) { + writer.write(data); + } + } +} diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationOutputBody.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationOutputBody.java index 533db93ac0..eb348307c9 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationOutputBody.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationOutputBody.java @@ -10,20 +10,20 @@ package org.opendaylight.restconf.server.spi; import static java.util.Objects.requireNonNull; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.MoreObjects.ToStringHelper; import java.io.IOException; import java.io.OutputStream; import javax.xml.XMLConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.opendaylight.restconf.api.FormatParameters; import org.opendaylight.restconf.api.FormattableBody; -import org.opendaylight.restconf.nb.rfc8040.jersey.providers.ParameterAwareNormalizedNodeWriter; -import org.opendaylight.restconf.nb.rfc8040.jersey.providers.api.RestconfNormalizedNodeWriter; import org.opendaylight.restconf.server.api.DatabindPath.OperationPath; +import org.opendaylight.restconf.server.api.DatabindPathFormattableBody; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; import org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.codec.xml.XMLStreamNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack; @@ -32,13 +32,11 @@ import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack; * A {@link FormattableBody} corresponding to a {@code rpc} or {@code action} invocation. */ @NonNullByDefault -public final class OperationOutputBody extends FormattableBody { - private final OperationPath path; +public final class OperationOutputBody extends DatabindPathFormattableBody { private final ContainerNode output; public OperationOutputBody(final FormatParameters format, final OperationPath path, final ContainerNode output) { - super(format); - this.path = requireNonNull(path); + super(format, path); this.output = requireNonNull(output); if (output.isEmpty()) { throw new IllegalArgumentException("output may not be empty"); @@ -51,7 +49,8 @@ public final class OperationOutputBody extends FormattableBody { } @Override - protected void formatToJSON(final OutputStream out, final FormatParameters format) throws IOException { + protected void formatToJSON(final OutputStream out, final FormatParameters format) + throws IOException { final var stack = prepareStack(); // RpcDefinition/ActionDefinition is not supported as initial codec in JSONStreamWriter, so we need to emit @@ -60,9 +59,9 @@ public final class OperationOutputBody extends FormattableBody { final var module = stack.currentModule(); jsonWriter.beginObject().name(module.argument().getLocalName() + ":output").beginObject(); - final var nnWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter( - JSONNormalizedNodeStreamWriter.createNestedWriter(path.databind().jsonCodecs(), stack.toInference(), - module.namespace().argument(), jsonWriter), null, null); + final var nnWriter = NormalizedNodeWriter.forStreamWriter( + JSONNormalizedNodeStreamWriter.createNestedWriter(path().databind().jsonCodecs(), stack.toInference(), + module.namespace().argument(), jsonWriter)); for (var child : output.body()) { nnWriter.write(child); } @@ -79,25 +78,26 @@ public final class OperationOutputBody extends FormattableBody { // RpcDefinition/ActionDefinition is not supported as initial codec in XMLStreamWriter, so we need to emit // initial output declaration. final var xmlWriter = FormattableBodySupport.createXmlWriter(out, format); - final var nnWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter( - XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, stack.toInference()), null, null); + final var nnWriter = NormalizedNodeWriter.forStreamWriter( + XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, stack.toInference())); writeElements(xmlWriter, nnWriter, output); nnWriter.flush(); } @Override - protected ToStringHelper addToStringAttributes(final ToStringHelper helper) { - return super.addToStringAttributes(helper.add("path", path).add("output", output.prettyTree())); + protected @NonNull Object bodyAttribute() { + return output.prettyTree(); } private SchemaInferenceStack prepareStack() { + final var path = path(); final var stack = path.inference().toSchemaInferenceStack(); stack.enterSchemaTree(path.outputStatement().argument()); return stack; } - private static void writeElements(final XMLStreamWriter xmlWriter, final RestconfNormalizedNodeWriter nnWriter, + private static void writeElements(final XMLStreamWriter xmlWriter, final NormalizedNodeWriter nnWriter, final ContainerNode data) throws IOException { final QName nodeType = data.name().getNodeType(); final String namespace = nodeType.getNamespace().toString(); diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationsResource.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationsResource.java index b58d463dd9..7a041d798a 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationsResource.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/OperationsResource.java @@ -15,12 +15,13 @@ import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.opendaylight.restconf.api.ApiPath; import org.opendaylight.restconf.api.FormattableBody; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfFuture; import org.opendaylight.restconf.server.api.DatabindPath.Rpc; +import org.opendaylight.restconf.server.api.QueryParams; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.Revision; @@ -31,14 +32,16 @@ import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement; * RESTCONF {@code /operations} content for a {@code GET} operation as per * RFC8040. */ -public final class OperationsResource { +@NonNullByDefault +public final class OperationsResource implements HttpGetResource { private final ApiPathNormalizer pathNormalizer; public OperationsResource(final ApiPathNormalizer pathNormalizer) { this.pathNormalizer = requireNonNull(pathNormalizer); } - public @NonNull RestconfFuture httpGET() { + @Override + public RestconfFuture httpGET(final QueryParams params) { // RPC QNames by their XMLNamespace/Revision. This should be a Table, but Revision can be null, which wrecks us. final var table = new HashMap>>(); final var modelContext = pathNormalizer.databind().modelContext(); @@ -65,11 +68,8 @@ public final class OperationsResource { return RestconfFuture.of(new AllOperations(modelContext, rpcs.build())); } - public @NonNull RestconfFuture httpGET(final ApiPath apiPath) { - if (apiPath.steps().isEmpty()) { - return httpGET(); - } - + @Override + public RestconfFuture httpGET(final ApiPath apiPath, final QueryParams params) { final Rpc path; try { path = pathNormalizer.normalizeRpcPath(apiPath); diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/YangLibraryVersionResource.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/YangLibraryVersionResource.java index eeb5db2529..f6944c2d95 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/YangLibraryVersionResource.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/YangLibraryVersionResource.java @@ -7,29 +7,42 @@ */ package org.opendaylight.restconf.server.spi; +import static java.util.Objects.requireNonNull; + import org.eclipse.jdt.annotation.NonNullByDefault; +import org.opendaylight.restconf.api.ApiPath; +import org.opendaylight.restconf.api.FormattableBody; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfFuture; -import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; import org.opendaylight.restconf.server.api.DatabindContext; import org.opendaylight.restconf.server.api.QueryParams; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.YangApi; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.restconf.Restconf; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack; import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * RESTCONF {@code /yang-library-version} content for a {@code GET} operation as per * RFC8040, section 3.3.3. */ @NonNullByDefault -public sealed interface YangLibraryVersionResource - permits DefaultYangLibraryVersionResource, FailedYangLibraryVersionResource { +public record YangLibraryVersionResource(DatabindContext databind, Inference restconf, LeafNode leaf) + implements HttpGetResource { + private static final Logger LOG = LoggerFactory.getLogger(YangLibraryVersionResource.class); + private static final QName YANG_LIBRARY_VERSION = QName.create(Restconf.QNAME, "yang-library-version").intern(); - RestconfFuture httpGET(QueryParams params); + public YangLibraryVersionResource { + requireNonNull(databind); + requireNonNull(restconf); + requireNonNull(leaf); + } - static YangLibraryVersionResource of(final DatabindContext databind) { + public static HttpGetResource of(final DatabindContext databind) { final var modelContext = databind.modelContext(); final Inference leafInference; @@ -37,18 +50,32 @@ public sealed interface YangLibraryVersionResource final var stack = SchemaInferenceStack.of(modelContext); stack.enterYangData(YangApi.NAME); stack.enterDataTree(Restconf.QNAME); - stack.enterDataTree(DefaultYangLibraryVersionResource.YANG_LIBRARY_VERSION); + stack.enterDataTree(YANG_LIBRARY_VERSION); + stack.exitToDataTree(); leafInference = stack.toInference(); } catch (IllegalArgumentException e) { - return new FailedYangLibraryVersionResource(new RestconfDocumentedException( + LOG.debug("Cannot find yang-library-version", e); + return new FailedHttpGetResource(new RestconfDocumentedException( "yang-library-version is not available", e)); } final var it = modelContext.findModuleStatements("ietf-yang-library").iterator(); - return it.hasNext() - ? new DefaultYangLibraryVersionResource(leafInference, - ImmutableNodes.leafNode(DefaultYangLibraryVersionResource.YANG_LIBRARY_VERSION, - it.next().localQNameModule().revisionUnion().unionString())) - : new FailedYangLibraryVersionResource(new RestconfDocumentedException("No ietf-yang-library present")); + if (!it.hasNext()) { + LOG.debug("Cannot find ietf-yang-library"); + return new FailedHttpGetResource(new RestconfDocumentedException("No ietf-yang-library present")); + } + + return new YangLibraryVersionResource(databind, leafInference, + ImmutableNodes.leafNode(YANG_LIBRARY_VERSION, it.next().localQNameModule().revisionUnion().unionString())); + } + + @Override + public RestconfFuture httpGET(final QueryParams params) { + return RestconfFuture.of(new NormalizedFormattableBody<>(params::prettyPrint, databind, restconf, leaf)); + } + + @Override + public RestconfFuture httpGET(final ApiPath apiPath, final QueryParams params) { + throw new UnsupportedOperationException(); } } diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfYangLibraryVersionGetTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfYangLibraryVersionGetTest.java index 69ef89494c..1dac52090f 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfYangLibraryVersionGetTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfYangLibraryVersionGetTest.java @@ -7,14 +7,9 @@ */ package org.opendaylight.restconf.nb.jaxrs; -import static org.junit.jupiter.api.Assertions.assertEquals; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.Restconf; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @@ -27,7 +22,12 @@ class RestconfYangLibraryVersionGetTest extends AbstractRestconfTest { @Test void testLibraryVersion() { - assertEquals(ImmutableNodes.leafNode(QName.create(Restconf.QNAME, "yang-library-version"), "2019-01-04"), - assertNormalizedNode(200, ar -> restconf.yangLibraryVersionGET(ar))); + final var body = assertFormatableBody(200, ar -> restconf.yangLibraryVersionGET(ar)); + + assertFormat(""" + {"ietf-restconf:yang-library-version":"2019-01-04"}""", body::formatToJSON); + assertFormat(""" + 2019-01-04\ + """, body::formatToXML); } } diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriterDepthTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriterDepthTest.java index a6a8fb8332..ae15892556 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriterDepthTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriterDepthTest.java @@ -88,7 +88,7 @@ public class ParameterAwareNormalizedNodeWriterDepthTest { */ @Test public void writeContainerWithoutChildrenDepthTest() throws Exception { - final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.min(), null); + final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.min()); parameterWriter.write(containerNodeData); @@ -104,7 +104,7 @@ public class ParameterAwareNormalizedNodeWriterDepthTest { */ @Test public void writeContainerWithChildrenDepthTest() throws Exception { - final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.max(), null); + final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.max()); parameterWriter.write(containerNodeData); @@ -123,7 +123,7 @@ public class ParameterAwareNormalizedNodeWriterDepthTest { */ @Test public void writeMapNodeWithoutChildrenDepthTest() throws Exception { - final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.min(), null); + final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.min()); parameterWriter.write(mapNodeData); @@ -144,7 +144,7 @@ public class ParameterAwareNormalizedNodeWriterDepthTest { @Ignore @Test public void writeMapNodeWithChildrenDepthTest() throws Exception { - final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.max(), null); + final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.max()); parameterWriter.write(mapNodeData); @@ -170,7 +170,7 @@ public class ParameterAwareNormalizedNodeWriterDepthTest { */ @Test public void writeLeafSetNodeWithoutChildrenDepthTest() throws Exception { - final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.min(), null); + final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.min()); parameterWriter.write(leafSetNodeData); @@ -186,7 +186,7 @@ public class ParameterAwareNormalizedNodeWriterDepthTest { */ @Test public void writeLeafSetNodeWithChildrenDepthTest() throws Exception { - final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.max(), null); + final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.max()); parameterWriter.write(leafSetNodeData); @@ -204,7 +204,7 @@ public class ParameterAwareNormalizedNodeWriterDepthTest { */ @Test public void writeLeafSetEntryNodeDepthTest() throws Exception { - final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.max(), null); + final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.max()); parameterWriter.write(leafSetEntryNodeData); @@ -262,8 +262,7 @@ public class ParameterAwareNormalizedNodeWriterDepthTest { */ @Test public void writeMapEntryNodeOrderedWithoutChildrenTest() throws Exception { - final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, true, DepthParam.min(), - null); + final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.min()); parameterWriter.write(mapEntryNodeData); @@ -283,8 +282,7 @@ public class ParameterAwareNormalizedNodeWriterDepthTest { @Ignore @Test public void writeMapEntryNodeOrderedTest() throws Exception { - final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, true, DepthParam.max(), - null); + final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, DepthParam.max()); parameterWriter.write(mapEntryNodeData); diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriterParametersTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriterParametersTest.java index 42e98b4b84..a0d11b7ffd 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriterParametersTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriterParametersTest.java @@ -92,7 +92,7 @@ public class ParameterAwareNormalizedNodeWriterParametersTest { */ @Test public void writeRootDataTest() throws Exception { - final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, null, null); + final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, null); parameterWriter.write(rootDataContainerData); @@ -106,7 +106,7 @@ public class ParameterAwareNormalizedNodeWriterParametersTest { @Test public void writeEmptyRootContainerTest() throws Exception { - final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, null, null); + final var parameterWriter = ParameterAwareNormalizedNodeWriter.forStreamWriter(writer, null); parameterWriter.write(ImmutableNodes.newContainerBuilder() .withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME)) -- 2.36.6