Migrate yang-data-tree-ri to JUnit5
[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 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;
27
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");
33
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");
38
39     protected static final QName CHOICE_QNAME = QName.create(ROOT_QNAME, "choice");
40     protected static final QName AUGMENT_QNAME = QName.create(ROOT_QNAME, "augment");
41
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");
46
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");
49
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");
53
54     protected static final QName UNKEYED_LIST_QNAME = QName.create(ROOT_QNAME,
55             "unkeyed-list");
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,
59             "unkeyed-list-leaf");
60
61     protected static final QName ANY_DATA_QNAME = QName.create(ROOT_QNAME, "any-data");
62
63     /**
64      * Return a test node.
65      *
66      * <pre>
67      * root
68      *     list-a
69      *          leaf-a "foo"
70      *     list-a
71      *          leaf-a "bar"
72      *          list-b
73      *                  leaf-b "one"
74      *          list-b
75      *                  leaf-b "two"
76      *     choice
77      *          augment
78      *                  augmented-leaf "Augmented leaf value"
79      *     another
80      *          list-from-another-namespace
81      *               leaf-from-another-namespace "Leaf from another namespace value"
82      *     leaf "Leaf value"
83      *     leaf-set "Leaf set value"
84      *     user-leaf-set "User leaf set value"
85      *     user-map
86      *          user-map-entry "User map entry value"
87      *     unkeyed-list
88      *          unkeyed-list-entry
89      *               unkeyed-list-leaf "Unkeyed list leaf value"
90      *     any-data "Any data value"
91      *
92      * </pre>
93      *
94      * @return A test node
95      */
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())
108             .build();
109     }
110
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())
115             .build();
116     }
117
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"))
123                 .build())
124             .build();
125     }
126
127     protected static ChoiceNode createChoiceNode() {
128         return Builders.choiceBuilder()
129                 .withNodeIdentifier(NodeIdentifier.create(CHOICE_QNAME))
130                 .withChild(createAugmentedLeafNode())
131                 .build();
132     }
133
134     protected static LeafNode<String> createAugmentedLeafNode() {
135         return ImmutableNodes.leafNode(AUGMENT_QNAME, "Augmented leaf value");
136     }
137
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"))
144                 .build())
145             .build();
146     }
147
148     protected static LeafNode<String> createLeafNode() {
149         return ImmutableNodes.leafNode(LEAF_QNAME, "Leaf value");
150     }
151
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))
158                 .withValue(value)
159                 .build()))
160             .build();
161     }
162
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))
169                 .withValue(value)
170                 .build())
171             .build();
172     }
173
174     protected static UserMapNode createUserMapNode() {
175         return Builders.orderedMapBuilder()
176             .withNodeIdentifier(NodeIdentifier.create(USER_MAP_QNAME))
177             .withChild(createUserMapEntryNode())
178             .build();
179     }
180
181     protected static MapEntryNode createUserMapEntryNode() {
182         return ImmutableNodes.mapEntry(USER_MAP_QNAME, USER_MAP_ENTRY_QNAME, "User map entry value");
183     }
184
185     protected static UnkeyedListNode createUnkeyedListNode() {
186         return Builders.unkeyedListBuilder()
187             .withNodeIdentifier(NodeIdentifier.create(UNKEYED_LIST_QNAME))
188             .withChild(createUnkeyedListEntryNode())
189             .build();
190     }
191
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"))
196             .build();
197     }
198
199     protected static AnydataNode<String> createAnyDataNode() {
200         return Builders.anydataBuilder(String.class)
201                 .withNodeIdentifier(NodeIdentifier.create(ANY_DATA_QNAME))
202                 .withValue("Any data value")
203                 .build();
204     }
205 }