* 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;
"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));
}
/**
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.";
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}