2 * Copyright (c) 2021 PANTHEON.tech s.r.o. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.tree.impl;
10 import org.opendaylight.yangtools.yang.common.QName;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
13 import org.opendaylight.yangtools.yang.data.api.schema.AnydataNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
23 import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
24 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
26 abstract class AbstractPrettyTreeTest {
27 protected static final QName ROOT_QNAME = QName.create(
28 "urn:opendaylight:controller:sal:dom:store:test", "2014-03-13", "root");
29 protected static final QName ANOTHER_QNAME = QName.create(
30 "urn:opendaylight:controller:sal:dom:store:another", "another");
32 protected static final QName LIST_A_QNAME = QName.create(ROOT_QNAME, "list-a");
33 protected static final QName LEAF_A_QNAME = QName.create(ROOT_QNAME, "leaf-a");
34 protected static final QName LIST_B_QNAME = QName.create(ROOT_QNAME, "list-b");
35 protected static final QName LEAF_B_QNAME = QName.create(ROOT_QNAME, "leaf-b");
37 protected static final QName CHOICE_QNAME = QName.create(ROOT_QNAME, "choice");
38 protected static final QName AUGMENT_QNAME = QName.create(ROOT_QNAME, "augment");
40 protected static final QName LIST_ANOTHER_NAMESPACE_QNAME = QName.create(ANOTHER_QNAME,
41 "list-from-another-namespace");
42 protected static final QName LEAF_ANOTHER_NAMESPACE_QNAME = QName.create(ANOTHER_QNAME,
43 "leaf-from-another-namespace");
45 protected static final QName LEAF_QNAME = QName.create(ROOT_QNAME, "leaf");
46 protected static final QName LEAF_SET_QNAME = QName.create(ROOT_QNAME, "leaf-set");
48 protected static final QName USER_LEAF_SET_QNAME = QName.create(ROOT_QNAME, "user-leaf-set");
49 protected static final QName USER_MAP_QNAME = QName.create(ROOT_QNAME, "user-map");
50 protected static final QName USER_MAP_ENTRY_QNAME = QName.create(ROOT_QNAME, "user-map-entry");
52 protected static final QName UNKEYED_LIST_QNAME = QName.create(ROOT_QNAME, "unkeyed-list");
53 protected static final QName UNKEYED_LIST_ENTRY_QNAME = QName.create(ROOT_QNAME, "unkeyed-list-entry");
54 protected static final QName UNKEYED_LIST_LEAF_QNAME = QName.create(ROOT_QNAME, "unkeyed-list-leaf");
56 protected static final QName ANY_DATA_QNAME = QName.create(ROOT_QNAME, "any-data");
73 * augmented-leaf "Augmented leaf value"
75 * list-from-another-namespace
76 * leaf-from-another-namespace "Leaf from another namespace value"
78 * leaf-set "Leaf set value"
79 * user-leaf-set "User leaf set value"
81 * user-map-entry "User map entry value"
84 * unkeyed-list-leaf "Unkeyed list leaf value"
85 * any-data "Any data value"
91 protected static ContainerNode createContainerNode() {
92 return ImmutableNodes.newContainerBuilder()
93 .withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
94 .withChild(createMapNode())
95 .withChild(createChoiceNode())
96 .withChild(createContainerFromAnotherNamespace())
97 .withChild(createLeafNode())
98 .withChild(createLeafSetNode())
99 .withChild(createUserLeafSetNode())
100 .withChild(createUserMapNode())
101 .withChild(createUnkeyedListNode())
102 .withChild(createAnyDataNode())
106 protected static MapNode createMapNode() {
107 return ImmutableNodes.newSystemMapBuilder()
108 .withNodeIdentifier(new NodeIdentifier(LIST_A_QNAME))
109 .withChild(createMapEntry(LIST_A_QNAME, LEAF_A_QNAME, "foo"))
110 .withChild(createMapEntryNode())
114 private static MapEntryNode createMapEntry(final QName list, final QName key, final String value) {
115 return ImmutableNodes.newMapEntryBuilder()
116 .withNodeIdentifier(NodeIdentifierWithPredicates.of(list, key, value))
117 .withChild(ImmutableNodes.leafNode(key, value))
121 protected static MapEntryNode createMapEntryNode() {
122 return ImmutableNodes.newMapEntryBuilder()
123 .withNodeIdentifier(NodeIdentifierWithPredicates.of(LIST_A_QNAME, LEAF_A_QNAME, "bar"))
124 .withChild(ImmutableNodes.leafNode(LEAF_A_QNAME, "bar"))
125 .withChild(ImmutableNodes.newSystemMapBuilder()
126 .withNodeIdentifier(new NodeIdentifier(LIST_B_QNAME))
127 .withChild(createMapEntry(LIST_B_QNAME, LEAF_B_QNAME, "one"))
128 .withChild(createMapEntry(LIST_B_QNAME, LEAF_B_QNAME, "two"))
133 protected static ChoiceNode createChoiceNode() {
134 return ImmutableNodes.newChoiceBuilder()
135 .withNodeIdentifier(NodeIdentifier.create(CHOICE_QNAME))
136 .withChild(createAugmentedLeafNode())
140 protected static LeafNode<String> createAugmentedLeafNode() {
141 return ImmutableNodes.leafNode(AUGMENT_QNAME, "Augmented leaf value");
144 protected static ContainerNode createContainerFromAnotherNamespace() {
145 return ImmutableNodes.newContainerBuilder()
146 .withNodeIdentifier(new NodeIdentifier(ANOTHER_QNAME))
147 .withChild(ImmutableNodes.newSystemMapBuilder()
148 .withNodeIdentifier(new NodeIdentifier(LIST_ANOTHER_NAMESPACE_QNAME))
149 .withChild(createMapEntry(LIST_ANOTHER_NAMESPACE_QNAME, LEAF_ANOTHER_NAMESPACE_QNAME,
150 "Leaf from another namespace value"))
155 protected static LeafNode<String> createLeafNode() {
156 return ImmutableNodes.leafNode(LEAF_QNAME, "Leaf value");
159 protected static LeafSetNode<String> createLeafSetNode() {
160 final var value = "Leaf set value";
161 return ImmutableNodes.<String>newSystemLeafSetBuilder()
162 .withNodeIdentifier(NodeIdentifier.create(LEAF_SET_QNAME))
163 .withChild(ImmutableNodes.leafSetEntry(LEAF_SET_QNAME, value))
167 protected static UserLeafSetNode<String> createUserLeafSetNode() {
168 final var value = "User leaf set value";
169 return ImmutableNodes.<String>newUserLeafSetBuilder()
170 .withNodeIdentifier(NodeIdentifier.create(USER_LEAF_SET_QNAME))
171 .withChild(ImmutableNodes.leafSetEntry(USER_LEAF_SET_QNAME, value))
175 protected static UserMapNode createUserMapNode() {
176 return ImmutableNodes.newUserMapBuilder()
177 .withNodeIdentifier(NodeIdentifier.create(USER_MAP_QNAME))
178 .withChild(createUserMapEntryNode())
182 protected static MapEntryNode createUserMapEntryNode() {
183 return createMapEntry(USER_MAP_QNAME, USER_MAP_ENTRY_QNAME, "User map entry value");
186 protected static UnkeyedListNode createUnkeyedListNode() {
187 return ImmutableNodes.newUnkeyedListBuilder()
188 .withNodeIdentifier(NodeIdentifier.create(UNKEYED_LIST_QNAME))
189 .withChild(createUnkeyedListEntryNode())
193 protected static UnkeyedListEntryNode createUnkeyedListEntryNode() {
194 return ImmutableNodes.newUnkeyedListEntryBuilder()
195 .withNodeIdentifier(NodeIdentifier.create(UNKEYED_LIST_ENTRY_QNAME))
196 .withChild(ImmutableNodes.leafNode(UNKEYED_LIST_LEAF_QNAME, "Unkeyed list leaf value"))
200 protected static AnydataNode<String> createAnyDataNode() {
201 return ImmutableNodes.newAnydataBuilder(String.class)
202 .withNodeIdentifier(NodeIdentifier.create(ANY_DATA_QNAME))
203 .withValue("Any data value")