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 java.util.List;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
14 import org.opendaylight.yangtools.yang.data.api.schema.AnydataNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
23 import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
24 import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
25 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
26 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
28 abstract class AbstractPrettyTreeTest {
29 protected static final QName ROOT_QNAME = QName.create(
30 "urn:opendaylight:controller:sal:dom:store:test", "2014-03-13", "root");
31 protected static final QName ANOTHER_QNAME = QName.create(
32 "urn:opendaylight:controller:sal:dom:store:another", "another");
34 protected static final QName LIST_A_QNAME = QName.create(ROOT_QNAME, "list-a");
35 protected static final QName LEAF_A_QNAME = QName.create(ROOT_QNAME, "leaf-a");
36 protected static final QName LIST_B_QNAME = QName.create(ROOT_QNAME, "list-b");
37 protected static final QName LEAF_B_QNAME = QName.create(ROOT_QNAME, "leaf-b");
39 protected static final QName CHOICE_QNAME = QName.create(ROOT_QNAME, "choice");
40 protected static final QName AUGMENT_QNAME = QName.create(ROOT_QNAME, "augment");
42 protected static final QName LIST_ANOTHER_NAMESPACE_QNAME = QName.create(ANOTHER_QNAME,
43 "list-from-another-namespace");
44 protected static final QName LEAF_ANOTHER_NAMESPACE_QNAME = QName.create(ANOTHER_QNAME,
45 "leaf-from-another-namespace");
47 protected static final QName LEAF_QNAME = QName.create(ROOT_QNAME, "leaf");
48 protected static final QName LEAF_SET_QNAME = QName.create(ROOT_QNAME, "leaf-set");
50 protected static final QName USER_LEAF_SET_QNAME = QName.create(ROOT_QNAME, "user-leaf-set");
51 protected static final QName USER_MAP_QNAME = QName.create(ROOT_QNAME, "user-map");
52 protected static final QName USER_MAP_ENTRY_QNAME = QName.create(ROOT_QNAME, "user-map-entry");
54 protected static final QName UNKEYED_LIST_QNAME = QName.create(ROOT_QNAME,
56 protected static final QName UNKEYED_LIST_ENTRY_QNAME = QName.create(ROOT_QNAME,
57 "unkeyed-list-entry");
58 protected static final QName UNKEYED_LIST_LEAF_QNAME = QName.create(ROOT_QNAME,
61 protected static final QName ANY_DATA_QNAME = QName.create(ROOT_QNAME, "any-data");
78 * augmented-leaf "Augmented leaf value"
80 * list-from-another-namespace
81 * leaf-from-another-namespace "Leaf from another namespace value"
83 * leaf-set "Leaf set value"
84 * user-leaf-set "User leaf set value"
86 * user-map-entry "User map entry value"
89 * unkeyed-list-leaf "Unkeyed list leaf value"
90 * any-data "Any data value"
96 protected static ContainerNode createContainerNode() {
97 return Builders.containerBuilder()
98 .withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
99 .withChild(createMapNode())
100 .withChild(createChoiceNode())
101 .withChild(createContainerFromAnotherNamespace())
102 .withChild(createLeafNode())
103 .withChild(createLeafSetNode())
104 .withChild(createUserLeafSetNode())
105 .withChild(createUserMapNode())
106 .withChild(createUnkeyedListNode())
107 .withChild(createAnyDataNode())
111 protected static MapNode createMapNode() {
112 return ImmutableNodes.mapNodeBuilder(LIST_A_QNAME)
113 .withChild(ImmutableNodes.mapEntry(LIST_A_QNAME, LEAF_A_QNAME, "foo"))
114 .withChild(createMapEntryNode())
118 protected static MapEntryNode createMapEntryNode() {
119 return ImmutableNodes.mapEntryBuilder(LIST_A_QNAME, LEAF_A_QNAME, "bar")
120 .withChild(ImmutableNodes.mapNodeBuilder(LIST_B_QNAME)
121 .withChild(ImmutableNodes.mapEntry(LIST_B_QNAME, LEAF_B_QNAME, "one"))
122 .withChild(ImmutableNodes.mapEntry(LIST_B_QNAME, LEAF_B_QNAME, "two"))
127 protected static ChoiceNode createChoiceNode() {
128 return Builders.choiceBuilder()
129 .withNodeIdentifier(NodeIdentifier.create(CHOICE_QNAME))
130 .withChild(createAugmentedLeafNode())
134 protected static LeafNode<String> createAugmentedLeafNode() {
135 return ImmutableNodes.leafNode(AUGMENT_QNAME, "Augmented leaf value");
138 protected static ContainerNode createContainerFromAnotherNamespace() {
139 return Builders.containerBuilder()
140 .withNodeIdentifier(new NodeIdentifier(ANOTHER_QNAME))
141 .withChild(ImmutableNodes.mapNodeBuilder(LIST_ANOTHER_NAMESPACE_QNAME)
142 .withChild(ImmutableNodes.mapEntry(LIST_ANOTHER_NAMESPACE_QNAME, LEAF_ANOTHER_NAMESPACE_QNAME,
143 "Leaf from another namespace value"))
148 protected static LeafNode<String> createLeafNode() {
149 return ImmutableNodes.leafNode(LEAF_QNAME, "Leaf value");
152 protected static LeafSetNode<String> createLeafSetNode() {
153 final var value = "Leaf set value";
154 return Builders.<String>leafSetBuilder()
155 .withNodeIdentifier(NodeIdentifier.create(LEAF_SET_QNAME))
156 .withValue(List.of(Builders.<String>leafSetEntryBuilder()
157 .withNodeIdentifier(new NodeWithValue<>(LEAF_SET_QNAME, value))
163 protected static UserLeafSetNode<String> createUserLeafSetNode() {
164 final var value = "User leaf set value";
165 return Builders.<String>orderedLeafSetBuilder()
166 .withNodeIdentifier(NodeIdentifier.create(USER_LEAF_SET_QNAME))
167 .withChild(Builders.<String>leafSetEntryBuilder()
168 .withNodeIdentifier(new NodeWithValue<>(USER_LEAF_SET_QNAME, value))
174 protected static UserMapNode createUserMapNode() {
175 return Builders.orderedMapBuilder()
176 .withNodeIdentifier(NodeIdentifier.create(USER_MAP_QNAME))
177 .withChild(createUserMapEntryNode())
181 protected static MapEntryNode createUserMapEntryNode() {
182 return ImmutableNodes.mapEntry(USER_MAP_QNAME, USER_MAP_ENTRY_QNAME, "User map entry value");
185 protected static UnkeyedListNode createUnkeyedListNode() {
186 return Builders.unkeyedListBuilder()
187 .withNodeIdentifier(NodeIdentifier.create(UNKEYED_LIST_QNAME))
188 .withChild(createUnkeyedListEntryNode())
192 protected static UnkeyedListEntryNode createUnkeyedListEntryNode() {
193 return Builders.unkeyedListEntryBuilder()
194 .withNodeIdentifier(NodeIdentifier.create(UNKEYED_LIST_ENTRY_QNAME))
195 .withChild(ImmutableNodes.leafNode(UNKEYED_LIST_LEAF_QNAME, "Unkeyed list leaf value"))
199 protected static AnydataNode<String> createAnyDataNode() {
200 return Builders.anydataBuilder(String.class)
201 .withNodeIdentifier(NodeIdentifier.create(ANY_DATA_QNAME))
202 .withValue("Any data value")