Use ChoiceNode in EstablishSubscriptionRpc 67/115567/8
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 21 Feb 2025 13:13:35 +0000 (14:13 +0100)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Mon, 24 Feb 2025 13:22:04 +0000 (13:22 +0000)
The data coming in has been validated and therefore we can rely on
things being ChoiceNode rather than a generic DataNodeContainer.

This flushes out the fact the UT data does not actually match the
expected models, hence we fix that up.

JIRA: NETCONF-714
Change-Id: I62195d70b3720d368912ef0e41a4a652671c33d2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
apps/restconf-subscription/src/main/java/org/opendaylight/restconf/subscription/EstablishSubscriptionRpc.java
apps/restconf-subscription/src/test/java/org/opendaylight/restconf/subscription/DeleteSubscriptionRpcTest.java
apps/restconf-subscription/src/test/java/org/opendaylight/restconf/subscription/EstablishSubscriptionRpcTest.java

index 39a95c0d46bc8e37e12e75ece6e74c003946272a..77841d096ff03408486719ff3cad01b3b94f8405 100644 (file)
@@ -42,8 +42,8 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
@@ -110,7 +110,7 @@ public final class EstablishSubscriptionRpc extends RpcImplementation {
         }
 
         final var body = input.input();
-        final var target = (DataContainerNode) body.childByArg(SUBSCRIPTION_TARGET);
+        final var target = (ChoiceNode) body.childByArg(SUBSCRIPTION_TARGET);
         if (target == null) {
             // means there is no stream information present
             request.completeWith(new ServerException(ErrorType.APPLICATION, ErrorTag.MISSING_ELEMENT,
@@ -152,11 +152,12 @@ public final class EstablishSubscriptionRpc extends RpcImplementation {
         nodeTargetBuilder.withChild(ImmutableNodes.leafNode(SubscriptionUtil.QNAME_STREAM, streamName));
 
         // check stream filter
-        final var streamFilter = (DataContainerNode) target.childByArg(SUBSCRIPTION_STREAM_FILTER);
+        final var streamFilter = (ChoiceNode) target.childByArg(SUBSCRIPTION_STREAM_FILTER);
         if (streamFilter != null) {
             final var streamFilterName = leaf(streamFilter, SUBSCRIPTION_STREAM_FILTER_NAME, String.class);
-            final var nodeFilterBuilder = ImmutableNodes.newChoiceBuilder().withNodeIdentifier(NodeIdentifier
-                .create(StreamFilter.QNAME));
+            final var nodeFilterBuilder = ImmutableNodes.newChoiceBuilder()
+                .withNodeIdentifier(NodeIdentifier.create(StreamFilter.QNAME));
+
             if (streamFilterName != null) {
                 try {
                     if (!mdsalService.exist(SubscriptionUtil.FILTERS.node(NodeIdentifierWithPredicates.of(
index d727a6b853f14f2bcf9f9a8f8453755e21e8694d..79fb62a2606afa25d496c02bea62229aee9566c0 100644 (file)
@@ -35,7 +35,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.subscribed.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.subscribed.notifications.rev190909.DeleteSubscriptionOutput;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.subscribed.notifications.rev190909.subscriptions.Subscription;
 import org.opendaylight.yangtools.yang.common.Uint32;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
 
@@ -43,10 +44,10 @@ import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
 class DeleteSubscriptionRpcTest {
     private static final URI RESTCONF_URI = URI.create("/restconf/");
     private static final Uint32 ID = Uint32.valueOf(2147483648L);
-    private static final YangInstanceIdentifier.NodeIdentifierWithPredicates IDENTIFIER =
-        YangInstanceIdentifier.NodeIdentifierWithPredicates.of(Subscription.QNAME, SubscriptionUtil.QNAME_ID, ID);
+    private static final NodeIdentifierWithPredicates IDENTIFIER =
+        NodeIdentifierWithPredicates.of(Subscription.QNAME, SubscriptionUtil.QNAME_ID, ID);
     private static final ContainerNode INPUT = ImmutableNodes.newContainerBuilder()
-        .withNodeIdentifier(YangInstanceIdentifier.NodeIdentifier.create(DeleteSubscriptionInput.QNAME))
+        .withNodeIdentifier(NodeIdentifier.create(DeleteSubscriptionInput.QNAME))
         .withChild(ImmutableNodes.leafNode(SubscriptionUtil.QNAME_ID, ID))
         .build();
 
@@ -79,7 +80,7 @@ class DeleteSubscriptionRpcTest {
     @Test
     void deleteSubscriptionTest() {
         final var responseBuilder = ImmutableNodes.newContainerBuilder()
-            .withNodeIdentifier(YangInstanceIdentifier.NodeIdentifier.create(DeleteSubscriptionOutput.QNAME))
+            .withNodeIdentifier(NodeIdentifier.create(DeleteSubscriptionOutput.QNAME))
             .build();
 
         doReturn(writeTx).when(dataBroker).newWriteOnlyTransaction();
index 546f8b2bc01f2dc25c298f70496e9867cea50904..731a15b5c6b9b5b222c6dffb72138b8c1acddd95 100644 (file)
@@ -33,9 +33,11 @@ import org.opendaylight.restconf.server.api.TransportSession;
 import org.opendaylight.restconf.server.api.testlib.CompletingServerRequest;
 import org.opendaylight.restconf.server.spi.OperationInput;
 import org.opendaylight.restconf.server.spi.RestconfStream;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.subscribed.notifications.rev190909.EncodeJson$I;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.subscribed.notifications.rev190909.EstablishSubscriptionInput;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.subscribed.notifications.rev190909.EstablishSubscriptionOutput;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.subscribed.notifications.rev190909.filters.StreamFilter;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.subscribed.notifications.rev190909.subscription.policy.modifiable.Target;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.subscribed.notifications.rev190909.subscriptions.Subscription;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.subscribed.notifications.rev190909.subscriptions.subscription.receivers.Receiver;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
@@ -104,14 +106,14 @@ class EstablishSubscriptionRpcTest {
         final var expectedNode = ImmutableNodes.newMapEntryBuilder()
             .withNodeIdentifier(NodeIdentifierWithPredicates.of(Subscription.QNAME, SubscriptionUtil.QNAME_ID, ID))
             .withChild(ImmutableNodes.leafNode(SubscriptionUtil.QNAME_ID, ID))
+            .withChild(ImmutableNodes.leafNode(SubscriptionUtil.QNAME_ENCODING, EncodeJson$I.QNAME))
             .withChild(nodeReceivers)
             .withChild(nodeTarget)
             .build();
 
         final var responseBuilder = ImmutableNodes.newContainerBuilder()
             .withNodeIdentifier(NodeIdentifier.create(EstablishSubscriptionOutput.QNAME))
-            .withChild(ImmutableNodes.leafNode(NodeIdentifier.create(QName.create(EstablishSubscriptionOutput.QNAME,
-                "id").intern()), ID))
+            .withChild(ImmutableNodes.leafNode(QName.create(EstablishSubscriptionOutput.QNAME, "id"), ID))
             .build();
 
         doReturn(writeTx).when(dataBroker).newWriteOnlyTransaction();
@@ -152,11 +154,11 @@ class EstablishSubscriptionRpcTest {
     void establishSubscriptionWrongFilterTest() {
         final var input = ImmutableNodes.newContainerBuilder()
             .withNodeIdentifier(NodeIdentifier.create(EstablishSubscriptionInput.QNAME))
-            .withChild(ImmutableNodes.newContainerBuilder().withNodeIdentifier(NodeIdentifier
-                    .create(SubscriptionUtil.QNAME_TARGET))
+            .withChild(ImmutableNodes.newChoiceBuilder()
+                .withNodeIdentifier(NodeIdentifier.create(Target.QNAME))
                 .withChild(ImmutableNodes.leafNode(SubscriptionUtil.QNAME_STREAM, "NETCONF"))
-                .withChild(ImmutableNodes.newContainerBuilder().withNodeIdentifier(NodeIdentifier
-                        .create(QName.create(Subscription.QNAME, "stream-filter")))
+                .withChild(ImmutableNodes.newChoiceBuilder()
+                    .withNodeIdentifier(NodeIdentifier.create(StreamFilter.QNAME))
                     .withChild(ImmutableNodes.leafNode(SubscriptionUtil.QNAME_STREAM_FILTER, "filter"))
                     .build())
                 .build())
@@ -177,8 +179,9 @@ class EstablishSubscriptionRpcTest {
     private static ContainerNode getInput() {
         return ImmutableNodes.newContainerBuilder()
             .withNodeIdentifier(NodeIdentifier.create(EstablishSubscriptionInput.QNAME))
-            .withChild(ImmutableNodes.newContainerBuilder().withNodeIdentifier(NodeIdentifier
-                    .create(SubscriptionUtil.QNAME_TARGET))
+            .withChild(ImmutableNodes.leafNode(SubscriptionUtil.QNAME_ENCODING, EncodeJson$I.QNAME))
+            .withChild(ImmutableNodes.newChoiceBuilder()
+                .withNodeIdentifier(NodeIdentifier.create(Target.QNAME))
                 .withChild(ImmutableNodes.leafNode(SubscriptionUtil.QNAME_STREAM, "NETCONF"))
                 .build())
             .build();