Add choice/case tests 09/84509/15
authorajay_dp001 <ajay.deep.singh@est.tech>
Tue, 17 Sep 2019 15:50:29 +0000 (16:50 +0100)
committerRobert Varga <nite@hq.sk>
Thu, 4 Nov 2021 15:56:24 +0000 (15:56 +0000)
Add two unit tests for traversal of choice/case nodes, asserting we
create a correct YangInstanceIdentifier.

JIRA: NETCONF-631
Change-Id: Icf9a00728bf4707f1951cdce208be225bba0b40c
Signed-off-by: ajay_dp001 <ajay.deep.singh@est.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java
restconf/restconf-nb-rfc8040/src/test/resources/restconf/parser/deserializer/example-actions.yang

index 1e57c6c08444da6c72ffe1561c47b9f06f4f2b7b..9d97189295a0fbe94aa18ec6dd33397c3a3cb610 100644 (file)
@@ -46,6 +46,9 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
  * Unit tests for {@link YangInstanceIdentifierDeserializer}.
  */
 public class YangInstanceIdentifierDeserializerTest {
+    private static final QName ACTIONS_INTERFACES =
+        QName.create("https://example.com/ns/example-actions", "2016-07-07", "interfaces");
+
     // schema context
     private static EffectiveModelContext SCHEMA_CONTEXT;
 
@@ -116,15 +119,58 @@ public class YangInstanceIdentifierDeserializerTest {
             "example-actions:interfaces/interface=eth0/reset");
         assertEquals(4, result.size());
         // container
-        assertEquals(NodeIdentifier.create(
-            QName.create("https://example.com/ns/example-actions", "2016-07-07", "interfaces")), result.get(0));
+        assertEquals(NodeIdentifier.create(ACTIONS_INTERFACES), result.get(0));
         // list
-        final QName list = QName.create("https://example.com/ns/example-actions", "2016-07-07", "interface");
+        final QName list = QName.create(ACTIONS_INTERFACES, "interface");
         assertEquals(NodeIdentifier.create(list), result.get(1));
         assertEquals(NodeIdentifierWithPredicates.of(list, QName.create(list, "name"), "eth0"), result.get(2));
         // action
-        assertEquals(NodeIdentifier.create(
-            QName.create("https://example.com/ns/example-actions", "2016-07-07", "reset")), result.get(3));
+        assertEquals(NodeIdentifier.create(QName.create(ACTIONS_INTERFACES, "reset")), result.get(3));
+    }
+
+    /**
+     * Test of deserialization <code>String</code> URI with container containing choice node with Action to
+     * {@code Iterable<YangInstanceIdentifier.PathArgument>}.
+     */
+    @Test
+    public void deserializeContainerWithChoiceSchemaNodeWithActionTest() {
+        final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+            "example-actions:interfaces/typeA-gigabyte/interface=eth0/reboot");
+        assertEquals(6, result.size());
+
+        // container
+        assertEquals(NodeIdentifier.create(ACTIONS_INTERFACES), result.get(0));
+        // choice
+        assertEquals(NodeIdentifier.create(QName.create(ACTIONS_INTERFACES, "interface-type")), result.get(1));
+        // container
+        assertEquals(NodeIdentifier.create(QName.create(ACTIONS_INTERFACES, "typeA-gigabyte")), result.get(2));
+
+        // list
+        final QName list = QName.create(ACTIONS_INTERFACES, "interface");
+        assertEquals(NodeIdentifier.create(list), result.get(3));
+        assertEquals(NodeIdentifierWithPredicates.of(list, QName.create(list, "name"), "eth0"), result.get(4));
+
+        // action QName
+        assertEquals(NodeIdentifier.create(QName.create(ACTIONS_INTERFACES, "reboot")), result.get(5));
+    }
+
+    /**
+     * Test of deserialization <code>String</code> URI with container containing choice node with Action to
+     * {@code Iterable<YangInstanceIdentifier.PathArgument>}.
+     */
+    @Test
+    public void deserializeContainerWithChoiceCaseSchemaNodeWithActionTest() {
+        final var result = YangInstanceIdentifierDeserializer.create(SCHEMA_CONTEXT,
+            "example-actions:interfaces/udp/reboot");
+        assertEquals(4, result.size());
+        // container
+        assertEquals(NodeIdentifier.create(ACTIONS_INTERFACES), result.get(0));
+        // choice
+        assertEquals(NodeIdentifier.create(QName.create(ACTIONS_INTERFACES, "protocol")), result.get(1));
+        // choice container
+        assertEquals(NodeIdentifier.create(QName.create(ACTIONS_INTERFACES, "udp")), result.get(2));
+        // action QName
+        assertEquals(NodeIdentifier.create(QName.create(ACTIONS_INTERFACES, "reboot")), result.get(3));
     }
 
     /**
index e5bb3cdd07a4578b38f77d1769d0610ae1cda058..f9a1160839dd8ab8655d5b01708c1da45201d305 100644 (file)
@@ -1,41 +1,90 @@
 module example-actions {
-     yang-version 1.1;
-     namespace "https://example.com/ns/example-actions";
-     prefix "act";
-
-     organization "Example, Inc.";
-     contact "support at example.com";
-     description "Example Actions Data Model Module.";
-
-     revision "2016-07-07" {
-       description "Initial version.";
-       reference "example.com document 2-9973.";
-     }
-
-     container interfaces {
-       description "System interfaces.";
-
-      list interface {
-         key name;
-         description "One interface entry.";
-         leaf name {
-           type string;
-           description "Interface name.";
-         }
-
-         action reset {
-           description "Reset an interface.";
-           input {
-             leaf delay {
-               type uint32;
-               units "seconds";
-               default 0;
-               description
-                 "Number of seconds to wait before starting the
-                  interface reset.";
-             }
-           }
-         }
-       }
-     }
-   }
+  yang-version 1.1;
+  namespace "https://example.com/ns/example-actions";
+  prefix "act";
+
+  organization "Example, Inc.";
+  contact "support at example.com";
+  description "Example Actions Data Model Module.";
+
+  revision "2016-07-07" {
+    description "Initial version.";
+    reference "example.com document 2-9973.";
+  }
+
+  container interfaces {
+    description "System interfaces.";
+
+    list interface {
+      key name;
+      description "One interface entry.";
+      leaf name {
+        type string;
+        description "Interface name.";
+      }
+
+      action reset {
+        description "Reset an interface.";
+        input {
+          leaf delay {
+            type uint32;
+            units "seconds";
+            default 0;
+            description
+              "Number of seconds to wait before starting the
+               interface reset.";
+          }
+        }
+      }
+    }
+
+    choice protocol {
+      case protocol-type {
+        container udp {
+          action reboot {
+            description "Reboot operation.";
+            input {
+              leaf delay {
+                type uint32;
+                units "seconds";
+                description  "Number of seconds to wait before initiating the reboot operation.";
+              }
+              leaf message {
+                type string;
+                description  "Log message to display when reboot is started.";
+              }
+            }
+          }
+        }
+      }
+    }
+
+    choice interface-type {
+      container typeA-gigabyte {
+        list interface {
+          key name;
+          description "One interface entry.";
+          leaf name {
+            type string;
+            description "Interface name.";
+          }
+
+          action reboot {
+            description "Reboot operation.";
+            input {
+              leaf delay {
+                type uint32;
+                units "seconds";
+                description  "Number of seconds to wait before initiating the reboot operation.";
+              }
+              leaf message {
+                type string;
+                description  "Log message to display when reboot is started.";
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}