2 * Copyright (c) 2016 Cisco Systems, Inc. and others. 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.codec.gson;
10 import com.google.common.collect.ImmutableMap;
11 import com.google.common.collect.ImmutableSet;
13 import java.util.Arrays;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.common.Revision;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
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.NodeIdentifierWithPredicates;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
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.DataContainerChild;
26 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
31 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
33 public final class TestingNormalizedNodeStructuresCreator {
34 private static final QNameModule COMPLEX_JSON = QNameModule.create(URI.create("ns:complex:json"),
35 Revision.of("2014-08-11"));
36 private static final QNameModule COMPLEX_JSON_AUG = QNameModule.create(URI.create("ns:complex:json:augmentation"),
37 Revision.of("2014-08-14"));
39 private TestingNormalizedNodeStructuresCreator() {
40 throw new UnsupportedOperationException();
44 static ContainerNode cont1Node(final DataContainerChild<?, ?>... children) {
45 return Builders.containerBuilder()
46 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "cont1")))
47 .withValue(Arrays.asList(children))
51 static ContainerNode cont2Node() {
52 return Builders.containerBuilder()
53 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "cont2")))
57 private static UnkeyedListNode lst12Node() {
58 return Builders.unkeyedListBuilder()
59 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lst12")))
60 .withChild(lst12Entry1Node())
64 private static UnkeyedListEntryNode lst12Entry1Node() {
65 return Builders.unkeyedListEntryBuilder()
66 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lst12")))
67 .withChild(Builders.leafBuilder()
68 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf121")))
69 .withValue("lf121 value").build())
73 private static ChoiceNode choc12Node() {
74 return Builders.choiceBuilder()
75 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "choc12")))
76 .withChild(lf17Node())
80 protected static LeafNode<Object> lf17Node() {
81 return Builders.leafBuilder()
82 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf17")))
83 .withValue("lf17 value").build();
86 private static AugmentationNode externalAugmentC11AWithLf15_11AndLf15_12Node() {
87 return Builders.augmentationBuilder()
88 .withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(
89 QName.create(COMPLEX_JSON_AUG, "lf15_11"),
90 QName.create(COMPLEX_JSON_AUG, "lf15_12"))))
91 .withChild(lf15_11NodeExternal())
92 .withChild(lf15_12NodeExternal())
96 private static LeafNode<Object> lf15_12NodeExternal() {
97 return Builders.leafBuilder()
98 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON_AUG, "lf15_12")))
99 .withValue("lf15_12 value from augmentation")
103 private static LeafNode<Object> lf15_11NodeExternal() {
104 return Builders.leafBuilder()
105 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON_AUG, "lf15_11")))
106 .withValue("lf15_11 value from augmentation")
111 private static ChoiceNode choc11Node(final DataContainerChild<?, ?>... children) {
112 return Builders.choiceBuilder()
113 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "choc11")))
114 .withValue(Arrays.asList(children))
115 // choc11Builder.addChild(lf13Node());
116 // choc11Builder.addChild(augmentChoc11_c11A_lf1511AndLf1512Children());
117 // choc11Builder.addChild(augmentChoc11_c11_lf1521Children());
121 private static LeafNode<Object> lf13Node() {
122 return Builders.leafBuilder()
123 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf13")))
124 .withValue("lf13 value").build();
127 private static AugmentationNode augmentC11AWithLf15_21Node() {
128 return Builders.augmentationBuilder().withNodeIdentifier(
129 new AugmentationIdentifier(ImmutableSet.of(QName.create(COMPLEX_JSON, "lf15_21"))))
130 .withChild(lf15_21Node()).build();
133 private static LeafNode<Object> lf15_21Node() {
134 return Builders.leafBuilder()
135 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf15_21")))
136 .withValue("lf15_21 value").build();
139 private static AugmentationNode augmentC11AWithLf15_11AndLf15_12Node() {
140 return Builders.augmentationBuilder()
141 .withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(
142 QName.create(COMPLEX_JSON, "lf15_11"),
143 QName.create(COMPLEX_JSON, "lf15_12"))))
144 .withChild(lf15_11Node())
145 .withChild(lf15_12Node())
149 private static LeafNode<Object> lf15_12Node() {
150 return Builders.leafBuilder()
151 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf15_12")))
152 .withValue(QName.create(COMPLEX_JSON, "ident")).build();
155 private static LeafNode<Object> lf15_11Node() {
156 return Builders.leafBuilder()
157 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf15_11")))
158 .withValue(ImmutableSet.of("one", "two")).build();
161 private static AugmentationNode lf12_1Node() {
162 return Builders.augmentationBuilder()
163 .withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(
164 QName.create(COMPLEX_JSON, "lf12_1"),
165 QName.create(COMPLEX_JSON, "lf12_2"))))
166 .withChild(Builders.leafBuilder()
167 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf12_1")))
168 .withValue("lf12 value").build())
172 private static MapNode childLst11() {
173 return Builders.mapBuilder()
174 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lst11")))
175 .withChild(Builders.mapEntryBuilder().withNodeIdentifier(
176 NodeIdentifierWithPredicates.of(QName.create(COMPLEX_JSON, "lst11"), ImmutableMap.of(
177 QName.create(COMPLEX_JSON, "key111"), "key111 value",
178 QName.create(COMPLEX_JSON, "lf111"), "lf111 value")))
179 .withChild(Builders.leafBuilder()
180 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "key111")))
181 .withValue("key111 value").build())
182 .withChild(Builders.leafBuilder()
183 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf112")))
184 .withValue(lf112Value()).build())
185 .withChild(Builders.leafBuilder()
186 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf113")))
187 .withValue("lf113 value").build())
188 .withChild(Builders.leafBuilder()
189 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf111")))
190 .withValue("lf111 value").build())
195 private static Object lf112Value() {
196 return YangInstanceIdentifier.create(
197 new NodeIdentifier(QName.create(COMPLEX_JSON, "cont1")),
198 new NodeIdentifier(QName.create(COMPLEX_JSON, "lflst11")),
199 new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"),"foo")
203 private static LeafSetNode<?> childLflst11() {
204 return Builders.leafSetBuilder()
205 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lflst11")))
206 .withChild(Builders.leafSetEntryBuilder()
207 .withNodeIdentifier(new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"), "lflst11 value1"))
208 .withValue("lflst11 value1").build())
209 .withChild(Builders.leafSetEntryBuilder()
210 .withNodeIdentifier(new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"), "lflst11 value2"))
211 .withValue("lflst11 value2").build())
215 private static LeafSetNode<?> childLflst11Multiline() {
216 return Builders.leafSetBuilder()
217 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lflst11")))
218 .withChild(Builders.leafSetEntryBuilder()
219 .withNodeIdentifier(new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"),
220 "lflst11 value1\nanother line 1"))
221 .withValue("lflst11 value1\nanother line 1").build())
222 .withChild(Builders.leafSetEntryBuilder()
223 .withNodeIdentifier(new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"),
224 "lflst11 value2\r\nanother line 2"))
225 .withValue("lflst11 value2\r\nanother line 2").build())
229 public static ContainerNode leafNodeInContainer() {
230 return cont1Node(Builders.leafBuilder()
231 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf11")))
232 .withValue(453).build());
235 public static ContainerNode leafListNodeInContainer() {
236 return cont1Node(childLflst11());
239 public static ContainerNode leafListNodeInContainerMultiline() {
240 return cont1Node(childLflst11Multiline());
243 public static ContainerNode keyedListNodeInContainer() {
244 return cont1Node(childLst11());
247 public static ContainerNode leafNodeViaAugmentationInContainer() {
248 return cont1Node(lf12_1Node());
251 public static ContainerNode choiceNodeInContainer() {
252 return cont1Node(choc11Node(lf13Node()));
256 * choc11 contains lf13, lf15_11 and lf15_12 are added via external augmentation.
258 public static ContainerNode caseNodeAugmentationInChoiceInContainer() {
259 return cont1Node(choc11Node(augmentC11AWithLf15_11AndLf15_12Node(), lf13Node(), augmentC11AWithLf15_21Node()));
262 public static ContainerNode caseNodeExternalAugmentationInChoiceInContainer() {
263 return cont1Node(choc11Node(lf13Node(), augmentC11AWithLf15_11AndLf15_12Node(),
264 externalAugmentC11AWithLf15_11AndLf15_12Node()));
267 public static ContainerNode choiceNodeAugmentationInContainer() {
268 return cont1Node(choc12Node());
271 public static ContainerNode unkeyedNodeInContainer() {
272 return cont1Node(lst12Node());
275 public static ContainerNode topLevelContainer() {
279 public static ContainerNode emptyContainerInContainer() {
280 return cont1Node(Builders.augmentationBuilder()
281 .withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(QName.create(COMPLEX_JSON, "cont11"))))
282 .withChild(Builders.containerBuilder()
283 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "cont11")))