2 * Copyright (c) 2014 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 org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
14 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
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.InstanceIdentifierBuilder;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
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.LeafSetEntryNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
32 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
33 import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
34 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
35 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
36 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
37 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
38 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
39 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
41 import java.util.HashMap;
44 public class TestingNormalizedNodeStructuresCreator {
46 static NormalizedNode<?, ?> cont1Node(
47 DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>... children) {
48 DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> cont1 = Builders.containerBuilder();
49 cont1.withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "cont1")));
51 cont1.withValue(Lists.newArrayList(children));
55 private static DataContainerChild<? extends PathArgument, ?> lst12Node() {
56 CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> lst12Builder = Builders.unkeyedListBuilder()
57 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lst12")));
58 lst12Builder.withChild(lst12Entry1Node());
59 return lst12Builder.build();
62 private static UnkeyedListEntryNode lst12Entry1Node() {
63 DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> lst12Entry1Builder = Builders
64 .unkeyedListEntryBuilder();
66 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lst12")));
67 lst12Entry1Builder.withChild(Builders.leafBuilder()
68 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf121")))
69 .withValue("lf121 value").build());
70 return lst12Entry1Builder.build();
73 private static DataContainerChild<? extends PathArgument, ?> choc12Node() {
74 DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choc12Builder = Builders.choiceBuilder()
75 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "choc12")));
77 // DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> choc12Augmentation = Builders
78 // .augmentationBuilder();
79 // choc12Augmentation.withNodeIdentifier(new AugmentationIdentifier(Sets.newHashSet(QName.create(
80 // "ns:complex:json", "2014-08-11", "c12B"))));
81 // choc12Augmentation.withChild(lf17Node());
83 choc12Builder.withChild(lf17Node());
84 return choc12Builder.build();
87 protected static LeafNode<Object> lf17Node() {
88 return Builders.leafBuilder()
89 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf17")))
90 .withValue("lf17 value").build();
93 private static DataContainerChild<? extends PathArgument, ?> externalAugmentC11AWithLf15_11AndLf15_12Node() {
94 DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> augmentationBuilder = Builders
95 .augmentationBuilder();
96 augmentationBuilder.withNodeIdentifier(new AugmentationIdentifier(Sets.newHashSet(
97 QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_11"),
98 QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_12"))));
99 augmentationBuilder.withChild(lf15_11NodeExternal());
100 augmentationBuilder.withChild(lf15_12NodeExternal());
101 return augmentationBuilder.build();
104 private static LeafNode<Object> lf15_12NodeExternal() {
108 new NodeIdentifier(QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_12")))
109 .withValue("lf15_12 value from augmentation").build();
112 private static LeafNode<Object> lf15_11NodeExternal() {
116 new NodeIdentifier(QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_11")))
117 .withValue("lf15_11 value from augmentation").build();
120 private static DataContainerChild<? extends PathArgument, ?> choc11Node(
121 DataContainerChild<? extends PathArgument, ?>... children) {
122 DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choc11Builder = Builders.choiceBuilder()
123 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "choc11")));
124 choc11Builder.withValue(Lists.newArrayList(children));
125 // choc11Builder.addChild(lf13Node());
126 // choc11Builder.addChild(augmentChoc11_c11A_lf1511AndLf1512Children());
127 // choc11Builder.addChild(augmentChoc11_c11_lf1521Children());
128 return choc11Builder.build();
131 private static LeafNode<Object> lf13Node() {
132 return Builders.leafBuilder()
133 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf13")))
134 .withValue("lf13 value").build();
137 private static DataContainerChild<? extends PathArgument, ?> augmentC11AWithLf15_21Node() {
138 DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> choc11_c11AugmentBuilder = Builders
139 .augmentationBuilder();
140 choc11_c11AugmentBuilder.withNodeIdentifier(new AugmentationIdentifier(Sets.newHashSet(QName.create(
141 "ns:complex:json", "2014-08-11", "lf15_21"))));
143 choc11_c11AugmentBuilder.withChild(lf15_21Node());
144 return choc11_c11AugmentBuilder.build();
147 private static LeafNode<Object> lf15_21Node() {
148 return Builders.leafBuilder()
149 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf15_21")))
150 .withValue("lf15_21 value").build();
153 private static DataContainerChild<? extends PathArgument, ?> augmentC11AWithLf15_11AndLf15_12Node() {
154 DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> choc11_c11AugmentBuilder = Builders
155 .augmentationBuilder();
156 choc11_c11AugmentBuilder.withNodeIdentifier(new AugmentationIdentifier(Sets.newHashSet(
157 QName.create("ns:complex:json", "2014-08-11", "lf15_11"),
158 QName.create("ns:complex:json", "2014-08-11", "lf15_12"))));
159 choc11_c11AugmentBuilder.withChild(lf15_11Node());
160 choc11_c11AugmentBuilder.withChild(lf15_12Node());
161 return choc11_c11AugmentBuilder.build();
164 private static LeafNode<Object> lf15_12Node() {
165 return Builders.leafBuilder()
166 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf15_12")))
167 .withValue(QName.create("ns:complex:json", "2014-08-11", "lf11")).build();
170 private static LeafNode<Object> lf15_11Node() {
171 return Builders.leafBuilder()
172 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf15_11")))
173 .withValue(Sets.newHashSet("one", "two")).build();
176 private static DataContainerChild<? extends PathArgument, ?> lf12_1Node() {
177 DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> augmentBuilder = Builders
178 .augmentationBuilder().withNodeIdentifier(
179 new AugmentationIdentifier(Sets.newHashSet(
180 QName.create("ns:complex:json", "2014-08-11", "lf12_1"),
181 QName.create("ns:complex:json", "2014-08-11", "lf12_2"))));
182 augmentBuilder.withChild(Builders.leafBuilder()
183 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf12_1")))
184 .withValue("lf12 value").build());
185 return augmentBuilder.build();
188 private static DataContainerChild<? extends PathArgument, ?> childLst11() {
189 CollectionNodeBuilder<MapEntryNode, MapNode> lst11 = Builders.mapBuilder().withNodeIdentifier(
190 new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lst11")));
192 DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> lst11Entry1Builder = Builders
195 Map<QName, Object> key = new HashMap<>();
196 key.put(QName.create("ns:complex:json", "2014-08-11", "key111"), "key111 value");
197 key.put(QName.create("ns:complex:json", "2014-08-11", "lf111"), "lf111 value");
199 lst11Entry1Builder.withNodeIdentifier(new NodeIdentifierWithPredicates(QName.create("ns:complex:json",
200 "2014-08-11", "lst11"), key));
201 lst11Entry1Builder.withChild(Builders.leafBuilder()
202 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "key111")))
203 .withValue("key111 value").build());
204 lst11Entry1Builder.withChild(Builders.leafBuilder()
205 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf112")))
206 .withValue(lf112Value()).build());
207 lst11Entry1Builder.withChild(Builders.leafBuilder()
208 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf113")))
209 .withValue("lf113 value").build());
210 lst11Entry1Builder.withChild(Builders.leafBuilder()
211 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf111")))
212 .withValue("lf111 value").build());
213 lst11.withChild(lst11Entry1Builder.build());
214 return lst11.build();
217 private static Object lf112Value() {
218 InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder();
219 builder.node(QName.create("ns:complex:json", "2014-08-11", "cont1"));
220 builder.node(QName.create("ns:complex:json", "2014-08-11", "lflst11"));
221 return builder.build();
224 private static DataContainerChild<? extends PathArgument, ?> childLflst11() {
225 ListNodeBuilder<Object, LeafSetEntryNode<Object>> lflst11 = Builders.leafSetBuilder().withNodeIdentifier(
226 new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11")));
227 lflst11.withChild(Builders
228 .leafSetEntryBuilder()
230 new NodeWithValue(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value1"))
231 .withValue("lflst11 value1").build());
232 lflst11.withChild(Builders
233 .leafSetEntryBuilder()
235 new NodeWithValue(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value2"))
236 .withValue("lflst11 value2").build());
237 return lflst11.build();
240 private static DataContainerChild<? extends PathArgument, ?> childLflst11Multiline() {
241 ListNodeBuilder<Object, LeafSetEntryNode<Object>> lflst11 = Builders.leafSetBuilder().withNodeIdentifier(
242 new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11")));
243 lflst11.withChild(Builders
244 .leafSetEntryBuilder()
246 new NodeWithValue(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value1\nanother line 1"))
247 .withValue("lflst11 value1\nanother line 1").build());
248 lflst11.withChild(Builders
249 .leafSetEntryBuilder()
251 new NodeWithValue(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value2\r\nanother line 2"))
252 .withValue("lflst11 value2\r\nanother line 2").build());
253 return lflst11.build();
256 private static CompositeNode prepareLf12Value() {
257 SimpleNode<?> anyxmlInData = NodeFactory.createImmutableSimpleNode(
258 QName.create("ns:complex:json", "2014-08-11", "anyxml-in-data"), null, "foo");
259 return ImmutableCompositeNode.builder().add(anyxmlInData)
260 .setQName(QName.create("ns:complex:json", "2014-08-11", "lf12-any")).toInstance();
263 private static CompositeNode prepareLf13Value() {
264 SimpleNode<?> anyxmlInData = NodeFactory.createImmutableSimpleNode(
265 QName.create("ns:complex:json", "2014-08-11", "anyxml-in-data"), null, "foo");
266 return ImmutableCompositeNode.builder().add(anyxmlInData)
267 .setQName(QName.create("ns:complex:json", "2014-08-11", "lf13-any")).toInstance();
270 public static NormalizedNode<?, ?> leafNodeInContainer() {
271 LeafNode<Object> lf11 = Builders.leafBuilder()
272 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf11")))
273 .withValue((int) 453).build();
274 return cont1Node(lf11);
277 public static NormalizedNode<?, ?> leafListNodeInContainer() {
278 return cont1Node(childLflst11());
280 public static NormalizedNode<?, ?> leafListNodeInContainerMultiline() {
281 return cont1Node(childLflst11Multiline());
284 public static NormalizedNode<?, ?> keyedListNodeInContainer() {
285 return cont1Node(childLst11());
288 public static NormalizedNode<?, ?> leafNodeViaAugmentationInContainer() {
289 return cont1Node(lf12_1Node());
292 public static NormalizedNode<?, ?> choiceNodeInContainer() {
293 return cont1Node(choc11Node(lf13Node()));
297 * choc11 contains lf13, lf15_11 and lf15_12 are added via external augmentation
301 public static NormalizedNode<?, ?> caseNodeAugmentationInChoiceInContainer() {
302 return cont1Node(choc11Node(lf13Node(), lf15_11Node(), lf15_12Node(), lf15_21Node()));
305 public static NormalizedNode<?, ?> caseNodeExternalAugmentationInChoiceInContainer() {
306 return cont1Node(choc11Node(lf13Node(), lf15_11Node(), lf15_12Node(), lf15_11NodeExternal(), lf15_12NodeExternal()));
309 public static NormalizedNode<?, ?> choiceNodeAugmentationInContainer() {
310 return cont1Node(choc12Node());
313 public static NormalizedNode<?, ?> unkeyedNodeInContainer() {
314 return cont1Node(lst12Node());
317 public static NormalizedNode<?, ?> topLevelContainer() {