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;
12 import java.util.Arrays;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15 import org.opendaylight.yangtools.yang.common.Revision;
16 import org.opendaylight.yangtools.yang.common.XMLNamespace;
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.SystemLeafSetNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
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 =
35 QNameModule.create(XMLNamespace.of("ns:complex:json"), Revision.of("2014-08-11"));
36 private static final QNameModule COMPLEX_JSON_AUG =
37 QNameModule.create(XMLNamespace.of("ns:complex:json:augmentation"), Revision.of("2014-08-14"));
39 private TestingNormalizedNodeStructuresCreator() {
40 throw new UnsupportedOperationException();
43 static ContainerNode cont1Node(final DataContainerChild... children) {
44 return Builders.containerBuilder()
45 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "cont1")))
46 .withValue(Arrays.asList(children))
50 static ContainerNode cont2Node() {
51 return Builders.containerBuilder()
52 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "cont2")))
56 private static UnkeyedListNode lst12Node() {
57 return Builders.unkeyedListBuilder()
58 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lst12")))
59 .withChild(lst12Entry1Node())
63 private static UnkeyedListEntryNode lst12Entry1Node() {
64 return Builders.unkeyedListEntryBuilder()
65 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lst12")))
66 .withChild(Builders.leafBuilder()
67 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf121")))
68 .withValue("lf121 value").build())
72 private static ChoiceNode choc12Node() {
73 return Builders.choiceBuilder()
74 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "choc12")))
75 .withChild(lf17Node())
79 protected static LeafNode<Object> lf17Node() {
80 return Builders.leafBuilder()
81 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf17")))
82 .withValue("lf17 value").build();
85 private static AugmentationNode externalAugmentC11AWithLf15_11AndLf15_12Node() {
86 return Builders.augmentationBuilder()
87 .withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(
88 QName.create(COMPLEX_JSON_AUG, "lf15_11"),
89 QName.create(COMPLEX_JSON_AUG, "lf15_12"))))
90 .withChild(lf15_11NodeExternal())
91 .withChild(lf15_12NodeExternal())
95 private static LeafNode<Object> lf15_12NodeExternal() {
96 return Builders.leafBuilder()
97 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON_AUG, "lf15_12")))
98 .withValue("lf15_12 value from augmentation")
102 private static LeafNode<Object> lf15_11NodeExternal() {
103 return Builders.leafBuilder()
104 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON_AUG, "lf15_11")))
105 .withValue("lf15_11 value from augmentation")
109 private static ChoiceNode choc11Node(final DataContainerChild... children) {
110 return Builders.choiceBuilder()
111 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "choc11")))
112 .withValue(Arrays.asList(children))
113 // choc11Builder.addChild(lf13Node());
114 // choc11Builder.addChild(augmentChoc11_c11A_lf1511AndLf1512Children());
115 // choc11Builder.addChild(augmentChoc11_c11_lf1521Children());
119 private static LeafNode<Object> lf13Node() {
120 return Builders.leafBuilder()
121 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf13")))
122 .withValue("lf13 value").build();
125 private static AugmentationNode augmentC11AWithLf15_21Node() {
126 return Builders.augmentationBuilder().withNodeIdentifier(
127 new AugmentationIdentifier(ImmutableSet.of(QName.create(COMPLEX_JSON, "lf15_21"))))
128 .withChild(lf15_21Node()).build();
131 private static LeafNode<Object> lf15_21Node() {
132 return Builders.leafBuilder()
133 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf15_21")))
134 .withValue("lf15_21 value").build();
137 private static AugmentationNode augmentC11AWithLf15_11AndLf15_12Node() {
138 return Builders.augmentationBuilder()
139 .withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(
140 QName.create(COMPLEX_JSON, "lf15_11"),
141 QName.create(COMPLEX_JSON, "lf15_12"))))
142 .withChild(lf15_11Node())
143 .withChild(lf15_12Node())
147 private static LeafNode<Object> lf15_12Node() {
148 return Builders.leafBuilder()
149 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf15_12")))
150 .withValue(QName.create(COMPLEX_JSON, "ident")).build();
153 private static LeafNode<Object> lf15_11Node() {
154 return Builders.leafBuilder()
155 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf15_11")))
156 .withValue(ImmutableSet.of("one", "two")).build();
159 private static AugmentationNode lf12_1Node() {
160 return Builders.augmentationBuilder()
161 .withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(
162 QName.create(COMPLEX_JSON, "lf12_1"),
163 QName.create(COMPLEX_JSON, "lf12_2"))))
164 .withChild(Builders.leafBuilder()
165 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf12_1")))
166 .withValue("lf12 value").build())
170 private static SystemMapNode childLst11() {
171 return Builders.mapBuilder()
172 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lst11")))
173 .withChild(Builders.mapEntryBuilder().withNodeIdentifier(
174 NodeIdentifierWithPredicates.of(QName.create(COMPLEX_JSON, "lst11"), ImmutableMap.of(
175 QName.create(COMPLEX_JSON, "key111"), "key111 value",
176 QName.create(COMPLEX_JSON, "lf111"), "lf111 value")))
177 .withChild(Builders.leafBuilder()
178 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "key111")))
179 .withValue("key111 value").build())
180 .withChild(Builders.leafBuilder()
181 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf112")))
182 .withValue(lf112Value()).build())
183 .withChild(Builders.leafBuilder()
184 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf113")))
185 .withValue("lf113 value").build())
186 .withChild(Builders.leafBuilder()
187 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf111")))
188 .withValue("lf111 value").build())
193 private static Object lf112Value() {
194 return YangInstanceIdentifier.create(
195 new NodeIdentifier(QName.create(COMPLEX_JSON, "cont1")),
196 new NodeIdentifier(QName.create(COMPLEX_JSON, "lflst11")),
197 new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"),"foo")
201 private static SystemLeafSetNode<?> childLflst11() {
202 return Builders.leafSetBuilder()
203 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lflst11")))
204 .withChild(Builders.leafSetEntryBuilder()
205 .withNodeIdentifier(new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"), "lflst11 value1"))
206 .withValue("lflst11 value1").build())
207 .withChild(Builders.leafSetEntryBuilder()
208 .withNodeIdentifier(new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"), "lflst11 value2"))
209 .withValue("lflst11 value2").build())
213 private static SystemLeafSetNode<?> childLflst11Multiline() {
214 return Builders.leafSetBuilder()
215 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lflst11")))
216 .withChild(Builders.leafSetEntryBuilder()
217 .withNodeIdentifier(new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"),
218 "lflst11 value1\nanother line 1"))
219 .withValue("lflst11 value1\nanother line 1").build())
220 .withChild(Builders.leafSetEntryBuilder()
221 .withNodeIdentifier(new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"),
222 "lflst11 value2\r\nanother line 2"))
223 .withValue("lflst11 value2\r\nanother line 2").build())
227 public static ContainerNode leafNodeInContainer() {
228 return cont1Node(Builders.leafBuilder()
229 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf11")))
230 .withValue(453).build());
233 public static ContainerNode leafListNodeInContainer() {
234 return cont1Node(childLflst11());
237 public static ContainerNode leafListNodeInContainerMultiline() {
238 return cont1Node(childLflst11Multiline());
241 public static ContainerNode keyedListNodeInContainer() {
242 return cont1Node(childLst11());
245 public static ContainerNode leafNodeViaAugmentationInContainer() {
246 return cont1Node(lf12_1Node());
249 public static ContainerNode choiceNodeInContainer() {
250 return cont1Node(choc11Node(lf13Node()));
254 * choc11 contains lf13, lf15_11 and lf15_12 are added via external augmentation.
256 public static ContainerNode caseNodeAugmentationInChoiceInContainer() {
257 return cont1Node(choc11Node(augmentC11AWithLf15_11AndLf15_12Node(), lf13Node(), augmentC11AWithLf15_21Node()));
260 public static ContainerNode caseNodeExternalAugmentationInChoiceInContainer() {
261 return cont1Node(choc11Node(lf13Node(), augmentC11AWithLf15_11AndLf15_12Node(),
262 externalAugmentC11AWithLf15_11AndLf15_12Node()));
265 public static ContainerNode choiceNodeAugmentationInContainer() {
266 return cont1Node(choc12Node());
269 public static ContainerNode unkeyedNodeInContainer() {
270 return cont1Node(lst12Node());
273 public static ContainerNode topLevelContainer() {
277 public static ContainerNode emptyContainerInContainer() {
278 return cont1Node(Builders.augmentationBuilder()
279 .withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(QName.create(COMPLEX_JSON, "cont11"))))
280 .withChild(Builders.containerBuilder()
281 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "cont11")))