From a7f1f9567b8890198c9964671f6ed1430efc9d28 Mon Sep 17 00:00:00 2001 From: ajay_dp001 Date: Tue, 17 Sep 2019 16:50:29 +0100 Subject: [PATCH] Add choice/case tests 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 Signed-off-by: Robert Varga --- ...angInstanceIdentifierDeserializerTest.java | 56 +++++++- .../parser/deserializer/example-actions.yang | 129 ++++++++++++------ 2 files changed, 140 insertions(+), 45 deletions(-) diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java index 1e57c6c084..9d97189295 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/YangInstanceIdentifierDeserializerTest.java @@ -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 String URI with container containing choice node with Action to + * {@code Iterable}. + */ + @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 String URI with container containing choice node with Action to + * {@code Iterable}. + */ + @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)); } /** diff --git a/restconf/restconf-nb-rfc8040/src/test/resources/restconf/parser/deserializer/example-actions.yang b/restconf/restconf-nb-rfc8040/src/test/resources/restconf/parser/deserializer/example-actions.yang index e5bb3cdd07..f9a1160839 100644 --- a/restconf/restconf-nb-rfc8040/src/test/resources/restconf/parser/deserializer/example-actions.yang +++ b/restconf/restconf-nb-rfc8040/src/test/resources/restconf/parser/deserializer/example-actions.yang @@ -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."; + } + } + } + } + } + } + } +} -- 2.36.6