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 static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
11 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry;
12 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder;
13 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder;
15 import java.util.List;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
21 import org.opendaylight.yangtools.yang.data.api.schema.AnydataNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
23 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
24 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
25 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
26 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
32 import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
34 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
35 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
37 public abstract class AbstractPrettyTreeTest {
38 protected static final QName ROOT_QNAME = QName.create(
39 "urn:opendaylight:controller:sal:dom:store:test", "2014-03-13", "root");
40 protected static final QName ANOTHER_QNAME = QName.create(
41 "urn:opendaylight:controller:sal:dom:store:another", "another");
43 protected static final QName LIST_A_QNAME = QName.create(ROOT_QNAME, "list-a");
44 protected static final QName LEAF_A_QNAME = QName.create(ROOT_QNAME, "leaf-a");
45 protected static final QName LIST_B_QNAME = QName.create(ROOT_QNAME, "list-b");
46 protected static final QName LEAF_B_QNAME = QName.create(ROOT_QNAME, "leaf-b");
48 protected static final QName CHOICE_QNAME = QName.create(ROOT_QNAME, "choice");
49 protected static final QName AUGMENT_QNAME = QName.create(ROOT_QNAME, "augment");
51 protected static final QName LIST_ANOTHER_NAMESPACE_QNAME = QName.create(ANOTHER_QNAME,
52 "list-from-another-namespace");
53 protected static final QName LEAF_ANOTHER_NAMESPACE_QNAME = QName.create(ANOTHER_QNAME,
54 "leaf-from-another-namespace");
56 protected static final QName LEAF_QNAME = QName.create(ROOT_QNAME, "leaf");
57 protected static final QName LEAF_SET_QNAME = QName.create(ROOT_QNAME, "leaf-set");
59 protected static final QName USER_LEAF_SET_QNAME = QName.create(ROOT_QNAME, "user-leaf-set");
60 protected static final QName USER_MAP_QNAME = QName.create(ROOT_QNAME, "user-map");
61 protected static final QName USER_MAP_ENTRY_QNAME = QName.create(ROOT_QNAME, "user-map-entry");
63 protected static final QName UNKEYED_LIST_QNAME = QName.create(ROOT_QNAME,
65 protected static final QName UNKEYED_LIST_ENTRY_QNAME = QName.create(ROOT_QNAME,
66 "unkeyed-list-entry");
67 protected static final QName UNKEYED_LIST_LEAF_QNAME = QName.create(ROOT_QNAME,
70 protected static final QName ANY_DATA_QNAME = QName.create(ROOT_QNAME, "any-data");
87 * augmented-leaf "Augmented leaf value"
89 * list-from-another-namespace
90 * leaf-from-another-namespace "Leaf from another namespace value"
92 * leaf-set "Leaf set value"
93 * user-leaf-set "User leaf set value"
95 * user-map-entry "User map entry value"
98 * unkeyed-list-leaf "Unkeyed list leaf value"
99 * any-data "Any data value"
103 * @return A test node
105 protected static ContainerNode createContainerNode() {
106 return Builders.containerBuilder()
107 .withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
108 .withChild(createMapNode())
109 .withChild(createChoiceNode())
110 .withChild(createContainerFromAnotherNamespace())
111 .withChild(createLeafNode())
112 .withChild(createLeafSetNode())
113 .withChild(createUserLeafSetNode())
114 .withChild(createUserMapNode())
115 .withChild(createUnkeyedListNode())
116 .withChild(createAnyDataNode())
120 protected static MapNode createMapNode() {
121 return mapNodeBuilder(LIST_A_QNAME)
122 .withChild(mapEntry(LIST_A_QNAME, LEAF_A_QNAME, "foo"))
123 .withChild(createMapEntryNode()).build();
126 protected static MapEntryNode createMapEntryNode() {
127 return mapEntryBuilder(LIST_A_QNAME, LEAF_A_QNAME, "bar")
128 .withChild(mapNodeBuilder(LIST_B_QNAME)
129 .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, "one"))
130 .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, "two"))
134 protected static ChoiceNode createChoiceNode() {
135 return Builders.choiceBuilder()
136 .withNodeIdentifier(NodeIdentifier.create(CHOICE_QNAME))
137 .withChild(createAugmentationNode())
141 protected static AugmentationNode createAugmentationNode() {
142 return Builders.augmentationBuilder()
143 .withNodeIdentifier(AugmentationIdentifier
144 .create(Set.of(AUGMENT_QNAME)))
145 .withChild(createAugmentedLeafNode())
149 protected static LeafNode<String> createAugmentedLeafNode() {
150 return leafNode(AUGMENT_QNAME, "Augmented leaf value");
153 protected static ContainerNode createContainerFromAnotherNamespace() {
154 return Builders.containerBuilder()
155 .withNodeIdentifier(new NodeIdentifier(ANOTHER_QNAME))
156 .withChild(mapNodeBuilder(LIST_ANOTHER_NAMESPACE_QNAME)
157 .withChild(mapEntry(LIST_ANOTHER_NAMESPACE_QNAME, LEAF_ANOTHER_NAMESPACE_QNAME,
158 "Leaf from another namespace value"))
163 protected static LeafNode<String> createLeafNode() {
164 return ImmutableNodes.leafNode(LEAF_QNAME, "Leaf value");
167 protected static LeafSetNode<String> createLeafSetNode() {
168 final String value = "Leaf set value";
169 return Builders.<String>leafSetBuilder()
170 .withNodeIdentifier(NodeIdentifier.create(LEAF_SET_QNAME))
171 .withValue(List.of(Builders.<String>leafSetEntryBuilder()
172 .withNodeIdentifier(new NodeWithValue<>(LEAF_SET_QNAME, value))
178 protected static UserLeafSetNode<String> createUserLeafSetNode() {
179 final String value = "User leaf set value";
180 final LeafSetEntryNode<String> leafSetValue = Builders.<String>leafSetEntryBuilder()
181 .withNodeIdentifier(new NodeWithValue<>(USER_LEAF_SET_QNAME, value))
184 return Builders.<String>orderedLeafSetBuilder()
185 .withNodeIdentifier(NodeIdentifier.create(USER_LEAF_SET_QNAME))
186 .withValue(List.of(leafSetValue))
190 protected static UserMapNode createUserMapNode() {
191 return Builders.orderedMapBuilder()
192 .withNodeIdentifier(NodeIdentifier.create(USER_MAP_QNAME))
193 .withValue(List.of(createUserMapEntryNode()))
197 protected static MapEntryNode createUserMapEntryNode() {
198 return mapEntry(USER_MAP_QNAME, USER_MAP_ENTRY_QNAME, "User map entry value");
201 protected static UnkeyedListNode createUnkeyedListNode() {
202 return Builders.unkeyedListBuilder()
203 .withNodeIdentifier(NodeIdentifier.create(UNKEYED_LIST_QNAME))
204 .withChild(createUnkeyedListEntryNode())
208 protected static UnkeyedListEntryNode createUnkeyedListEntryNode() {
209 return Builders.unkeyedListEntryBuilder()
210 .withNodeIdentifier(NodeIdentifier.create(UNKEYED_LIST_ENTRY_QNAME))
211 .withChild(leafNode(UNKEYED_LIST_LEAF_QNAME, "Unkeyed list leaf value"))
215 protected static AnydataNode<String> createAnyDataNode() {
216 return Builders.anydataBuilder(String.class)
217 .withNodeIdentifier(NodeIdentifier.create(ANY_DATA_QNAME))
218 .withValue("Any data value")