Address FIXME for QueuedNotificationManager
[yangtools.git] / yang / yang-data-codec-gson / src / test / java / org / opendaylight / yangtools / yang / data / codec / gson / retest / TestingNormalizedNodeStructuresCreator.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.codec.gson.retest;
9
10 import com.google.common.collect.Lists;
11 import com.google.common.collect.Sets;
12 import java.util.HashMap;
13 import java.util.Map;
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;
37
38 public class TestingNormalizedNodeStructuresCreator {
39
40     @SafeVarargs
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")));
45
46         cont1.withValue(Lists.newArrayList(children));
47         return cont1.build();
48     }
49
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();
55     }
56
57     private static UnkeyedListEntryNode lst12Entry1Node() {
58         DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> lst12Entry1Builder = Builders
59                 .unkeyedListEntryBuilder();
60         lst12Entry1Builder
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();
66     }
67
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")));
71
72         choc12Builder.withChild(lf17Node());
73         return choc12Builder.build();
74     }
75
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();
80     }
81
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();
91     }
92
93     private static LeafNode<Object> lf15_12NodeExternal() {
94         return Builders
95                 .leafBuilder()
96                 .withNodeIdentifier(
97                         new NodeIdentifier(QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_12")))
98                 .withValue("lf15_12 value from augmentation").build();
99     }
100
101     private static LeafNode<Object> lf15_11NodeExternal() {
102         return Builders
103                 .leafBuilder()
104                 .withNodeIdentifier(
105                         new NodeIdentifier(QName.create("ns:complex:json:augmentation", "2014-08-14", "lf15_11")))
106                 .withValue("lf15_11 value from augmentation").build();
107     }
108
109     @SafeVarargs
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();
119     }
120
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();
125     }
126
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"))));
132
133         choc11_c11AugmentBuilder.withChild(lf15_21Node());
134         return choc11_c11AugmentBuilder.build();
135     }
136
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();
141     }
142
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();
152     }
153
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", "lf11")).build();
158     }
159
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();
164     }
165
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();
176     }
177
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")));
181
182         DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> lst11Entry1Builder = Builders
183                 .mapEntryBuilder();
184
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");
188
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();
205     }
206
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")
212         );
213     }
214
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()
220                 .withNodeIdentifier(
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()
225                 .withNodeIdentifier(
226                         new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value2"))
227                 .withValue("lflst11 value2").build());
228         return lflst11.build();
229     }
230
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()
236                 .withNodeIdentifier(
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()
241                 .withNodeIdentifier(
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();
245     }
246
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);
252     }
253
254     public static NormalizedNode<?, ?> leafListNodeInContainer() {
255         return cont1Node(childLflst11());
256     }
257     public static NormalizedNode<?, ?> leafListNodeInContainerMultiline() {
258         return cont1Node(childLflst11Multiline());
259     }
260
261     public static NormalizedNode<?, ?> keyedListNodeInContainer() {
262         return cont1Node(childLst11());
263     }
264
265     public static NormalizedNode<?, ?> leafNodeViaAugmentationInContainer() {
266         return cont1Node(lf12_1Node());
267     }
268
269     public static NormalizedNode<?, ?> choiceNodeInContainer() {
270         return cont1Node(choc11Node(lf13Node()));
271     }
272
273     /**
274      * choc11 contains lf13, lf15_11 and lf15_12 are added via external augmentation
275      *
276      * @return
277      */
278     public static NormalizedNode<?, ?> caseNodeAugmentationInChoiceInContainer() {
279         return cont1Node(choc11Node(augmentC11AWithLf15_11AndLf15_12Node(), lf13Node(), augmentC11AWithLf15_21Node()));
280     }
281
282     public static NormalizedNode<?, ?> caseNodeExternalAugmentationInChoiceInContainer() {
283         return cont1Node(choc11Node(lf13Node(), augmentC11AWithLf15_11AndLf15_12Node(), externalAugmentC11AWithLf15_11AndLf15_12Node()));
284     }
285
286     public static NormalizedNode<?, ?> choiceNodeAugmentationInContainer() {
287         return cont1Node(choc12Node());
288     }
289
290     public static NormalizedNode<?, ?> unkeyedNodeInContainer() {
291         return cont1Node(lst12Node());
292     }
293
294     public static NormalizedNode<?, ?> topLevelContainer() {
295         return cont1Node();
296     }
297 }