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.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.schema.ChoiceNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
23 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
24 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
25 import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
26 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
29 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
31 public final class TestingNormalizedNodeStructuresCreator {
32 private static final QNameModule COMPLEX_JSON =
33 QNameModule.create(XMLNamespace.of("ns:complex:json"), Revision.of("2014-08-11"));
34 private static final QNameModule COMPLEX_JSON_AUG =
35 QNameModule.create(XMLNamespace.of("ns:complex:json:augmentation"), Revision.of("2014-08-14"));
37 private TestingNormalizedNodeStructuresCreator() {
38 throw new UnsupportedOperationException();
41 static ContainerNode cont1Node(final DataContainerChild... children) {
42 return Builders.containerBuilder()
43 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "cont1")))
44 .withValue(Arrays.asList(children))
48 static ContainerNode cont2Node() {
49 return Builders.containerBuilder()
50 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "cont2")))
54 private static UnkeyedListNode lst12Node() {
55 return Builders.unkeyedListBuilder()
56 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lst12")))
57 .withChild(lst12Entry1Node())
61 private static UnkeyedListEntryNode lst12Entry1Node() {
62 return Builders.unkeyedListEntryBuilder()
63 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lst12")))
64 .withChild(Builders.leafBuilder()
65 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf121")))
66 .withValue("lf121 value").build())
70 private static ChoiceNode choc12Node() {
71 return Builders.choiceBuilder()
72 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "choc12")))
73 .withChild(lf17Node())
77 protected static LeafNode<Object> lf17Node() {
78 return Builders.leafBuilder()
79 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf17")))
80 .withValue("lf17 value").build();
83 private static LeafNode<Object> lf15_12NodeExternal() {
84 return Builders.leafBuilder()
85 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON_AUG, "lf15_12")))
86 .withValue("lf15_12 value from augmentation")
90 private static LeafNode<Object> lf15_11NodeExternal() {
91 return Builders.leafBuilder()
92 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON_AUG, "lf15_11")))
93 .withValue("lf15_11 value from augmentation")
97 private static ChoiceNode choc11Node(final DataContainerChild... children) {
98 return Builders.choiceBuilder()
99 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "choc11")))
100 .withValue(Arrays.asList(children))
101 // choc11Builder.addChild(lf13Node());
102 // choc11Builder.addChild(augmentChoc11_c11A_lf1511AndLf1512Children());
103 // choc11Builder.addChild(augmentChoc11_c11_lf1521Children());
107 private static LeafNode<Object> lf13Node() {
108 return Builders.leafBuilder()
109 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf13")))
110 .withValue("lf13 value").build();
113 private static LeafNode<Object> lf15_21Node() {
114 return Builders.leafBuilder()
115 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf15_21")))
116 .withValue("lf15_21 value").build();
119 private static LeafNode<Object> lf15_12Node() {
120 return Builders.leafBuilder()
121 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf15_12")))
122 .withValue(QName.create(COMPLEX_JSON, "ident")).build();
125 private static LeafNode<Object> lf15_11Node() {
126 return Builders.leafBuilder()
127 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf15_11")))
128 .withValue(ImmutableSet.of("one", "two")).build();
131 private static SystemMapNode childLst11() {
132 return Builders.mapBuilder()
133 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lst11")))
134 .withChild(Builders.mapEntryBuilder().withNodeIdentifier(
135 NodeIdentifierWithPredicates.of(QName.create(COMPLEX_JSON, "lst11"), ImmutableMap.of(
136 QName.create(COMPLEX_JSON, "key111"), "key111 value",
137 QName.create(COMPLEX_JSON, "lf111"), "lf111 value")))
138 .withChild(Builders.leafBuilder()
139 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "key111")))
140 .withValue("key111 value").build())
141 .withChild(Builders.leafBuilder()
142 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf112")))
143 .withValue(lf112Value()).build())
144 .withChild(Builders.leafBuilder()
145 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf113")))
146 .withValue("lf113 value").build())
147 .withChild(Builders.leafBuilder()
148 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf111")))
149 .withValue("lf111 value").build())
154 private static Object lf112Value() {
155 return YangInstanceIdentifier.create(
156 new NodeIdentifier(QName.create(COMPLEX_JSON, "cont1")),
157 new NodeIdentifier(QName.create(COMPLEX_JSON, "lflst11")),
158 new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"),"foo")
162 private static SystemLeafSetNode<?> childLflst11() {
163 return Builders.leafSetBuilder()
164 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lflst11")))
165 .withChild(Builders.leafSetEntryBuilder()
166 .withNodeIdentifier(new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"), "lflst11 value1"))
167 .withValue("lflst11 value1").build())
168 .withChild(Builders.leafSetEntryBuilder()
169 .withNodeIdentifier(new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"), "lflst11 value2"))
170 .withValue("lflst11 value2").build())
174 private static SystemLeafSetNode<?> childLflst11Multiline() {
175 return Builders.leafSetBuilder()
176 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lflst11")))
177 .withChild(Builders.leafSetEntryBuilder()
178 .withNodeIdentifier(new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"),
179 "lflst11 value1\nanother line 1"))
180 .withValue("lflst11 value1\nanother line 1").build())
181 .withChild(Builders.leafSetEntryBuilder()
182 .withNodeIdentifier(new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"),
183 "lflst11 value2\r\nanother line 2"))
184 .withValue("lflst11 value2\r\nanother line 2").build())
188 public static ContainerNode leafNodeInContainer() {
189 return cont1Node(Builders.leafBuilder()
190 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf11")))
191 .withValue(453).build());
194 public static ContainerNode leafListNodeInContainer() {
195 return cont1Node(childLflst11());
198 public static ContainerNode leafListNodeInContainerMultiline() {
199 return cont1Node(childLflst11Multiline());
202 public static ContainerNode keyedListNodeInContainer() {
203 return cont1Node(childLst11());
206 public static ContainerNode leafNodeViaAugmentationInContainer() {
207 return cont1Node(Builders.leafBuilder()
208 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lf12_1")))
209 .withValue("lf12 value")
213 public static ContainerNode choiceNodeInContainer() {
214 return cont1Node(choc11Node(lf13Node()));
218 * choc11 contains lf13, lf15_11 and lf15_12 are added via external augmentation.
220 public static ContainerNode caseNodeAugmentationInChoiceInContainer() {
221 return cont1Node(choc11Node(lf15_11Node(), lf15_12Node(), lf13Node(), lf15_21Node()));
224 public static ContainerNode caseNodeExternalAugmentationInChoiceInContainer() {
225 return cont1Node(choc11Node(lf13Node(), lf15_11Node(), lf15_12Node(),
226 lf15_11NodeExternal(), lf15_12NodeExternal()));
229 public static ContainerNode choiceNodeAugmentationInContainer() {
230 return cont1Node(choc12Node());
233 public static ContainerNode unkeyedNodeInContainer() {
234 return cont1Node(lst12Node());
237 public static ContainerNode topLevelContainer() {
241 public static ContainerNode emptyContainerInContainer() {
242 return cont1Node(Builders.containerBuilder()
243 .withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "cont11")))