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.NormalizedNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
32 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
33 import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
34 import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
35 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
36 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
38 public abstract class AbstractPrettyTreeTest {
39 protected static final QName ROOT_QNAME = QName.create(
40 "urn:opendaylight:controller:sal:dom:store:test", "2014-03-13", "root");
41 protected static final QName ANOTHER_QNAME = QName.create(
42 "urn:opendaylight:controller:sal:dom:store:another", "another");
44 protected static final QName LIST_A_QNAME = QName.create(ROOT_QNAME, "list-a");
45 protected static final QName LEAF_A_QNAME = QName.create(ROOT_QNAME, "leaf-a");
46 protected static final QName LIST_B_QNAME = QName.create(ROOT_QNAME, "list-b");
47 protected static final QName LEAF_B_QNAME = QName.create(ROOT_QNAME, "leaf-b");
49 protected static final QName CHOICE_QNAME = QName.create(ROOT_QNAME, "choice");
50 protected static final QName AUGMENT_QNAME = QName.create(ROOT_QNAME, "augment");
52 protected static final QName LIST_ANOTHER_NAMESPACE_QNAME = QName.create(ANOTHER_QNAME,
53 "list-from-another-namespace");
54 protected static final QName LEAF_ANOTHER_NAMESPACE_QNAME = QName.create(ANOTHER_QNAME,
55 "leaf-from-another-namespace");
57 protected static final QName LEAF_QNAME = QName.create(ROOT_QNAME, "leaf");
58 protected static final QName LEAF_SET_QNAME = QName.create(ROOT_QNAME, "leaf-set");
60 protected static final QName USER_LEAF_SET_QNAME = QName.create(ROOT_QNAME, "user-leaf-set");
61 protected static final QName USER_MAP_QNAME = QName.create(ROOT_QNAME, "user-map");
62 protected static final QName USER_MAP_ENTRY_QNAME = QName.create(ROOT_QNAME, "user-map-entry");
64 protected static final QName UNKEYED_LIST_QNAME = QName.create(ROOT_QNAME,
66 protected static final QName UNKEYED_LIST_ENTRY_QNAME = QName.create(ROOT_QNAME,
67 "unkeyed-list-entry");
68 protected static final QName UNKEYED_LIST_LEAF_QNAME = QName.create(ROOT_QNAME,
71 protected static final QName ANY_DATA_QNAME = QName.create(ROOT_QNAME, "any-data");
88 * augmented-leaf "Augmented leaf value"
90 * list-from-another-namespace
91 * leaf-from-another-namespace "Leaf from another namespace value"
93 * leaf-set "Leaf set value"
94 * user-leaf-set "User leaf set value"
96 * user-map-entry "User map entry value"
99 * unkeyed-list-leaf "Unkeyed list leaf value"
100 * any-data "Any data value"
104 * @return A test node
106 protected static NormalizedNode createContainerNode() {
107 return ImmutableContainerNodeBuilder.create()
108 .withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
109 .withChild(createMapNode())
110 .withChild(createChoiceNode())
111 .withChild(createContainerFromAnotherNamespace())
112 .withChild(createLeafNode())
113 .withChild(createLeafSetNode())
114 .withChild(createUserLeafSetNode())
115 .withChild(createUserMapNode())
116 .withChild(createUnkeyedListNode())
117 .withChild(createAnyDataNode())
121 protected static MapNode createMapNode() {
122 return mapNodeBuilder(LIST_A_QNAME)
123 .withChild(mapEntry(LIST_A_QNAME, LEAF_A_QNAME, "foo"))
124 .withChild(createMapEntryNode()).build();
127 protected static MapEntryNode createMapEntryNode() {
128 return mapEntryBuilder(LIST_A_QNAME, LEAF_A_QNAME, "bar")
129 .withChild(mapNodeBuilder(LIST_B_QNAME)
130 .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, "one"))
131 .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, "two"))
135 protected static ChoiceNode createChoiceNode() {
136 return Builders.choiceBuilder()
137 .withNodeIdentifier(NodeIdentifier.create(CHOICE_QNAME))
138 .withChild(createAugmentationNode())
142 protected static AugmentationNode createAugmentationNode() {
143 return Builders.augmentationBuilder()
144 .withNodeIdentifier(AugmentationIdentifier
145 .create(Set.of(AUGMENT_QNAME)))
146 .withChild(createAugmentedLeafNode())
150 protected static LeafNode<String> createAugmentedLeafNode() {
151 return leafNode(AUGMENT_QNAME, "Augmented leaf value");
154 protected static ContainerNode createContainerFromAnotherNamespace() {
155 return ImmutableContainerNodeBuilder.create()
156 .withNodeIdentifier(new NodeIdentifier(ANOTHER_QNAME))
157 .withChild(mapNodeBuilder(LIST_ANOTHER_NAMESPACE_QNAME)
158 .withChild(mapEntry(LIST_ANOTHER_NAMESPACE_QNAME,
159 LEAF_ANOTHER_NAMESPACE_QNAME,
160 "Leaf from another namespace value"))
165 protected static LeafNode<String> createLeafNode() {
166 return Builders.<String>leafBuilder()
167 .withNodeIdentifier(NodeIdentifier.create(LEAF_QNAME))
168 .withValue("Leaf value")
172 protected static LeafSetNode<String> createLeafSetNode() {
173 final String value = "Leaf set value";
174 final LeafSetEntryNode<String> leafSetValue = Builders.<String>leafSetEntryBuilder()
175 .withNodeIdentifier(new NodeWithValue<>(LEAF_SET_QNAME, value))
178 return Builders.<String>leafSetBuilder()
179 .withNodeIdentifier(NodeIdentifier.create(LEAF_SET_QNAME))
180 .withValue(List.of(leafSetValue))
184 protected static UserLeafSetNode<String> createUserLeafSetNode() {
185 final String value = "User leaf set value";
186 final LeafSetEntryNode<String> leafSetValue = Builders.<String>leafSetEntryBuilder()
187 .withNodeIdentifier(new NodeWithValue<>(USER_LEAF_SET_QNAME, value))
190 return Builders.<String>orderedLeafSetBuilder()
191 .withNodeIdentifier(NodeIdentifier.create(USER_LEAF_SET_QNAME))
192 .withValue(List.of(leafSetValue))
196 protected static UserMapNode createUserMapNode() {
197 return Builders.orderedMapBuilder()
198 .withNodeIdentifier(NodeIdentifier.create(USER_MAP_QNAME))
199 .withValue(List.of(createUserMapEntryNode()))
203 protected static MapEntryNode createUserMapEntryNode() {
204 return mapEntry(USER_MAP_QNAME, USER_MAP_ENTRY_QNAME, "User map entry value");
207 protected static UnkeyedListNode createUnkeyedListNode() {
208 return Builders.unkeyedListBuilder()
209 .withNodeIdentifier(NodeIdentifier.create(UNKEYED_LIST_QNAME))
210 .withChild(createUnkeyedListEntryNode())
214 protected static UnkeyedListEntryNode createUnkeyedListEntryNode() {
215 return Builders.unkeyedListEntryBuilder()
216 .withNodeIdentifier(NodeIdentifier.create(UNKEYED_LIST_ENTRY_QNAME))
217 .withChild(leafNode(UNKEYED_LIST_LEAF_QNAME, "Unkeyed list leaf value"))
221 protected static AnydataNode<String> createAnyDataNode() {
222 return Builders.anydataBuilder(String.class)
223 .withNodeIdentifier(NodeIdentifier.create(ANY_DATA_QNAME))
224 .withValue("Any data value")