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;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
19 import org.opendaylight.yangtools.yang.data.api.schema.AnydataNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
23 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
24 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
25 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
26 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
31 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
32 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
34 public abstract class AbstractPrettyTreeTest {
35 protected static final QName ROOT_QNAME = QName.create(
36 "urn:opendaylight:controller:sal:dom:store:test", "2014-03-13", "root");
37 protected static final QName ANOTHER_QNAME = QName.create(
38 "urn:opendaylight:controller:sal:dom:store:another", "another");
40 protected static final QName LIST_A_QNAME = QName.create(ROOT_QNAME, "list-a");
41 protected static final QName LEAF_A_QNAME = QName.create(ROOT_QNAME, "leaf-a");
42 protected static final QName LIST_B_QNAME = QName.create(ROOT_QNAME, "list-b");
43 protected static final QName LEAF_B_QNAME = QName.create(ROOT_QNAME, "leaf-b");
45 protected static final QName CHOICE_QNAME = QName.create(ROOT_QNAME, "choice");
46 protected static final QName AUGMENT_QNAME = QName.create(ROOT_QNAME, "augment");
48 protected static final QName LIST_ANOTHER_NAMESPACE_QNAME = QName.create(ANOTHER_QNAME,
49 "list-from-another-namespace");
50 protected static final QName LEAF_ANOTHER_NAMESPACE_QNAME = QName.create(ANOTHER_QNAME,
51 "leaf-from-another-namespace");
53 protected static final QName LEAF_QNAME = QName.create(ROOT_QNAME, "leaf");
54 protected static final QName LEAF_SET_QNAME = QName.create(ROOT_QNAME, "leaf-set");
56 protected static final QName USER_LEAF_SET_QNAME = QName.create(ROOT_QNAME, "user-leaf-set");
57 protected static final QName USER_MAP_QNAME = QName.create(ROOT_QNAME, "user-map");
58 protected static final QName USER_MAP_ENTRY_QNAME = QName.create(ROOT_QNAME, "user-map-entry");
60 protected static final QName UNKEYED_LIST_QNAME = QName.create(ROOT_QNAME,
62 protected static final QName UNKEYED_LIST_ENTRY_QNAME = QName.create(ROOT_QNAME,
63 "unkeyed-list-entry");
64 protected static final QName UNKEYED_LIST_LEAF_QNAME = QName.create(ROOT_QNAME,
67 protected static final QName ANY_DATA_QNAME = QName.create(ROOT_QNAME, "any-data");
84 * augmented-leaf "Augmented leaf value"
86 * list-from-another-namespace
87 * leaf-from-another-namespace "Leaf from another namespace value"
89 * leaf-set "Leaf set value"
90 * user-leaf-set "User leaf set value"
92 * user-map-entry "User map entry value"
95 * unkeyed-list-leaf "Unkeyed list leaf value"
96 * any-data "Any data value"
100 * @return A test node
102 protected static ContainerNode createContainerNode() {
103 return Builders.containerBuilder()
104 .withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
105 .withChild(createMapNode())
106 .withChild(createChoiceNode())
107 .withChild(createContainerFromAnotherNamespace())
108 .withChild(createLeafNode())
109 .withChild(createLeafSetNode())
110 .withChild(createUserLeafSetNode())
111 .withChild(createUserMapNode())
112 .withChild(createUnkeyedListNode())
113 .withChild(createAnyDataNode())
117 protected static MapNode createMapNode() {
118 return mapNodeBuilder(LIST_A_QNAME)
119 .withChild(mapEntry(LIST_A_QNAME, LEAF_A_QNAME, "foo"))
120 .withChild(createMapEntryNode()).build();
123 protected static MapEntryNode createMapEntryNode() {
124 return mapEntryBuilder(LIST_A_QNAME, LEAF_A_QNAME, "bar")
125 .withChild(mapNodeBuilder(LIST_B_QNAME)
126 .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, "one"))
127 .withChild(mapEntry(LIST_B_QNAME, LEAF_B_QNAME, "two"))
131 protected static ChoiceNode createChoiceNode() {
132 return Builders.choiceBuilder()
133 .withNodeIdentifier(NodeIdentifier.create(CHOICE_QNAME))
134 .withChild(createAugmentedLeafNode())
138 protected static LeafNode<String> createAugmentedLeafNode() {
139 return leafNode(AUGMENT_QNAME, "Augmented leaf value");
142 protected static ContainerNode createContainerFromAnotherNamespace() {
143 return Builders.containerBuilder()
144 .withNodeIdentifier(new NodeIdentifier(ANOTHER_QNAME))
145 .withChild(mapNodeBuilder(LIST_ANOTHER_NAMESPACE_QNAME)
146 .withChild(mapEntry(LIST_ANOTHER_NAMESPACE_QNAME, LEAF_ANOTHER_NAMESPACE_QNAME,
147 "Leaf from another namespace value"))
152 protected static LeafNode<String> createLeafNode() {
153 return ImmutableNodes.leafNode(LEAF_QNAME, "Leaf value");
156 protected static LeafSetNode<String> createLeafSetNode() {
157 final String value = "Leaf set value";
158 return Builders.<String>leafSetBuilder()
159 .withNodeIdentifier(NodeIdentifier.create(LEAF_SET_QNAME))
160 .withValue(List.of(Builders.<String>leafSetEntryBuilder()
161 .withNodeIdentifier(new NodeWithValue<>(LEAF_SET_QNAME, value))
167 protected static UserLeafSetNode<String> createUserLeafSetNode() {
168 final String value = "User leaf set value";
169 final LeafSetEntryNode<String> leafSetValue = Builders.<String>leafSetEntryBuilder()
170 .withNodeIdentifier(new NodeWithValue<>(USER_LEAF_SET_QNAME, value))
173 return Builders.<String>orderedLeafSetBuilder()
174 .withNodeIdentifier(NodeIdentifier.create(USER_LEAF_SET_QNAME))
175 .withValue(List.of(leafSetValue))
179 protected static UserMapNode createUserMapNode() {
180 return Builders.orderedMapBuilder()
181 .withNodeIdentifier(NodeIdentifier.create(USER_MAP_QNAME))
182 .withValue(List.of(createUserMapEntryNode()))
186 protected static MapEntryNode createUserMapEntryNode() {
187 return mapEntry(USER_MAP_QNAME, USER_MAP_ENTRY_QNAME, "User map entry value");
190 protected static UnkeyedListNode createUnkeyedListNode() {
191 return Builders.unkeyedListBuilder()
192 .withNodeIdentifier(NodeIdentifier.create(UNKEYED_LIST_QNAME))
193 .withChild(createUnkeyedListEntryNode())
197 protected static UnkeyedListEntryNode createUnkeyedListEntryNode() {
198 return Builders.unkeyedListEntryBuilder()
199 .withNodeIdentifier(NodeIdentifier.create(UNKEYED_LIST_ENTRY_QNAME))
200 .withChild(leafNode(UNKEYED_LIST_LEAF_QNAME, "Unkeyed list leaf value"))
204 protected static AnydataNode<String> createAnyDataNode() {
205 return Builders.anydataBuilder(String.class)
206 .withNodeIdentifier(NodeIdentifier.create(ANY_DATA_QNAME))
207 .withValue("Any data value")