Rename opendaylight.mdsal.binding.runtime.spi
[yangtools.git] / data / yang-data-tree-ri / src / test / java / org / opendaylight / yangtools / yang / data / tree / impl / AbstractPrettyTreeTest.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech s.r.o. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.tree.impl;
9
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;
25
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");
31
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");
36
37     protected static final QName CHOICE_QNAME = QName.create(ROOT_QNAME, "choice");
38     protected static final QName AUGMENT_QNAME = QName.create(ROOT_QNAME, "augment");
39
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");
44
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");
47
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");
51
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");
55
56     protected static final QName ANY_DATA_QNAME = QName.create(ROOT_QNAME, "any-data");
57
58     /**
59      * Return a test node.
60      *
61      * <pre>
62      * root
63      *     list-a
64      *          leaf-a "foo"
65      *     list-a
66      *          leaf-a "bar"
67      *          list-b
68      *                  leaf-b "one"
69      *          list-b
70      *                  leaf-b "two"
71      *     choice
72      *          augment
73      *                  augmented-leaf "Augmented leaf value"
74      *     another
75      *          list-from-another-namespace
76      *               leaf-from-another-namespace "Leaf from another namespace value"
77      *     leaf "Leaf value"
78      *     leaf-set "Leaf set value"
79      *     user-leaf-set "User leaf set value"
80      *     user-map
81      *          user-map-entry "User map entry value"
82      *     unkeyed-list
83      *          unkeyed-list-entry
84      *               unkeyed-list-leaf "Unkeyed list leaf value"
85      *     any-data "Any data value"
86      *
87      * </pre>
88      *
89      * @return A test node
90      */
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())
103             .build();
104     }
105
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())
111             .build();
112     }
113
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))
118             .build();
119     }
120
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"))
129                 .build())
130             .build();
131     }
132
133     protected static ChoiceNode createChoiceNode() {
134         return ImmutableNodes.newChoiceBuilder()
135                 .withNodeIdentifier(NodeIdentifier.create(CHOICE_QNAME))
136                 .withChild(createAugmentedLeafNode())
137                 .build();
138     }
139
140     protected static LeafNode<String> createAugmentedLeafNode() {
141         return ImmutableNodes.leafNode(AUGMENT_QNAME, "Augmented leaf value");
142     }
143
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"))
151                 .build())
152             .build();
153     }
154
155     protected static LeafNode<String> createLeafNode() {
156         return ImmutableNodes.leafNode(LEAF_QNAME, "Leaf value");
157     }
158
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))
164             .build();
165     }
166
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))
172             .build();
173     }
174
175     protected static UserMapNode createUserMapNode() {
176         return ImmutableNodes.newUserMapBuilder()
177             .withNodeIdentifier(NodeIdentifier.create(USER_MAP_QNAME))
178             .withChild(createUserMapEntryNode())
179             .build();
180     }
181
182     protected static MapEntryNode createUserMapEntryNode() {
183         return createMapEntry(USER_MAP_QNAME, USER_MAP_ENTRY_QNAME, "User map entry value");
184     }
185
186     protected static UnkeyedListNode createUnkeyedListNode() {
187         return ImmutableNodes.newUnkeyedListBuilder()
188             .withNodeIdentifier(NodeIdentifier.create(UNKEYED_LIST_QNAME))
189             .withChild(createUnkeyedListEntryNode())
190             .build();
191     }
192
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"))
197             .build();
198     }
199
200     protected static AnydataNode<String> createAnyDataNode() {
201         return ImmutableNodes.newAnydataBuilder(String.class)
202             .withNodeIdentifier(NodeIdentifier.create(ANY_DATA_QNAME))
203             .withValue("Any data value")
204             .build();
205     }
206 }