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.ImmutableSet;
11 import java.util.Arrays;
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.NormalizedNode;
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;
32 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
33 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
34 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
36 public final class TestingNormalizedNodeStructuresCreator {
37 private TestingNormalizedNodeStructuresCreator() {
38 throw new UnsupportedOperationException();
42 static NormalizedNode<?, ?> cont1Node(
43 final DataContainerChild<? extends PathArgument, ?>... children) {
44 DataContainerNodeBuilder<NodeIdentifier, ContainerNode> cont1 = Builders.containerBuilder();
45 cont1.withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "cont1")));
47 cont1.withValue(Arrays.asList(children));
51 private static DataContainerChild<? extends PathArgument, ?> lst12Node() {
52 CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> lst12Builder = Builders.unkeyedListBuilder()
53 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lst12")));
54 lst12Builder.withChild(lst12Entry1Node());
55 return lst12Builder.build();
58 private static UnkeyedListEntryNode lst12Entry1Node() {
59 DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> lst12Entry1Builder = Builders
60 .unkeyedListEntryBuilder();
62 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lst12")));
63 lst12Entry1Builder.withChild(Builders.leafBuilder()
64 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf121")))
65 .withValue("lf121 value").build());
66 return lst12Entry1Builder.build();
69 private static DataContainerChild<? extends PathArgument, ?> choc12Node() {
70 DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choc12Builder = Builders.choiceBuilder()
71 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "choc12")));
73 choc12Builder.withChild(lf17Node());
74 return choc12Builder.build();
77 protected static LeafNode<Object> lf17Node() {
78 return Builders.leafBuilder()
79 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf17")))
80 .withValue("lf17 value").build();
83 private static DataContainerChild<? extends PathArgument, ?> externalAugmentC11AWithLf15_11AndLf15_12Node() {
84 DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> augmentationBuilder = Builders
85 .augmentationBuilder();
86 augmentationBuilder.withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(
87 QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_11"),
88 QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_12"))));
89 augmentationBuilder.withChild(lf15_11NodeExternal());
90 augmentationBuilder.withChild(lf15_12NodeExternal());
91 return augmentationBuilder.build();
94 private static LeafNode<Object> lf15_12NodeExternal() {
98 new NodeIdentifier(QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_12")))
99 .withValue("lf15_12 value from augmentation").build();
102 private static LeafNode<Object> lf15_11NodeExternal() {
106 new NodeIdentifier(QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_11")))
107 .withValue("lf15_11 value from augmentation").build();
111 private static DataContainerChild<? extends PathArgument, ?> choc11Node(
112 final DataContainerChild<? extends PathArgument, ?>... children) {
113 DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choc11Builder = Builders.choiceBuilder()
114 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "choc11")));
115 choc11Builder.withValue(Arrays.asList(children));
116 // choc11Builder.addChild(lf13Node());
117 // choc11Builder.addChild(augmentChoc11_c11A_lf1511AndLf1512Children());
118 // choc11Builder.addChild(augmentChoc11_c11_lf1521Children());
119 return choc11Builder.build();
122 private static LeafNode<Object> lf13Node() {
123 return Builders.leafBuilder()
124 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf13")))
125 .withValue("lf13 value").build();
128 private static DataContainerChild<? extends PathArgument, ?> augmentC11AWithLf15_21Node() {
129 return Builders.augmentationBuilder().withNodeIdentifier(
130 new AugmentationIdentifier(ImmutableSet.of(QName.create("ns:complex:json", "2014-08-11", "lf15_21"))))
131 .withChild(lf15_21Node()).build();
134 private static LeafNode<Object> lf15_21Node() {
135 return Builders.leafBuilder()
136 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf15_21")))
137 .withValue("lf15_21 value").build();
140 private static DataContainerChild<? extends PathArgument, ?> augmentC11AWithLf15_11AndLf15_12Node() {
141 return Builders.augmentationBuilder()
142 .withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(
143 QName.create("ns:complex:json", "2014-08-11", "lf15_11"),
144 QName.create("ns:complex:json", "2014-08-11", "lf15_12"))))
145 .withChild(lf15_11Node())
146 .withChild(lf15_12Node())
150 private static LeafNode<Object> lf15_12Node() {
151 return Builders.leafBuilder()
152 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf15_12")))
153 .withValue(QName.create("ns:complex:json", "2014-08-11", "ident")).build();
156 private static LeafNode<Object> lf15_11Node() {
157 return Builders.leafBuilder()
158 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf15_11")))
159 .withValue(ImmutableSet.of("one", "two")).build();
162 private static DataContainerChild<? extends PathArgument, ?> lf12_1Node() {
163 DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> augmentBuilder = Builders
164 .augmentationBuilder().withNodeIdentifier(
165 new AugmentationIdentifier(ImmutableSet.of(
166 QName.create("ns:complex:json", "2014-08-11", "lf12_1"),
167 QName.create("ns:complex:json", "2014-08-11", "lf12_2"))));
168 augmentBuilder.withChild(Builders.leafBuilder()
169 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf12_1")))
170 .withValue("lf12 value").build());
171 return augmentBuilder.build();
174 private static DataContainerChild<? extends PathArgument, ?> childLst11() {
176 DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> lst11Entry1Builder = Builders
179 Map<QName, Object> key = new HashMap<>();
180 key.put(QName.create("ns:complex:json", "2014-08-11", "key111"), "key111 value");
181 key.put(QName.create("ns:complex:json", "2014-08-11", "lf111"), "lf111 value");
183 lst11Entry1Builder.withNodeIdentifier(NodeIdentifierWithPredicates.of(QName.create("ns:complex:json",
184 "2014-08-11", "lst11"), key));
185 lst11Entry1Builder.withChild(Builders.leafBuilder()
186 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "key111")))
187 .withValue("key111 value").build());
188 lst11Entry1Builder.withChild(Builders.leafBuilder()
189 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf112")))
190 .withValue(lf112Value()).build());
191 lst11Entry1Builder.withChild(Builders.leafBuilder()
192 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf113")))
193 .withValue("lf113 value").build());
194 lst11Entry1Builder.withChild(Builders.leafBuilder()
195 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf111")))
196 .withValue("lf111 value").build());
197 return Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(
198 QName.create("ns:complex:json", "2014-08-11", "lst11"))).withChild(lst11Entry1Builder.build()).build();
201 private static Object lf112Value() {
202 return YangInstanceIdentifier.create(
203 new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "cont1")),
204 new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11")),
205 new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"),"foo")
209 private static DataContainerChild<? extends PathArgument, ?> childLflst11() {
210 ListNodeBuilder<Object, LeafSetEntryNode<Object>> lflst11 = Builders.leafSetBuilder().withNodeIdentifier(
211 new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11")));
212 lflst11.withChild(Builders
213 .leafSetEntryBuilder()
214 .withNodeIdentifier(new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"),
216 .withValue("lflst11 value1").build());
217 lflst11.withChild(Builders
218 .leafSetEntryBuilder()
219 .withNodeIdentifier(new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"),
221 .withValue("lflst11 value2").build());
222 return lflst11.build();
225 private static DataContainerChild<? extends PathArgument, ?> childLflst11Multiline() {
226 ListNodeBuilder<Object, LeafSetEntryNode<Object>> lflst11 = Builders.leafSetBuilder().withNodeIdentifier(
227 new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11")));
228 lflst11.withChild(Builders
229 .leafSetEntryBuilder()
230 .withNodeIdentifier(new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"),
231 "lflst11 value1\nanother line 1"))
232 .withValue("lflst11 value1\nanother line 1").build());
233 lflst11.withChild(Builders
234 .leafSetEntryBuilder()
235 .withNodeIdentifier(new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"),
236 "lflst11 value2\r\nanother line 2"))
237 .withValue("lflst11 value2\r\nanother line 2").build());
238 return lflst11.build();
241 public static NormalizedNode<?, ?> leafNodeInContainer() {
242 LeafNode<Object> lf11 = Builders.leafBuilder()
243 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf11")))
244 .withValue(453).build();
245 return cont1Node(lf11);
248 public static NormalizedNode<?, ?> leafListNodeInContainer() {
249 return cont1Node(childLflst11());
252 public static NormalizedNode<?, ?> leafListNodeInContainerMultiline() {
253 return cont1Node(childLflst11Multiline());
256 public static NormalizedNode<?, ?> keyedListNodeInContainer() {
257 return cont1Node(childLst11());
260 public static NormalizedNode<?, ?> leafNodeViaAugmentationInContainer() {
261 return cont1Node(lf12_1Node());
264 public static NormalizedNode<?, ?> choiceNodeInContainer() {
265 return cont1Node(choc11Node(lf13Node()));
269 * choc11 contains lf13, lf15_11 and lf15_12 are added via external augmentation.
271 public static NormalizedNode<?, ?> caseNodeAugmentationInChoiceInContainer() {
272 return cont1Node(choc11Node(augmentC11AWithLf15_11AndLf15_12Node(), lf13Node(), augmentC11AWithLf15_21Node()));
275 public static NormalizedNode<?, ?> caseNodeExternalAugmentationInChoiceInContainer() {
276 return cont1Node(choc11Node(lf13Node(), augmentC11AWithLf15_11AndLf15_12Node(),
277 externalAugmentC11AWithLf15_11AndLf15_12Node()));
280 public static NormalizedNode<?, ?> choiceNodeAugmentationInContainer() {
281 return cont1Node(choc12Node());
284 public static NormalizedNode<?, ?> unkeyedNodeInContainer() {
285 return cont1Node(lst12Node());
288 public static NormalizedNode<?, ?> topLevelContainer() {