2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
23 import java.io.FileNotFoundException;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.LinkedList;
28 import java.util.List;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
34 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
35 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
36 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
37 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
39 import static org.hamcrest.MatcherAssert.assertThat;
40 import static org.hamcrest.Matchers.is;
41 import static org.junit.Assert.assertTrue;
43 public final class PropertiesSerializerTest {
44 private SchemaContext context;
47 public void initialization() throws FileNotFoundException {
48 context = compileYangFile();
52 public void testBasicConstructs() throws SvcLogicException {
53 String uri = "test-yang:cont1/cont2";
54 Map<String, String> params = new HashMap<>();
55 params.put("test-yang_cont1.cont2.cont3.leaf10", "abc");
56 params.put("test-yang_cont1.cont2.list1[0].leaf1", "abc");
57 params.put("test-yang_cont1.cont2.list1[0].leaf2", "abc");
58 params.put("test-yang_cont1.cont2.list1[0].leaf3", "abc");
59 params.put("test-yang_cont1.cont2.list1[0].ll1[0]", "abc");
60 params.put("test-yang_cont1.cont2.list1[0].ll1[1]", "abc");
61 params.put("test-yang_cont1.cont2.list1[0].ll2[0]", "abc");
62 params.put("test-yang_cont1.cont2.list1[0].ll2[1]", "abc");
63 params.put("test-yang_cont1.cont2.list1[0].cont4.leaf11", "abc");
64 params.put("test-yang_cont1.cont2.list1[0].list4[0].leaf8", "abc");
65 params.put("test-yang_cont1.cont2.list1[0].list4[1].leaf8", "abc");
66 params.put("test-yang_cont1.cont2.list1[0].list5[0].leaf9", "abc");
67 params.put("test-yang_cont1.cont2.list1[0].list5[1].leaf9", "abc");
68 params.put("test-yang_cont1.cont2.list1[1].leaf1", "abc");
69 params.put("test-yang_cont1.cont2.list1[1].leaf2", "abc");
70 params.put("test-yang_cont1.cont2.list1[1].leaf3", "abc");
71 params.put("test-yang_cont1.cont2.list1[1].ll1[0]", "abc");
72 params.put("test-yang_cont1.cont2.list1[1].ll1[1]", "abc");
73 params.put("test-yang_cont1.cont2.list1[1].ll2[0]", "abc");
74 params.put("test-yang_cont1.cont2.list1[1].ll2[1]", "abc");
75 params.put("test-yang_cont1.cont2.list1[1].cont4.leaf11", "abc");
76 params.put("test-yang_cont1.cont2.list1[1].list4[0].leaf8", "abc");
77 params.put("test-yang_cont1.cont2.list1[1].list4[1].leaf8", "abc");
78 params.put("test-yang_cont1.cont2.list1[1].list5[0].leaf9", "abc");
79 params.put("test-yang_cont1.cont2.list1[1].list5[1].leaf9", "abc");
80 params.put("test-yang_cont1.cont2.list2[0].leaf4", "abc");
81 params.put("test-yang_cont1.cont2.list2[1].leaf4", "abc");
82 params.put("test-yang_cont1.cont2.leaf5", "abc");
83 params.put("test-yang_cont1.cont2.leaf6", "abc");
84 params.put("test-yang_cont1.cont2.ll3[0]", "abc");
85 params.put("test-yang_cont1.cont2.ll3[1]", "abc");
86 params.put("test-yang_cont1.cont2.ll4[0]", "abc");
87 params.put("test-yang_cont1.cont2.ll4[1]", "abc");
88 InstanceIdentifierContext<?> iCtx = ParserIdentifier
89 .toInstanceIdentifier(uri, context, null);
91 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
92 iCtx.getSchemaNode(), context, uri);
93 PropertiesNode node = ser.encode(params);
95 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
97 assertThat(childNodes.containsKey("cont3"), is(true));
98 SingleInstanceNode cont3 = ((SingleInstanceNode) childNodes.get("cont3"));
99 assertThat(cont3.uri(), is("test-yang:cont1.cont2.cont3"));
100 assertThat(cont3.children().containsKey("leaf10"), is(true));
102 assertThat(childNodes.containsKey("list1"), is(true));
103 HolderNode list1Holder = ((ListHolderNode) childNodes.get("list1"));
104 assertThat(list1Holder.uri(), is("test-yang:cont1.cont2.list1"));
105 MultiInstanceNode list10 = ((MultiInstanceNode) list1Holder.child("0"));
106 assertThat(list10.uri(), is("test-yang:cont1.cont2.list1[0]"));
107 Map<String, DataNodeChild> list10Child = list10.children();
108 assertThat(list10Child.containsKey("leaf1"), is(true));
109 LeafNode l = ((LeafNode) list10Child.get("leaf1"));
110 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].leaf1"));
111 assertThat(list10Child.containsKey("leaf2"), is(true));
112 l = ((LeafNode) list10Child.get("leaf2"));
113 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].leaf2"));
114 assertThat(list10Child.containsKey("leaf2"), is(true));
115 l = ((LeafNode) list10Child.get("leaf3"));
116 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].leaf3"));
118 LeafListHolderNode ll1Holder = ((LeafListHolderNode) list10Child.get("ll1"));
119 assertThat(ll1Holder.uri(), is("test-yang:cont1.cont2.list1[0].ll1"));
120 assertThat(ll1Holder.children().containsKey("0"), is(true));
121 l = ((LeafNode) ll1Holder.child("0"));
122 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll1[0]"));
123 assertThat(ll1Holder.children().containsKey("1"), is(true));
124 l = ((LeafNode) ll1Holder.child("1"));
125 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll1[1]"));
127 LeafListHolderNode ll2Holder = ((LeafListHolderNode) list10Child.get("ll2"));
128 assertThat(ll2Holder.uri(), is("test-yang:cont1.cont2.list1[0].ll2"));
129 assertThat(ll2Holder.children().containsKey("0"), is(true));
130 l = ((LeafNode) ll2Holder.child("0"));
131 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll2[0]"));
132 assertThat(ll2Holder.children().containsKey("1"), is(true));
133 l = ((LeafNode) ll2Holder.child("1"));
134 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll2[1]"));
136 SingleInstanceNode cont4 = ((SingleInstanceNode) list10Child.get("cont4"));
137 assertThat(cont4.uri(), is("test-yang:cont1.cont2.list1[0].cont4"));
138 assertThat(cont4.children().containsKey("leaf11"), is(true));
139 l = ((LeafNode) cont4.children().get("leaf11"));
140 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].cont4.leaf11"));
142 HolderNode list4Holder = ((HolderNode) list10Child.get("list4"));
143 assertThat(list4Holder.uri(), is("test-yang:cont1.cont2.list1[0].list4"));
144 Map<String, PropertiesNode> c = list4Holder.children();
145 MultiInstanceNode list40 = ((MultiInstanceNode) c.get("0"));
146 assertThat(list40.uri(), is("test-yang:cont1.cont2.list1[0].list4[0]"));
147 assertThat(list40.children().containsKey("leaf8"), is(true));
148 l = ((LeafNode) list40.children().get("leaf8"));
149 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list4[0].leaf8"));
150 MultiInstanceNode list41 = ((MultiInstanceNode) c.get("1"));
151 assertThat(list41.uri(), is("test-yang:cont1.cont2.list1[0].list4[1]"));
152 assertThat(list41.children().containsKey("leaf8"), is(true));
153 l = ((LeafNode) list41.children().get("leaf8"));
154 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list4[1].leaf8"));
156 HolderNode list5Holder = ((HolderNode) list10Child.get("list5"));
157 assertThat(list5Holder.uri(), is("test-yang:cont1.cont2.list1[0].list5"));
158 c = list5Holder.children();
159 MultiInstanceNode list50 = ((MultiInstanceNode) c.get("0"));
160 assertThat(list50.uri(), is("test-yang:cont1.cont2.list1[0].list5[0]"));
161 assertThat(list50.children().containsKey("leaf9"), is(true));
162 l = ((LeafNode) list50.children().get("leaf9"));
163 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list5[0].leaf9"));
164 MultiInstanceNode list51 = ((MultiInstanceNode) c.get("1"));
165 assertThat(list51.uri(), is("test-yang:cont1.cont2.list1[0].list5[1]"));
166 assertThat(list51.children().containsKey("leaf9"), is(true));
167 l = ((LeafNode) list51.children().get("leaf9"));
168 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list5[1].leaf9"));
170 MultiInstanceNode list11 = ((MultiInstanceNode) list1Holder.child("1"));
171 assertThat(list11.uri(), is("test-yang:cont1.cont2.list1[1]"));
172 Map<String, DataNodeChild> list11Child = list11.children();
173 assertThat(list11Child.containsKey("leaf1"), is(true));
174 l = ((LeafNode) list11Child.get("leaf1"));
175 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].leaf1"));
176 assertThat(list11Child.containsKey("leaf2"), is(true));
177 l = ((LeafNode) list11Child.get("leaf2"));
178 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].leaf2"));
179 assertThat(list11Child.containsKey("leaf3"), is(true));
180 l = ((LeafNode) list11Child.get("leaf3"));
181 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].leaf3"));
183 ll1Holder = ((LeafListHolderNode) list11Child.get("ll1"));
184 assertThat(ll1Holder.uri(), is("test-yang:cont1.cont2.list1[1].ll1"));
185 assertThat(ll1Holder.children().containsKey("0"), is(true));
186 l = ((LeafNode) ll1Holder.children().get("0"));
187 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll1[0]"));
188 assertThat(ll1Holder.children().containsKey("1"), is(true));
189 l = ((LeafNode) ll1Holder.children().get("1"));
190 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll1[1]"));
192 ll2Holder = ((LeafListHolderNode) list11Child.get("ll2"));
193 assertThat(ll2Holder.uri(), is("test-yang:cont1.cont2.list1[1].ll2"));
194 assertThat(ll2Holder.children().containsKey("0"), is(true));
195 l = ((LeafNode) ll2Holder.children().get("0"));
196 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll2[0]"));
197 assertThat(ll2Holder.children().containsKey("1"), is(true));
198 l = ((LeafNode) ll2Holder.children().get("1"));
199 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll2[1]"));
201 cont4 = ((SingleInstanceNode) list11Child.get("cont4"));
202 assertThat(cont4.uri(), is("test-yang:cont1.cont2.list1[1].cont4"));
203 assertThat(cont4.children().containsKey("leaf11"), is(true));
204 l = ((LeafNode) cont4.children().get("leaf11"));
205 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].cont4.leaf11"));
207 list4Holder = ((HolderNode) list11Child.get("list4"));
208 assertThat(list4Holder.uri(), is("test-yang:cont1.cont2.list1[1].list4"));
209 c = list4Holder.children();
210 list40 = ((MultiInstanceNode) c.get("0"));
211 assertThat(list40.uri(), is("test-yang:cont1.cont2.list1[1].list4[0]"));
212 assertThat(list40.children().containsKey("leaf8"), is(true));
213 l = ((LeafNode) list40.children().get("leaf8"));
214 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list4[0].leaf8"));
215 list41 = ((MultiInstanceNode) c.get("1"));
216 assertThat(list41.uri(), is("test-yang:cont1.cont2.list1[1].list4[1]"));
217 assertThat(list41.children().containsKey("leaf8"), is(true));
218 l = ((LeafNode) list41.children().get("leaf8"));
219 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list4[1].leaf8"));
221 list5Holder = ((HolderNode) list11Child.get("list5"));
222 assertThat(list5Holder.uri(), is("test-yang:cont1.cont2.list1[1].list5"));
223 c = list5Holder.children();
224 list50 = ((MultiInstanceNode) c.get("0"));
225 assertThat(list50.uri(), is("test-yang:cont1.cont2.list1[1].list5[0]"));
226 assertThat(list50.children().containsKey("leaf9"), is(true));
227 l = ((LeafNode) list50.children().get("leaf9"));
228 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list5[0].leaf9"));
229 list51 = ((MultiInstanceNode) c.get("1"));
230 assertThat(list51.uri(), is("test-yang:cont1.cont2.list1[1].list5[1]"));
231 assertThat(list51.children().containsKey("leaf9"), is(true));
232 l = ((LeafNode) list51.children().get("leaf9"));
233 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list5[1].leaf9"));
235 assertThat(childNodes.containsKey("list2"), is(true));
236 HolderNode list2Holder = ((HolderNode) childNodes.get("list2"));
237 assertThat(list2Holder.uri(), is("test-yang:cont1.cont2.list2"));
238 InnerNode list20 = ((InnerNode) list2Holder.children().get("0"));
239 assertThat(list20.uri(), is("test-yang:cont1.cont2.list2[0]"));
240 assertThat(list20.children().containsKey("leaf4"), is(true));
241 l = ((LeafNode) list20.children().get("leaf4"));
242 assertThat(l.uri(), is("test-yang:cont1.cont2.list2[0].leaf4"));
243 InnerNode list21 = ((InnerNode) list2Holder.children().get("1"));
244 assertThat(list21.uri(), is("test-yang:cont1.cont2.list2[1]"));
245 assertThat(list21.children().containsKey("leaf4"), is(true));
246 l = ((LeafNode) list21.children().get("leaf4"));
247 assertThat(l.uri(), is("test-yang:cont1.cont2.list2[1].leaf4"));
249 assertThat(childNodes.containsKey("leaf5"), is(true));
250 l = ((LeafNode) childNodes.get("leaf5"));
251 assertThat(l.uri(), is("test-yang:cont1.cont2.leaf5"));
252 assertThat(childNodes.containsKey("leaf6"), is(true));
253 l = ((LeafNode) childNodes.get("leaf6"));
254 assertThat(l.uri(), is("test-yang:cont1.cont2.leaf6"));
256 HolderNode ll3Holder = ((HolderNode) childNodes.get("ll3"));
257 assertThat(ll3Holder.uri(), is("test-yang:cont1.cont2.ll3"));
258 assertThat(((LeafNode) ll3Holder.children().get("0")).name(), is("ll3"));
259 l = ((LeafNode) ll3Holder.children().get("0"));
260 assertThat(l.uri(), is("test-yang:cont1.cont2.ll3[0]"));
261 assertThat(((LeafNode) ll3Holder.children().get("1")).name(), is("ll3"));
262 l = ((LeafNode) ll3Holder.children().get("1"));
263 assertThat(l.uri(), is("test-yang:cont1.cont2.ll3[1]"));
265 HolderNode ll4Holder = ((HolderNode) childNodes.get("ll4"));
266 assertThat(ll4Holder.uri(), is("test-yang:cont1.cont2.ll4"));
267 assertThat(((LeafNode) ll4Holder.children().get("0")).name(), is("ll4"));
268 l = ((LeafNode) ll4Holder.children().get("0"));
269 assertThat(l.uri(), is("test-yang:cont1.cont2.ll4[0]"));
270 assertThat(((LeafNode) ll4Holder.children().get("1")).name(), is("ll4"));
271 l = ((LeafNode) ll4Holder.children().get("1"));
272 assertThat(l.uri(), is("test-yang:cont1.cont2.ll4[1]"));
274 Map<String, String> output = ser.decode(node);
275 assertThat(output.size(), is(params.size()));
276 for (Map.Entry<String, String> entry : output.entrySet()) {
277 assertTrue(params.containsKey(entry.getKey()));
282 public void testAugment() throws SvcLogicException {
283 String uri = "test-yang:cont1/cont2";
284 Map<String, String> params = new HashMap<>();
285 params.put("test-yang_cont1.cont2.cont4.leaf10", "abc");
286 params.put("test-yang_cont1.cont2.cont4.test-augment_cont5.leaf13", "abc");
287 params.put("test-yang_cont1.cont2.cont4.test-augment_list7[0].leaf14", "abc");
288 params.put("test-yang_cont1.cont2.cont4.test-augment_list7[1].leaf14", "abc");
289 params.put("test-yang_cont1.cont2.cont4.test-augment_leaf15", "abc");
290 params.put("test-yang_cont1.cont2.cont4.test-augment_ll6[0]", "abc");
291 params.put("test-yang_cont1.cont2.cont4.test-augment_ll6[1]", "abc");
292 params.put("test-yang_cont1.cont2.list6[0].leaf11", "abc");
293 params.put("test-yang_cont1.cont2.list6[1].leaf11", "abc");
294 params.put("test-yang_cont1.cont2.leaf12", "abc");
295 params.put("test-yang_cont1.cont2.ll5[0]", "abc");
296 params.put("test-yang_cont1.cont2.ll5[1]", "abc");
298 InstanceIdentifierContext<?> iCtx = ParserIdentifier
299 .toInstanceIdentifier(uri, context, null);
300 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
301 iCtx.getSchemaNode(), context, uri);
302 PropertiesNode node = ser.encode(params);
304 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
306 assertThat(childNodes.containsKey("cont4"), is(true));
307 SingleInstanceNode cont4 = ((SingleInstanceNode) childNodes.get("cont4"));
308 for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
309 : cont4.augmentations().asMap().entrySet()) {
310 Collection<PropertiesNode> child = augToChild.getValue();
311 if (!child.isEmpty()) {
312 List<String> expectedNodes = new LinkedList<>();
313 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:cont5");
314 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:list7");
315 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:leaf15");
316 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:ll6");
317 assertThat(expectedNodes.size(), is(child.size()));
318 for (PropertiesNode pNode : child) {
319 assertThat(expectedNodes.contains(pNode.uri()), is(true));
320 if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:cont5")) {
321 assertThat(((SingleInstanceNode) pNode).children().containsKey("leaf13"), is(true));
322 LeafNode l = ((LeafNode) ((SingleInstanceNode) pNode).children().get("leaf13"));
323 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont5.leaf13"));
324 } else if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:list7")) {
325 ListHolderNode list7Holder = ((ListHolderNode) pNode);
326 MultiInstanceNode list7 = ((MultiInstanceNode) list7Holder.child("0"));
327 assertThat(list7.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[0]"));
328 Map<String, DataNodeChild> list7Child = list7.children();
329 assertThat(list7Child.containsKey("leaf14"), is(true));
330 LeafNode l = ((LeafNode) list7Child.get("leaf14"));
331 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[0].leaf14"));
332 list7 = ((MultiInstanceNode) list7Holder.child("1"));
333 assertThat(list7.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[1]"));
334 list7Child = list7.children();
335 assertThat(list7Child.containsKey("leaf14"), is(true));
336 l = ((LeafNode) list7Child.get("leaf14"));
337 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[1].leaf14"));
338 } else if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:leaf15")) {
339 LeafNode leaf15 = ((LeafNode) pNode);
340 assertThat(leaf15.name(), is("leaf15"));
341 assertThat(leaf15.uri(), is("test-yang:cont1.cont2.cont4.test-augment:leaf15"));
342 } else if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:ll6")) {
343 LeafListHolderNode ll6Holder = ((LeafListHolderNode) pNode);
344 assertThat(ll6Holder.children().containsKey("0"), is(true));
345 LeafNode l = ((LeafNode) ll6Holder.children().get("0"));
346 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:ll6[0]"));
347 assertThat(ll6Holder.children().containsKey("1"), is(true));
348 l = ((LeafNode) ll6Holder.children().get("1"));
349 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:ll6[1]"));
354 assertThat(cont4.uri(), is("test-yang:cont1.cont2.cont4"));
355 assertThat(cont4.children().containsKey("leaf10"), is(true));
356 LeafNode l = ((LeafNode) cont4.children().get("leaf10"));
357 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.leaf10"));
359 assertThat(childNodes.containsKey("list6"), is(true));
360 HolderNode list6Holder = ((ListHolderNode) childNodes.get("list6"));
361 assertThat(list6Holder.uri(), is("test-yang:cont1.cont2.list6"));
362 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
363 assertThat(list6.uri(), is("test-yang:cont1.cont2.list6[0]"));
364 Map<String, DataNodeChild> list6Child = list6.children();
365 assertThat(list6Child.containsKey("leaf11"), is(true));
366 l = ((LeafNode) list6Child.get("leaf11"));
367 assertThat(l.uri(), is("test-yang:cont1.cont2.list6[0].leaf11"));
368 list6 = ((MultiInstanceNode) list6Holder.child("1"));
369 assertThat(list6.uri(), is("test-yang:cont1.cont2.list6[1]"));
370 list6Child = list6.children();
371 assertThat(list6Child.containsKey("leaf11"), is(true));
372 l = ((LeafNode) list6Child.get("leaf11"));
373 assertThat(l.uri(), is("test-yang:cont1.cont2.list6[1].leaf11"));
375 assertThat(childNodes.containsKey("leaf12"), is(true));
376 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf12"));
377 assertThat(leaf12.name(), is("leaf12"));
378 assertThat(leaf12.uri(), is("test-yang:cont1.cont2.leaf12"));
380 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll5"));
381 assertThat(ll5Holder.uri(), is("test-yang:cont1.cont2.ll5"));
382 assertThat(ll5Holder.children().containsKey("0"), is(true));
383 l = ((LeafNode) ll5Holder.children().get("0"));
384 assertThat(l.uri(), is("test-yang:cont1.cont2.ll5[0]"));
385 assertThat(ll5Holder.children().containsKey("1"), is(true));
386 l = ((LeafNode) ll5Holder.children().get("1"));
387 assertThat(l.uri(), is("test-yang:cont1.cont2.ll5[1]"));
389 Map<String, String> output = ser.decode(node);
390 for (Map.Entry<String, String> entry : output.entrySet()) {
391 assertTrue(params.containsKey(entry.getKey()));
396 public void testChoiceCase1() throws SvcLogicException {
397 String uri = "test-yang:cont8";
398 Map<String, String> params = new HashMap<>();
399 params.put("test-yang_cont8.cont6.leaf16", "abc");
400 params.put("test-yang_cont8.list8[0].leaf18", "abc");
401 params.put("test-yang_cont8.list8[1].leaf18", "abc");
402 params.put("test-yang_cont8.leaf19", "abc");
403 params.put("test-yang_cont8.ll7[0]", "abc");
404 params.put("test-yang_cont8.ll7[1]", "abc");
406 InstanceIdentifierContext<?> iCtx = ParserIdentifier
407 .toInstanceIdentifier(uri, context, null);
408 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
409 iCtx.getSchemaNode(), context, uri);
410 PropertiesNode node = ser.encode(params);
412 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
414 assertThat(childNodes.containsKey("cont6"), is(true));
415 SingleInstanceNode cont6 = ((SingleInstanceNode) childNodes.get("cont6"));
416 assertThat(cont6.uri(), is("test-yang:cont8.cont6"));
417 assertThat(cont6.children().containsKey("leaf16"), is(true));
418 LeafNode l = ((LeafNode) cont6.children().get("leaf16"));
419 assertThat(l.uri(), is("test-yang:cont8.cont6.leaf16"));
421 assertThat(childNodes.containsKey("list8"), is(true));
422 HolderNode list6Holder = ((ListHolderNode) childNodes.get("list8"));
423 assertThat(list6Holder.uri(), is("test-yang:cont8.list8"));
424 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
425 assertThat(list6.uri(), is("test-yang:cont8.list8[0]"));
426 Map<String, DataNodeChild> list6Child = list6.children();
427 assertThat(list6Child.containsKey("leaf18"), is(true));
428 l = ((LeafNode) list6Child.get("leaf18"));
429 assertThat(l.uri(), is("test-yang:cont8.list8[0].leaf18"));
430 list6 = ((MultiInstanceNode) list6Holder.child("1"));
431 list6Child = list6.children();
432 assertThat(list6Child.containsKey("leaf18"), is(true));
433 l = ((LeafNode) list6Child.get("leaf18"));
434 assertThat(l.uri(), is("test-yang:cont8.list8[1].leaf18"));
436 assertThat(childNodes.containsKey("leaf19"), is(true));
437 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf19"));
438 assertThat(leaf12.name(), is("leaf19"));
439 assertThat(leaf12.uri(), is("test-yang:cont8.leaf19"));
441 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll7"));
442 assertThat(ll5Holder.uri(), is("test-yang:cont8.ll7"));
443 assertThat(ll5Holder.children().containsKey("0"), is(true));
444 l = ((LeafNode) ll5Holder.children().get("0"));
445 assertThat(l.uri(), is("test-yang:cont8.ll7[0]"));
446 assertThat(ll5Holder.children().containsKey("1"), is(true));
447 l = ((LeafNode) ll5Holder.children().get("1"));
448 assertThat(l.uri(), is("test-yang:cont8.ll7[1]"));
450 Map<String, String> output = ser.decode(node);
451 assertThat(output.size(), is(params.size()));
452 for (Map.Entry<String, String> entry : output.entrySet()) {
453 assertTrue(params.containsKey(entry.getKey()));
458 public void testChoiceCase2() throws SvcLogicException {
459 String uri = "test-yang:cont9";
460 Map<String, String> params = new HashMap<>();
461 params.put("test-yang_cont9.leaf20", "abc");
462 params.put("test-yang_cont9.ll8[0]", "abc");
463 params.put("test-yang_cont9.cont11.leaf25", "abc");
465 InstanceIdentifierContext<?> iCtx = ParserIdentifier
466 .toInstanceIdentifier(uri, context, null);
467 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
468 iCtx.getSchemaNode(), context, uri);
469 PropertiesNode node = ser.encode(params);
471 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
473 assertThat(childNodes.containsKey("cont11"), is(true));
474 SingleInstanceNode cont4 = ((SingleInstanceNode) childNodes.get("cont11"));
475 assertThat(cont4.uri(), is("test-yang:cont9.cont11"));
476 assertThat(cont4.children().containsKey("leaf25"), is(true));
477 LeafNode l = ((LeafNode) cont4.children().get("leaf25"));
478 assertThat(l.uri(), is("test-yang:cont9.cont11.leaf25"));
480 assertThat(childNodes.containsKey("leaf20"), is(true));
481 l = ((LeafNode) childNodes.get("leaf20"));
482 assertThat(l.uri(), is("test-yang:cont9.leaf20"));
484 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll8"));
485 assertThat(ll5Holder.uri(), is("test-yang:cont9.ll8"));
486 assertThat(ll5Holder.children().containsKey("0"), is(true));
487 l = ((LeafNode) ll5Holder.children().get("0"));
488 assertThat(l.uri(), is("test-yang:cont9.ll8[0]"));
490 Map<String, String> output = ser.decode(node);
491 assertThat(output.size(), is(params.size()));
492 for (Map.Entry<String, String> entry : output.entrySet()) {
493 assertTrue(params.containsKey(entry.getKey()));
498 public void testChoiceCase3() throws SvcLogicException {
499 String uri = "test-yang:cont8/cont6";
500 Map<String, String> params = new HashMap<>();
501 params.put("test-yang_cont8.cont6.test-augment_leaf21", "abc");
503 InstanceIdentifierContext<?> iCtx = ParserIdentifier
504 .toInstanceIdentifier(uri, context, null);
505 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
506 iCtx.getSchemaNode(), context, uri);
507 PropertiesNode node = ser.encode(params);
509 for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
510 : node.augmentations().asMap().entrySet()) {
511 Collection<PropertiesNode> child = augToChild.getValue();
512 if (!child.isEmpty()) {
513 List<String> expectedNodes = new LinkedList<>();
514 expectedNodes.add("test-yang:cont8.cont6.test-augment:leaf21");
515 assertThat(expectedNodes.size(), is(child.size()));
516 for (PropertiesNode pNode : child) {
517 assertThat(expectedNodes.contains(pNode.uri()), is(true));
522 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
524 assertThat(childNodes.containsKey("leaf21"), is(true));
525 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf21"));
526 assertThat(leaf12.name(), is("leaf21"));
527 assertThat(leaf12.uri(), is("test-yang:cont8.cont6.test-augment:leaf21"));
529 Map<String, String> output = ser.decode(node);
530 assertThat(output.size(), is(params.size()));
531 for (Map.Entry<String, String> entry : output.entrySet()) {
532 assertTrue(params.containsKey(entry.getKey()));
537 public void testGrouping() throws SvcLogicException {
538 String uri = "test-yang:cont13";
539 Map<String, String> params = new HashMap<>();
540 params.put("test-yang_cont13.cont12.leaf26", "abc");
541 params.put("test-yang_cont13.list9[0].leaf27", "abc");
542 params.put("test-yang_cont13.leaf28", "abc");
543 params.put("test-yang_cont13.ll9[0]", "abc");
545 InstanceIdentifierContext<?> iCtx = ParserIdentifier
546 .toInstanceIdentifier(uri, context, null);
547 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
548 iCtx.getSchemaNode(), context, uri);
549 PropertiesNode node = ser.encode(params);
551 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
553 assertThat(childNodes.containsKey("cont12"), is(true));
554 SingleInstanceNode cont4 = ((SingleInstanceNode) childNodes.get("cont12"));
555 assertThat(cont4.uri(), is("test-yang:cont13.cont12"));
556 assertThat(cont4.children().containsKey("leaf26"), is(true));
557 LeafNode l = ((LeafNode) cont4.children().get("leaf26"));
558 assertThat(l.uri(), is("test-yang:cont13.cont12.leaf26"));
560 assertThat(childNodes.containsKey("list9"), is(true));
561 HolderNode list6Holder = ((ListHolderNode) childNodes.get("list9"));
562 assertThat(list6Holder.uri(), is("test-yang:cont13.list9"));
563 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
564 assertThat(list6.uri(), is("test-yang:cont13.list9[0]"));
565 Map<String, DataNodeChild> list6Child = list6.children();
566 assertThat(list6Child.containsKey("leaf27"), is(true));
567 l = ((LeafNode) list6Child.get("leaf27"));
568 assertThat(l.uri(), is("test-yang:cont13.list9[0].leaf27"));
570 assertThat(childNodes.containsKey("leaf28"), is(true));
571 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf28"));
572 assertThat(leaf12.name(), is("leaf28"));
573 assertThat(leaf12.uri(), is("test-yang:cont13.leaf28"));
575 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll9"));
576 assertThat(ll5Holder.children().containsKey("0"), is(true));
578 Map<String, String> output = ser.decode(node);
579 assertThat(output.size(), is(params.size()));
580 for (Map.Entry<String, String> entry : output.entrySet()) {
581 assertTrue(params.containsKey(entry.getKey()));
586 public void testGrouping2() throws SvcLogicException {
587 String uri = "test-yang:cont9/cont11";
588 Map<String, String> params = new HashMap<>();
589 params.put("test-yang_cont9.cont11.leaf25", "abc");
590 params.put("test-yang_cont9.cont11.cont13.cont12.leaf26", "abc");
591 params.put("test-yang_cont9.cont11.cont13.list9[0].leaf27", "abc");
592 params.put("test-yang_cont9.cont11.cont13.leaf28", "abc");
593 params.put("test-yang_cont9.cont11.cont13.ll9[0]", "abc");
594 InstanceIdentifierContext<?> iCtx = ParserIdentifier
595 .toInstanceIdentifier(uri, context, null);
596 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
597 iCtx.getSchemaNode(), context, uri);
598 PropertiesNode node = ser.encode(params);
600 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
602 assertThat(childNodes.containsKey("cont13"), is(true));
603 SingleInstanceNode cont13 = ((SingleInstanceNode) childNodes.get("cont13"));
604 assertThat(cont13.uri(), is("test-yang:cont9.cont11.cont13"));
605 SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
606 assertThat(cont12.children().containsKey("leaf26"), is(true));
607 assertThat(cont12.uri(), is("test-yang:cont9.cont11.cont13.cont12"));
608 assertThat(cont12.children().containsKey("leaf26"), is(true));
609 LeafNode l = ((LeafNode) cont12.children().get("leaf26"));
610 assertThat(l.uri(), is("test-yang:cont9.cont11.cont13.cont12.leaf26"));
612 assertThat(cont13.children().containsKey("list9"), is(true));
613 HolderNode list6Holder = ((ListHolderNode) cont13.children().get("list9"));
614 assertThat(list6Holder.uri(), is("test-yang:cont9.cont11.cont13.list9"));
615 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
616 assertThat(list6.uri(), is("test-yang:cont9.cont11.cont13.list9[0]"));
617 Map<String, DataNodeChild> list6Child = list6.children();
618 assertThat(list6Child.containsKey("leaf27"), is(true));
619 l = ((LeafNode) list6Child.get("leaf27"));
620 assertThat(l.uri(), is("test-yang:cont9.cont11.cont13.list9[0].leaf27"));
622 assertThat(cont13.children().containsKey("leaf28"), is(true));
623 LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
624 assertThat(leaf12.name(), is("leaf28"));
625 assertThat(leaf12.uri(), is("test-yang:cont9.cont11.cont13.leaf28"));
627 LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
628 assertThat(ll5Holder.uri(), is("test-yang:cont9.cont11.cont13.ll9"));
629 assertThat(ll5Holder.children().containsKey("0"), is(true));
630 l = ((LeafNode) ll5Holder.children().get("0"));
631 assertThat(l.uri(), is("test-yang:cont9.cont11.cont13.ll9[0]"));
633 Map<String, String> output = ser.decode(node);
634 assertThat(output.size(), is(params.size()));
635 for (Map.Entry<String, String> entry : output.entrySet()) {
636 assertTrue(params.containsKey(entry.getKey()));
641 public void testGrouping3() throws SvcLogicException {
642 String uri = "test-augment:cont13";
643 Map<String, String> params = new HashMap<>();
644 params.put("test-augment_cont13.cont12.leaf26", "abc");
645 params.put("test-augment_cont13.list9[0].leaf27", "abc");
646 params.put("test-augment_cont13.leaf28", "abc");
647 params.put("test-augment_cont13.ll9[0]", "abc");
648 InstanceIdentifierContext<?> iCtx = ParserIdentifier
649 .toInstanceIdentifier(uri, context, null);
650 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
651 iCtx.getSchemaNode(), context, uri);
652 PropertiesNode node = ser.encode(params);
654 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
656 assertThat(childNodes.containsKey("cont12"), is(true));
657 SingleInstanceNode cont12 = ((SingleInstanceNode) childNodes.get("cont12"));
658 assertThat(cont12.uri(), is("test-augment:cont13.cont12"));
659 assertThat(cont12.children().containsKey("leaf26"), is(true));
660 LeafNode l = ((LeafNode) cont12.children().get("leaf26"));
661 assertThat(l.uri(), is("test-augment:cont13.cont12.leaf26"));
663 assertThat(childNodes.containsKey("list9"), is(true));
664 HolderNode list6Holder = ((ListHolderNode) childNodes.get("list9"));
665 assertThat(list6Holder.uri(), is("test-augment:cont13.list9"));
666 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
667 assertThat(list6.uri(), is("test-augment:cont13.list9[0]"));
668 Map<String, DataNodeChild> list6Child = list6.children();
669 assertThat(list6Child.containsKey("leaf27"), is(true));
670 l = ((LeafNode) list6Child.get("leaf27"));
671 assertThat(l.uri(), is("test-augment:cont13.list9[0].leaf27"));
673 assertThat(childNodes.containsKey("leaf28"), is(true));
674 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf28"));
675 assertThat(leaf12.name(), is("leaf28"));
676 assertThat(leaf12.uri(), is("test-augment:cont13.leaf28"));
678 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll9"));
679 assertThat(ll5Holder.uri(), is("test-augment:cont13.ll9"));
680 assertThat(ll5Holder.children().containsKey("0"), is(true));
681 l = ((LeafNode) ll5Holder.children().get("0"));
682 assertThat(l.uri(), is("test-augment:cont13.ll9[0]"));
684 Map<String, String> output = ser.decode(node);
685 assertThat(output.size(), is(params.size()));
686 for (Map.Entry<String, String> entry : output.entrySet()) {
687 assertTrue(params.containsKey(entry.getKey()));
692 public void testGrouping4() throws SvcLogicException {
693 String uri = "test-yang:cont1/cont2/cont4";
694 Map<String, String> params = new HashMap<>();
695 params.put("test-yang_cont1.cont2.cont4.test-augment_cont13.cont12.leaf26", "abc");
696 params.put("test-yang_cont1.cont2.cont4.test-augment_cont13.list9[0].leaf27", "abc");
697 params.put("test-yang_cont1.cont2.cont4.test-augment_cont13.leaf28", "abc");
698 params.put("test-yang_cont1.cont2.cont4.test-augment_cont13.ll9[0]", "abc");
700 InstanceIdentifierContext<?> iCtx = ParserIdentifier
701 .toInstanceIdentifier(uri, context, null);
702 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
703 iCtx.getSchemaNode(), context, uri);
704 PropertiesNode node = ser.encode(params);
706 for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
707 : node.augmentations().asMap().entrySet()) {
708 Collection<PropertiesNode> child = augToChild.getValue();
709 if (!child.isEmpty()) {
710 List<String> expectedNodes = new LinkedList<>();
711 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:cont13");
712 assertThat(expectedNodes.size(), is(child.size()));
713 for (PropertiesNode pNode : child) {
714 assertThat(expectedNodes.contains(pNode.uri()), is(true));
715 SingleInstanceNode cont13 = ((SingleInstanceNode) pNode);
716 assertThat(cont13.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13"));
717 SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
718 assertThat(cont12.children().containsKey("leaf26"), is(true));
719 LeafNode l = ((LeafNode) cont12.children().get("leaf26"));
720 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.cont12.leaf26"));
722 assertThat(cont13.children().containsKey("list9"), is(true));
723 HolderNode list6Holder = ((ListHolderNode) cont13.children().get("list9"));
724 assertThat(list6Holder.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.list9"));
725 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
726 assertThat(list6.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.list9[0]"));
727 Map<String, DataNodeChild> list6Child = list6.children();
728 assertThat(list6Child.containsKey("leaf27"), is(true));
729 l = ((LeafNode) list6Child.get("leaf27"));
730 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.list9[0].leaf27"));
732 assertThat(cont13.children().containsKey("leaf28"), is(true));
733 LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
734 assertThat(leaf12.name(), is("leaf28"));
735 assertThat(leaf12.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.leaf28"));
737 LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
738 assertThat(ll5Holder.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.ll9"));
739 assertThat(ll5Holder.children().containsKey("0"), is(true));
740 l = ((LeafNode) ll5Holder.children().get("0"));
741 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.ll9[0]"));
746 Map<String, String> output = ser.decode(node);
747 assertThat(output.size(), is(params.size()));
748 for (Map.Entry<String, String> entry : output.entrySet()) {
749 assertTrue(params.containsKey(entry.getKey()));
754 public void testRpcInput() throws SvcLogicException {
755 String uri = "test-yang:create-sfc";
756 Map<String, String> params = new HashMap<>();
757 params.put("test-yang_create-sfc.input.cont14.leaf28", "abc");
758 params.put("test-yang_create-sfc.input.list10[0].leaf29", "abc");
759 params.put("test-yang_create-sfc.input.leaf30", "abc");
760 params.put("test-yang_create-sfc.input.ll10[0]", "abc");
761 params.put("test-yang_create-sfc.input.cont15.leaf31", "abc");
762 params.put("test-yang_create-sfc.input.cont13.cont12.leaf26", "abc");
763 params.put("test-yang_create-sfc.input.cont13.list9[0].leaf27", "abc");
764 params.put("test-yang_create-sfc.input.cont13.leaf28", "abc");
765 params.put("test-yang_create-sfc.input.cont13.ll9[0]", "abc");
766 params.put("test-yang_create-sfc.input.test-augment_leaf36", "abc");
768 InstanceIdentifierContext<?> iCtx = ParserIdentifier
769 .toInstanceIdentifier(uri, context, null);
770 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
771 iCtx.getSchemaNode(), context, uri);
772 PropertiesNode node = ser.encode(params);
774 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
776 PropertiesNode input = childNodes.get("input");
777 assertThat(input.uri(), is("test-yang:create-sfc.input"));
778 for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
779 : node.augmentations().asMap().entrySet()) {
780 Collection<PropertiesNode> child = augToChild.getValue();
781 if (!child.isEmpty()) {
782 List<String> expectedNodes = new LinkedList<>();
783 expectedNodes.add("test-yang:create-sfc.input.test-augment:leaf36");
784 assertThat(expectedNodes.size(), is(child.size()));
785 for (PropertiesNode pNode : child) {
786 assertThat(expectedNodes.contains(pNode.uri()), is(true));
787 LeafNode leaf37 = ((LeafNode) pNode);
788 assertThat(leaf37.name(), is("leaf36"));
789 assertThat(leaf37.uri(), is("test-yang:create-sfc.input.test-augment:leaf36"));
793 childNodes = ((InnerNode) input).children();
795 assertThat(childNodes.containsKey("cont14"), is(true));
796 SingleInstanceNode cont14 = ((SingleInstanceNode) childNodes.get("cont14"));
797 assertThat(cont14.uri(), is("test-yang:create-sfc.input.cont14"));
798 assertThat(cont14.children().containsKey("leaf28"), is(true));
799 LeafNode l = ((LeafNode) cont14.children().get("leaf28"));
800 assertThat(l.uri(), is("test-yang:create-sfc.input.cont14.leaf28"));
802 assertThat(childNodes.containsKey("list10"), is(true));
803 HolderNode list10Holder = ((ListHolderNode) childNodes.get("list10"));
804 assertThat(list10Holder.uri(), is("test-yang:create-sfc.input.list10"));
805 MultiInstanceNode list10 = ((MultiInstanceNode) list10Holder.child("0"));
806 assertThat(list10.uri(), is("test-yang:create-sfc.input.list10[0]"));
807 Map<String, DataNodeChild> list10Child = list10.children();
808 assertThat(list10Child.containsKey("leaf29"), is(true));
809 l = ((LeafNode) list10Child.get("leaf29"));
810 assertThat(l.uri(), is("test-yang:create-sfc.input.list10[0].leaf29"));
812 assertThat(childNodes.containsKey("leaf30"), is(true));
813 LeafNode leaf30 = ((LeafNode) childNodes.get("leaf30"));
814 assertThat(leaf30.name(), is("leaf30"));
815 assertThat(leaf30.uri(), is("test-yang:create-sfc.input.leaf30"));
817 LeafListHolderNode ll10Holder = ((LeafListHolderNode) childNodes.get("ll10"));
818 assertThat(ll10Holder.uri(), is("test-yang:create-sfc.input.ll10"));
819 assertThat(ll10Holder.children().containsKey("0"), is(true));
820 l = ((LeafNode) ll10Holder.children().get("0"));
821 assertThat(l.uri(), is("test-yang:create-sfc.input.ll10[0]"));
823 assertThat(childNodes.containsKey("cont15"), is(true));
824 SingleInstanceNode cont15 = ((SingleInstanceNode) childNodes.get("cont15"));
825 assertThat(cont15.uri(), is("test-yang:create-sfc.input.cont15"));
826 assertThat(cont15.children().containsKey("leaf31"), is(true));
827 l = ((LeafNode) cont15.children().get("leaf31"));
828 assertThat(l.uri(), is("test-yang:create-sfc.input.cont15.leaf31"));
830 assertThat(childNodes.containsKey("cont13"), is(true));
831 SingleInstanceNode cont13 = ((SingleInstanceNode) childNodes.get("cont13"));
832 assertThat(cont13.uri(), is("test-yang:create-sfc.input.cont13"));
833 SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
834 assertThat(cont12.uri(), is("test-yang:create-sfc.input.cont13.cont12"));
835 assertThat(cont12.children().containsKey("leaf26"), is(true));
836 l = ((LeafNode) cont12.children().get("leaf26"));
837 assertThat(l.uri(), is("test-yang:create-sfc.input.cont13.cont12.leaf26"));
839 assertThat(cont13.children().containsKey("list9"), is(true));
840 HolderNode list9Holder = ((ListHolderNode) cont13.children().get("list9"));
841 assertThat(list9Holder.uri(), is("test-yang:create-sfc.input.cont13.list9"));
842 MultiInstanceNode list9 = ((MultiInstanceNode) list9Holder.child("0"));
843 assertThat(list9.uri(), is("test-yang:create-sfc.input.cont13.list9[0]"));
844 Map<String, DataNodeChild> list6Child = list9.children();
845 assertThat(list6Child.containsKey("leaf27"), is(true));
846 l = ((LeafNode) list6Child.get("leaf27"));
847 assertThat(l.uri(), is("test-yang:create-sfc.input.cont13.list9[0].leaf27"));
849 assertThat(cont13.children().containsKey("leaf28"), is(true));
850 LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
851 assertThat(leaf12.name(), is("leaf28"));
852 assertThat(leaf12.uri(), is("test-yang:create-sfc.input.cont13.leaf28"));
854 LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
855 assertThat(ll5Holder.uri(), is("test-yang:create-sfc.input.cont13.ll9"));
856 assertThat(ll5Holder.children().containsKey("0"), is(true));
857 l = ((LeafNode) ll5Holder.children().get("0"));
858 assertThat(l.uri(), is("test-yang:create-sfc.input.cont13.ll9[0]"));
860 Map<String, String> output = ser.decode(node);
861 assertThat(output.size(), is(params.size()));
862 for (Map.Entry<String, String> entry : output.entrySet()) {
863 assertTrue(params.containsKey(entry.getKey()));
868 public void testRpcOutput() throws SvcLogicException {
869 String uri = "test-yang:create-sfc";
870 Map<String, String> params = new HashMap<>();
871 params.put("test-yang_create-sfc.output.cont16.leaf32", "abc");
872 params.put("test-yang_create-sfc.output.list11[0].leaf33", "abc");
873 params.put("test-yang_create-sfc.output.leaf34", "abc");
874 params.put("test-yang_create-sfc.output.ll11[0]", "abc");
875 params.put("test-yang_create-sfc.output.cont17.leaf35", "abc");
876 params.put("test-yang_create-sfc.output.cont13.cont12.leaf26", "abc");
877 params.put("test-yang_create-sfc.output.cont13.list9[0].leaf27", "abc");
878 params.put("test-yang_create-sfc.output.cont13.leaf28", "abc");
879 params.put("test-yang_create-sfc.output.cont13.ll9[0]", "abc");
880 params.put("test-yang_create-sfc.output.test-augment_leaf37", "abc");
882 InstanceIdentifierContext<?> iCtx = ParserIdentifier
883 .toInstanceIdentifier(uri, context, null);
884 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
885 iCtx.getSchemaNode(), context, uri);
886 PropertiesNode node = ser.encode(params);
888 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
890 PropertiesNode output = childNodes.get("output");
891 assertThat(output.uri(), is("test-yang:create-sfc.output"));
892 for (Map.Entry<Object, Collection<PropertiesNode>> augmentationToChild :
893 node.augmentations().asMap().entrySet()) {
894 Collection<PropertiesNode> c = augmentationToChild.getValue();
896 List<String> expectedNodes = new LinkedList<>();
897 expectedNodes.add("test-yang:create-sfc.output.test-augment:leaf37");
898 assertThat(expectedNodes.size(), is(expectedNodes));
899 for (PropertiesNode pNode : c) {
900 assertThat(expectedNodes.contains(pNode.uri()), is(true));
901 LeafNode leaf37 = ((LeafNode) pNode);
902 assertThat(leaf37.name(), is("leaf37"));
903 assertThat(leaf37.uri(), is("test-yang:create-sfc.output.test-augment:leaf37"));
907 childNodes = ((InnerNode) output).children();
909 assertThat(childNodes.containsKey("cont16"), is(true));
910 SingleInstanceNode cont16 = ((SingleInstanceNode) childNodes.get("cont16"));
911 assertThat(cont16.uri(), is("test-yang:create-sfc.output.cont16"));
912 assertThat(cont16.children().containsKey("leaf32"), is(true));
913 LeafNode l = ((LeafNode) cont16.children().get("leaf32"));
914 assertThat(l.uri(), is("test-yang:create-sfc.output.cont16.leaf32"));
916 assertThat(childNodes.containsKey("list11"), is(true));
917 HolderNode list11Holder = ((ListHolderNode) childNodes.get("list11"));
918 assertThat(list11Holder.uri(), is("test-yang:create-sfc.output.list11"));
919 MultiInstanceNode list11 = ((MultiInstanceNode) list11Holder.child("0"));
920 assertThat(list11.uri(), is("test-yang:create-sfc.output.list11[0]"));
921 Map<String, DataNodeChild> list11Child = list11.children();
922 assertThat(list11Child.containsKey("leaf33"), is(true));
923 l = ((LeafNode) list11Child.get("leaf33"));
924 assertThat(l.uri(), is("test-yang:create-sfc.output.list11[0].leaf33"));
926 assertThat(childNodes.containsKey("leaf34"), is(true));
927 LeafNode leaf34 = ((LeafNode) childNodes.get("leaf34"));
928 assertThat(leaf34.name(), is("leaf34"));
929 assertThat(leaf34.uri(), is("test-yang:create-sfc.output.leaf34"));
931 LeafListHolderNode ll10Holder = ((LeafListHolderNode) childNodes.get("ll11"));
932 assertThat(ll10Holder.uri(), is("test-yang:create-sfc.output.ll11"));
933 assertThat(ll10Holder.children().containsKey("0"), is(true));
934 l = ((LeafNode) ll10Holder.children().get("0"));
935 assertThat(l.uri(), is("test-yang:create-sfc.output.ll11[0]"));
937 assertThat(childNodes.containsKey("cont17"), is(true));
938 SingleInstanceNode cont17 = ((SingleInstanceNode) childNodes.get("cont17"));
939 assertThat(cont17.uri(), is("test-yang:create-sfc.output.cont17"));
940 assertThat(cont17.children().containsKey("leaf35"), is(true));
941 l = ((LeafNode) cont17.children().get("leaf35"));
942 assertThat(l.uri(), is("test-yang:create-sfc.output.cont17.leaf35"));
944 assertThat(childNodes.containsKey("cont13"), is(true));
945 SingleInstanceNode cont13 = ((SingleInstanceNode) childNodes.get("cont13"));
946 assertThat(cont13.uri(), is("test-yang:create-sfc.output.cont13"));
947 SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
948 assertThat(cont12.uri(), is("test-yang:create-sfc.output.cont13.cont12"));
949 assertThat(cont12.children().containsKey("leaf26"), is(true));
950 l = ((LeafNode) cont12.children().get("leaf26"));
951 assertThat(l.uri(), is("test-yang:create-sfc.output.cont13.cont12.leaf26"));
953 assertThat(cont13.children().containsKey("list9"), is(true));
954 HolderNode list9Holder = ((ListHolderNode) cont13.children().get("list9"));
955 assertThat(list9Holder.uri(), is("test-yang:create-sfc.output.cont13.list9"));
956 MultiInstanceNode list9 = ((MultiInstanceNode) list9Holder.child("0"));
957 assertThat(list9.uri(), is("test-yang:create-sfc.output.cont13.list9[0]"));
958 Map<String, DataNodeChild> list6Child = list9.children();
959 assertThat(list6Child.containsKey("leaf27"), is(true));
960 l = ((LeafNode) list6Child.get("leaf27"));
961 assertThat(l.uri(), is("test-yang:create-sfc.output.cont13.list9[0].leaf27"));
963 assertThat(cont13.children().containsKey("leaf28"), is(true));
964 LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
965 assertThat(leaf12.name(), is("leaf28"));
966 assertThat(leaf12.uri(), is("test-yang:create-sfc.output.cont13.leaf28"));
968 LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
969 assertThat(ll5Holder.uri(), is("test-yang:create-sfc.output.cont13.ll9"));
970 assertThat(ll5Holder.children().containsKey("0"), is(true));
971 l = ((LeafNode) ll5Holder.children().get("0"));
972 assertThat(l.uri(), is("test-yang:create-sfc.output.cont13.ll9[0]"));
974 Map<String, String> output1 = ser.decode(node);
975 assertThat(output1.size(), is(params.size()));
976 for (Map.Entry<String, String> entry : output1.entrySet()) {
977 assertTrue(params.containsKey(entry.getKey()));
982 public void testContainerSameName() throws SvcLogicException {
983 String uri = "test-yang:cont18";
984 Map<String, String> params = new HashMap<>();
985 params.put("test-yang_cont18.cont18.list12[0].list12[0].leaf36", "abc");
986 params.put("test-yang_cont18.cont18.list12[0].leaf36", "hi");
987 params.put("test-yang_cont18.cont18.list12[1].list12[0].leaf36", "xyz");
988 params.put("test-yang_cont18.cont18.list12[1].list12[1].leaf36", "hey!");
990 InstanceIdentifierContext<?> iCtx = ParserIdentifier
991 .toInstanceIdentifier(uri, context, null);
992 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
993 iCtx.getSchemaNode(), context, uri);
994 PropertiesNode node = ser.encode(params);
996 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
998 assertThat(childNodes.containsKey("cont18"), is(true));
999 node = childNodes.get("cont18");
1000 assertThat(node.uri(), is("test-yang:cont18.cont18"));
1001 childNodes = ((InnerNode) node).children();
1003 assertThat(childNodes.containsKey("list12"), is(true));
1004 HolderNode holder = ((ListHolderNode) childNodes.get("list12"));
1005 assertThat(holder.uri(), is("test-yang:cont18.cont18.list12"));
1006 MultiInstanceNode node1 = ((MultiInstanceNode) holder.child("0"));
1007 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[0]"));
1008 Map<String, DataNodeChild> list12Child = node1.children();
1010 assertThat(list12Child.containsKey("leaf36"), is(true));
1011 LeafNode leaf = ((LeafNode) list12Child.get("leaf36"));
1012 assertThat(leaf.value(), is("hi"));
1013 assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[0].leaf36"));
1015 assertThat(list12Child.containsKey("list12"), is(true));
1016 HolderNode holder1 = ((ListHolderNode) list12Child.get("list12"));
1017 assertThat(holder1.uri(), is("test-yang:cont18.cont18.list12[0].list12"));
1018 node1 = ((MultiInstanceNode) holder1.child("0"));
1019 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[0].list12[0]"));
1020 list12Child = node1.children();
1021 assertThat(list12Child.containsKey("leaf36"), is(true));
1022 leaf = ((LeafNode) list12Child.get("leaf36"));
1023 assertThat(leaf.value(), is("abc"));
1024 assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[0].list12[0].leaf36"));
1026 node1 = ((MultiInstanceNode) holder.child("1"));
1027 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[1]"));
1028 list12Child = node1.children();
1029 assertThat(list12Child.containsKey("list12"), is(true));
1030 holder = ((ListHolderNode) list12Child.get("list12"));
1031 assertThat(holder.uri(), is("test-yang:cont18.cont18.list12[1].list12"));
1032 node1 = ((MultiInstanceNode) holder.child("0"));
1033 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[1].list12[0]"));
1034 assertThat(node1.children().containsKey("leaf36"), is(true));
1035 leaf = ((LeafNode) node1.children().get("leaf36"));
1036 assertThat(leaf.value(), is("xyz"));
1037 assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[1].list12[0].leaf36"));
1039 node1 = ((MultiInstanceNode) holder.child("1"));
1040 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[1].list12[1]"));
1041 assertThat(node1.children().containsKey("leaf36"), is(true));
1042 leaf = ((LeafNode) node1.children().get("leaf36"));
1043 assertThat(leaf.value(), is("hey!"));
1044 assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[1].list12[1].leaf36"));
1046 Map<String, String> output1 = ser.decode(node);
1047 assertThat(output1.size(), is(params.size()));
1048 for (Map.Entry<String, String> entry : output1.entrySet()) {
1049 assertTrue(params.containsKey(entry.getKey()));
1054 public void testPropertiesWithoutSchema() throws SvcLogicException {
1055 String uri = "test-yang:cont18";
1056 Map<String, String> params = new HashMap<>();
1057 params.put("test-yang_cont18.leaf40", "abc");
1058 params.put("leaf41", "hi");
1059 params.put("test-yang_cont18.leaf41", "abc");
1061 InstanceIdentifierContext<?> iCtx = ParserIdentifier
1062 .toInstanceIdentifier(uri, context, null);
1063 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
1064 iCtx.getSchemaNode(), context, uri);
1065 PropertiesNode node = ser.encode(params);
1067 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
1068 assertThat(childNodes.containsKey("leaf40"), is(true));
1069 node = childNodes.get("leaf40");
1070 assertThat(node.uri(), is("test-yang:cont18.leaf40"));
1074 public void testIdentityRef() throws SvcLogicException {
1075 String uri = "identity-test:test";
1076 Map<String, String> params = new HashMap<>();
1077 params.put("identity-test_test.con1.interface", "identity-types" +
1079 params.put("identity-test_test.con1.interfaces.int-list[0].iden", "identity-test:Giga");
1080 params.put("identity-test_test.con1.interfaces.int-list[0].available.ll[0]", "identity-types:Loopback");
1081 params.put("identity-test_test.con1.interfaces.int-list[0].available.leaf1", "identity-types-second:Ethernet");
1082 params.put("identity-test_test.con1.interfaces.int-list[0].available.leaf2", "identity-types-second:iden2");
1083 InstanceIdentifierContext<?> iCtx = ParserIdentifier
1084 .toInstanceIdentifier(uri, context, null);
1086 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
1087 iCtx.getSchemaNode(), context, uri);
1088 PropertiesNode node = ser.encode(params);
1089 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
1090 assertThat(childNodes.containsKey("con1"), is(true));
1091 node = childNodes.get("con1");
1092 assertThat(node.uri(), is("identity-test:test.con1"));
1093 LeafNode l = ((LeafNode) ((SingleInstanceNode) node).children().get("interface"));
1094 assertThat(l.uri(), is("identity-test:test.con1.interface"));
1095 assertThat(l.valueNs().moduleName(), is("identity-types"));
1096 assertThat(l.valueNs().moduleNs().toString(), is("identity:list:ns:test:json:ser"));
1098 // identity type inside union
1099 node = ((SingleInstanceNode) ((SingleInstanceNode) node).children().get("interfaces"));
1100 node = ((ListHolderNode) ((SingleInstanceNode) node).children().get("int-list"));
1101 node = ((MultiInstanceNode) ((ListHolderNode) node).children().get("0"));
1102 l = ((LeafNode) ((MultiInstanceNode) node).children().get("iden"));
1103 assertThat(l.uri(), is("identity-test:test.con1.interfaces.int-list[0].iden"));
1104 assertThat(l.valueNs().moduleName(), is("identity-test"));
1105 assertThat(l.valueNs().moduleNs().toString(), is("identity:ns:test:json:ser"));
1108 node = (SingleInstanceNode) ((MultiInstanceNode) node).children().get("available");
1109 LeafListHolderNode holder = (LeafListHolderNode) ((SingleInstanceNode) node).children().get("ll");
1110 l = ((LeafNode) holder.children().get("0"));
1111 assertThat(l.uri(), is("identity-test:test.con1.interfaces.int-list[0].available.ll[0]"));
1112 assertThat(l.valueNs().moduleName(), is("identity-types"));
1113 assertThat(l.valueNs().moduleNs().toString(), is("identity:list:ns:test:json:ser"));
1116 l = ((LeafNode) ((SingleInstanceNode) node).children().get("leaf1"));
1117 assertThat(l.uri(), is("identity-test:test.con1.interfaces.int-list[0].available.leaf1"));
1118 assertThat(l.valueNs().moduleName(), is("identity-types-second"));
1119 assertThat(l.valueNs().moduleNs().toString(), is("identity:list:second:ns:test:json:ser"));
1121 // list of base identity test
1122 l = ((LeafNode) ((SingleInstanceNode) node).children().get("leaf2"));
1123 assertThat(l.uri(), is("identity-test:test.con1.interfaces.int-list[0].available.leaf2"));
1124 assertThat(l.valueNs().moduleName(), is("identity-types-second"));
1125 assertThat(l.valueNs().moduleNs().toString(), is("identity:list:second:ns:test:json:ser"));
1128 public static SchemaContext compileYangFile() throws FileNotFoundException {
1129 String path = PropertiesSerializerTest.class.getResource("/yang").getPath();
1130 File dir = new File(path);
1131 String[] fileList = dir.list();
1132 List<File> yangFiles = new ArrayList<File>();
1133 if (fileList == null) {
1134 throw new FileNotFoundException("/yang");
1136 for (int i = 0; i < fileList.length; i++) {
1137 final String fileName = fileList[i];
1138 if (new File(dir, fileName).isDirectory() == false) {
1139 yangFiles.add(new File(dir, fileName));
1142 return YangParserTestUtils.parseYangFiles(yangFiles);