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.Lists;
11 import com.google.common.collect.Sets;
12 import java.util.HashMap;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
21 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
23 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
24 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
25 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
26 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
32 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
33 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
34 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
35 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
36 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
38 public class TestingNormalizedNodeStructuresCreator {
41 static NormalizedNode<?, ?> cont1Node(
42 final DataContainerChild<? extends PathArgument, ?>... children) {
43 DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> cont1 = Builders.containerBuilder();
44 cont1.withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "cont1")));
46 cont1.withValue(Lists.newArrayList(children));
50 private static DataContainerChild<? extends PathArgument, ?> lst12Node() {
51 CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> lst12Builder = Builders.unkeyedListBuilder()
52 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lst12")));
53 lst12Builder.withChild(lst12Entry1Node());
54 return lst12Builder.build();
57 private static UnkeyedListEntryNode lst12Entry1Node() {
58 DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> lst12Entry1Builder = Builders
59 .unkeyedListEntryBuilder();
61 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lst12")));
62 lst12Entry1Builder.withChild(Builders.leafBuilder()
63 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf121")))
64 .withValue("lf121 value").build());
65 return lst12Entry1Builder.build();
68 private static DataContainerChild<? extends PathArgument, ?> choc12Node() {
69 DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choc12Builder = Builders.choiceBuilder()
70 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "choc12")));
72 choc12Builder.withChild(lf17Node());
73 return choc12Builder.build();
76 protected static LeafNode<Object> lf17Node() {
77 return Builders.leafBuilder()
78 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf17")))
79 .withValue("lf17 value").build();
82 private static DataContainerChild<? extends PathArgument, ?> externalAugmentC11AWithLf15_11AndLf15_12Node() {
83 DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> augmentationBuilder = Builders
84 .augmentationBuilder();
85 augmentationBuilder.withNodeIdentifier(new AugmentationIdentifier(Sets.newHashSet(
86 QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_11"),
87 QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_12"))));
88 augmentationBuilder.withChild(lf15_11NodeExternal());
89 augmentationBuilder.withChild(lf15_12NodeExternal());
90 return augmentationBuilder.build();
93 private static LeafNode<Object> lf15_12NodeExternal() {
97 new NodeIdentifier(QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_12")))
98 .withValue("lf15_12 value from augmentation").build();
101 private static LeafNode<Object> lf15_11NodeExternal() {
105 new NodeIdentifier(QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_11")))
106 .withValue("lf15_11 value from augmentation").build();
110 private static DataContainerChild<? extends PathArgument, ?> choc11Node(
111 final DataContainerChild<? extends PathArgument, ?>... children) {
112 DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choc11Builder = Builders.choiceBuilder()
113 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "choc11")));
114 choc11Builder.withValue(Lists.newArrayList(children));
115 // choc11Builder.addChild(lf13Node());
116 // choc11Builder.addChild(augmentChoc11_c11A_lf1511AndLf1512Children());
117 // choc11Builder.addChild(augmentChoc11_c11_lf1521Children());
118 return choc11Builder.build();
121 private static LeafNode<Object> lf13Node() {
122 return Builders.leafBuilder()
123 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf13")))
124 .withValue("lf13 value").build();
127 private static DataContainerChild<? extends PathArgument, ?> augmentC11AWithLf15_21Node() {
128 DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> choc11_c11AugmentBuilder = Builders
129 .augmentationBuilder();
130 choc11_c11AugmentBuilder.withNodeIdentifier(new AugmentationIdentifier(Sets.newHashSet(QName.create(
131 "ns:complex:json", "2014-08-11", "lf15_21"))));
133 choc11_c11AugmentBuilder.withChild(lf15_21Node());
134 return choc11_c11AugmentBuilder.build();
137 private static LeafNode<Object> lf15_21Node() {
138 return Builders.leafBuilder()
139 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf15_21")))
140 .withValue("lf15_21 value").build();
143 private static DataContainerChild<? extends PathArgument, ?> augmentC11AWithLf15_11AndLf15_12Node() {
144 DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> choc11_c11AugmentBuilder = Builders
145 .augmentationBuilder();
146 choc11_c11AugmentBuilder.withNodeIdentifier(new AugmentationIdentifier(Sets.newHashSet(
147 QName.create("ns:complex:json", "2014-08-11", "lf15_11"),
148 QName.create("ns:complex:json", "2014-08-11", "lf15_12"))));
149 choc11_c11AugmentBuilder.withChild(lf15_11Node());
150 choc11_c11AugmentBuilder.withChild(lf15_12Node());
151 return choc11_c11AugmentBuilder.build();
154 private static LeafNode<Object> lf15_12Node() {
155 return Builders.leafBuilder()
156 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf15_12")))
157 .withValue(QName.create("ns:complex:json", "2014-08-11", "ident")).build();
160 private static LeafNode<Object> lf15_11Node() {
161 return Builders.leafBuilder()
162 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf15_11")))
163 .withValue(Sets.newHashSet("one", "two")).build();
166 private static DataContainerChild<? extends PathArgument, ?> lf12_1Node() {
167 DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> augmentBuilder = Builders
168 .augmentationBuilder().withNodeIdentifier(
169 new AugmentationIdentifier(Sets.newHashSet(
170 QName.create("ns:complex:json", "2014-08-11", "lf12_1"),
171 QName.create("ns:complex:json", "2014-08-11", "lf12_2"))));
172 augmentBuilder.withChild(Builders.leafBuilder()
173 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf12_1")))
174 .withValue("lf12 value").build());
175 return augmentBuilder.build();
178 private static DataContainerChild<? extends PathArgument, ?> childLst11() {
179 CollectionNodeBuilder<MapEntryNode, MapNode> lst11 = Builders.mapBuilder().withNodeIdentifier(
180 new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lst11")));
182 DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> lst11Entry1Builder = Builders
185 Map<QName, Object> key = new HashMap<>();
186 key.put(QName.create("ns:complex:json", "2014-08-11", "key111"), "key111 value");
187 key.put(QName.create("ns:complex:json", "2014-08-11", "lf111"), "lf111 value");
189 lst11Entry1Builder.withNodeIdentifier(new NodeIdentifierWithPredicates(QName.create("ns:complex:json",
190 "2014-08-11", "lst11"), key));
191 lst11Entry1Builder.withChild(Builders.leafBuilder()
192 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "key111")))
193 .withValue("key111 value").build());
194 lst11Entry1Builder.withChild(Builders.leafBuilder()
195 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf112")))
196 .withValue(lf112Value()).build());
197 lst11Entry1Builder.withChild(Builders.leafBuilder()
198 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf113")))
199 .withValue("lf113 value").build());
200 lst11Entry1Builder.withChild(Builders.leafBuilder()
201 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf111")))
202 .withValue("lf111 value").build());
203 lst11.withChild(lst11Entry1Builder.build());
204 return lst11.build();
207 private static Object lf112Value() {
208 return YangInstanceIdentifier.create(
209 new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "cont1")),
210 new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11")),
211 new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"),"foo")
215 private static DataContainerChild<? extends PathArgument, ?> childLflst11() {
216 ListNodeBuilder<Object, LeafSetEntryNode<Object>> lflst11 = Builders.leafSetBuilder().withNodeIdentifier(
217 new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11")));
218 lflst11.withChild(Builders
219 .leafSetEntryBuilder()
221 new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value1"))
222 .withValue("lflst11 value1").build());
223 lflst11.withChild(Builders
224 .leafSetEntryBuilder()
226 new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value2"))
227 .withValue("lflst11 value2").build());
228 return lflst11.build();
231 private static DataContainerChild<? extends PathArgument, ?> childLflst11Multiline() {
232 ListNodeBuilder<Object, LeafSetEntryNode<Object>> lflst11 = Builders.leafSetBuilder().withNodeIdentifier(
233 new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11")));
234 lflst11.withChild(Builders
235 .leafSetEntryBuilder()
237 new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value1\nanother line 1"))
238 .withValue("lflst11 value1\nanother line 1").build());
239 lflst11.withChild(Builders
240 .leafSetEntryBuilder()
242 new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value2\r\nanother line 2"))
243 .withValue("lflst11 value2\r\nanother line 2").build());
244 return lflst11.build();
247 public static NormalizedNode<?, ?> leafNodeInContainer() {
248 LeafNode<Object> lf11 = Builders.leafBuilder()
249 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf11")))
250 .withValue(453).build();
251 return cont1Node(lf11);
254 public static NormalizedNode<?, ?> leafListNodeInContainer() {
255 return cont1Node(childLflst11());
257 public static NormalizedNode<?, ?> leafListNodeInContainerMultiline() {
258 return cont1Node(childLflst11Multiline());
261 public static NormalizedNode<?, ?> keyedListNodeInContainer() {
262 return cont1Node(childLst11());
265 public static NormalizedNode<?, ?> leafNodeViaAugmentationInContainer() {
266 return cont1Node(lf12_1Node());
269 public static NormalizedNode<?, ?> choiceNodeInContainer() {
270 return cont1Node(choc11Node(lf13Node()));
274 * choc11 contains lf13, lf15_11 and lf15_12 are added via external augmentation
278 public static NormalizedNode<?, ?> caseNodeAugmentationInChoiceInContainer() {
279 return cont1Node(choc11Node(augmentC11AWithLf15_11AndLf15_12Node(), lf13Node(), augmentC11AWithLf15_21Node()));
282 public static NormalizedNode<?, ?> caseNodeExternalAugmentationInChoiceInContainer() {
283 return cont1Node(choc11Node(lf13Node(), augmentC11AWithLf15_11AndLf15_12Node(), externalAugmentC11AWithLf15_11AndLf15_12Node()));
286 public static NormalizedNode<?, ?> choiceNodeAugmentationInContainer() {
287 return cont1Node(choc12Node());
290 public static NormalizedNode<?, ?> unkeyedNodeInContainer() {
291 return cont1Node(lst12Node());
294 public static NormalizedNode<?, ?> topLevelContainer() {