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;
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.is;
24 import static org.junit.Assert.assertTrue;
26 import java.io.FileNotFoundException;
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.HashMap;
30 import java.util.LinkedList;
31 import java.util.List;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
36 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
37 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
38 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
39 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
41 public final class PropertiesSerializerTest {
42 private EffectiveModelContext context;
45 public void initialization() throws FileNotFoundException {
46 context = compileYangFile();
50 public void testBasicConstructs() throws SvcLogicException {
51 String uri = "test-yang:cont1/cont2";
52 Map<String, String> params = new HashMap<>();
53 params.put("test-yang_cont1.cont2.cont3.leaf10", "abc");
54 params.put("test-yang_cont1.cont2.list1[0].leaf1", "abc");
55 params.put("test-yang_cont1.cont2.list1[0].leaf2", "abc");
56 params.put("test-yang_cont1.cont2.list1[0].leaf3", "abc");
57 params.put("test-yang_cont1.cont2.list1[0].ll1[0]", "abc");
58 params.put("test-yang_cont1.cont2.list1[0].ll1[1]", "abc");
59 params.put("test-yang_cont1.cont2.list1[0].ll2[0]", "abc");
60 params.put("test-yang_cont1.cont2.list1[0].ll2[1]", "abc");
61 params.put("test-yang_cont1.cont2.list1[0].cont4.leaf11", "abc");
62 params.put("test-yang_cont1.cont2.list1[0].list4[0].leaf8", "abc");
63 params.put("test-yang_cont1.cont2.list1[0].list4[1].leaf8", "abc");
64 params.put("test-yang_cont1.cont2.list1[0].list5[0].leaf9", "abc");
65 params.put("test-yang_cont1.cont2.list1[0].list5[1].leaf9", "abc");
66 params.put("test-yang_cont1.cont2.list1[1].leaf1", "abc");
67 params.put("test-yang_cont1.cont2.list1[1].leaf2", "abc");
68 params.put("test-yang_cont1.cont2.list1[1].leaf3", "abc");
69 params.put("test-yang_cont1.cont2.list1[1].ll1[0]", "abc");
70 params.put("test-yang_cont1.cont2.list1[1].ll1[1]", "abc");
71 params.put("test-yang_cont1.cont2.list1[1].ll2[0]", "abc");
72 params.put("test-yang_cont1.cont2.list1[1].ll2[1]", "abc");
73 params.put("test-yang_cont1.cont2.list1[1].cont4.leaf11", "abc");
74 params.put("test-yang_cont1.cont2.list1[1].list4[0].leaf8", "abc");
75 params.put("test-yang_cont1.cont2.list1[1].list4[1].leaf8", "abc");
76 params.put("test-yang_cont1.cont2.list1[1].list5[0].leaf9", "abc");
77 params.put("test-yang_cont1.cont2.list1[1].list5[1].leaf9", "abc");
78 params.put("test-yang_cont1.cont2.list2[0].leaf4", "abc");
79 params.put("test-yang_cont1.cont2.list2[1].leaf4", "abc");
80 params.put("test-yang_cont1.cont2.leaf5", "abc");
81 params.put("test-yang_cont1.cont2.leaf6", "abc");
82 params.put("test-yang_cont1.cont2.ll3[0]", "abc");
83 params.put("test-yang_cont1.cont2.ll3[1]", "abc");
84 params.put("test-yang_cont1.cont2.ll4[0]", "abc");
85 params.put("test-yang_cont1.cont2.ll4[1]", "abc");
86 InstanceIdentifierContext<?> iCtx = ParserIdentifier
87 .toInstanceIdentifier(uri, context, null);
89 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
90 iCtx.getSchemaNode(), context, uri);
91 PropertiesNode node = ser.encode(params);
93 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
95 assertThat(childNodes.containsKey("cont3"), is(true));
96 SingleInstanceNode cont3 = ((SingleInstanceNode) childNodes.get("cont3"));
97 assertThat(cont3.uri(), is("test-yang:cont1.cont2.cont3"));
98 assertThat(cont3.children().containsKey("leaf10"), is(true));
100 assertThat(childNodes.containsKey("list1"), is(true));
101 HolderNode list1Holder = ((ListHolderNode) childNodes.get("list1"));
102 assertThat(list1Holder.uri(), is("test-yang:cont1.cont2.list1"));
103 MultiInstanceNode list10 = ((MultiInstanceNode) list1Holder.child("0"));
104 assertThat(list10.uri(), is("test-yang:cont1.cont2.list1[0]"));
105 Map<String, DataNodeChild> list10Child = list10.children();
106 assertThat(list10Child.containsKey("leaf1"), is(true));
107 LeafNode l = ((LeafNode) list10Child.get("leaf1"));
108 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].leaf1"));
109 assertThat(list10Child.containsKey("leaf2"), is(true));
110 l = ((LeafNode) list10Child.get("leaf2"));
111 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].leaf2"));
112 assertThat(list10Child.containsKey("leaf2"), is(true));
113 l = ((LeafNode) list10Child.get("leaf3"));
114 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].leaf3"));
116 LeafListHolderNode ll1Holder = ((LeafListHolderNode) list10Child.get("ll1"));
117 assertThat(ll1Holder.uri(), is("test-yang:cont1.cont2.list1[0].ll1"));
118 assertThat(ll1Holder.children().containsKey("0"), is(true));
119 l = ((LeafNode) ll1Holder.child("0"));
120 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll1[0]"));
121 assertThat(ll1Holder.children().containsKey("1"), is(true));
122 l = ((LeafNode) ll1Holder.child("1"));
123 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll1[1]"));
125 LeafListHolderNode ll2Holder = ((LeafListHolderNode) list10Child.get("ll2"));
126 assertThat(ll2Holder.uri(), is("test-yang:cont1.cont2.list1[0].ll2"));
127 assertThat(ll2Holder.children().containsKey("0"), is(true));
128 l = ((LeafNode) ll2Holder.child("0"));
129 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll2[0]"));
130 assertThat(ll2Holder.children().containsKey("1"), is(true));
131 l = ((LeafNode) ll2Holder.child("1"));
132 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll2[1]"));
134 SingleInstanceNode cont4 = ((SingleInstanceNode) list10Child.get("cont4"));
135 assertThat(cont4.uri(), is("test-yang:cont1.cont2.list1[0].cont4"));
136 assertThat(cont4.children().containsKey("leaf11"), is(true));
137 l = ((LeafNode) cont4.children().get("leaf11"));
138 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].cont4.leaf11"));
140 HolderNode list4Holder = ((HolderNode) list10Child.get("list4"));
141 assertThat(list4Holder.uri(), is("test-yang:cont1.cont2.list1[0].list4"));
142 Map<String, PropertiesNode> c = list4Holder.children();
143 MultiInstanceNode list40 = ((MultiInstanceNode) c.get("0"));
144 assertThat(list40.uri(), is("test-yang:cont1.cont2.list1[0].list4[0]"));
145 assertThat(list40.children().containsKey("leaf8"), is(true));
146 l = ((LeafNode) list40.children().get("leaf8"));
147 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list4[0].leaf8"));
148 MultiInstanceNode list41 = ((MultiInstanceNode) c.get("1"));
149 assertThat(list41.uri(), is("test-yang:cont1.cont2.list1[0].list4[1]"));
150 assertThat(list41.children().containsKey("leaf8"), is(true));
151 l = ((LeafNode) list41.children().get("leaf8"));
152 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list4[1].leaf8"));
154 HolderNode list5Holder = ((HolderNode) list10Child.get("list5"));
155 assertThat(list5Holder.uri(), is("test-yang:cont1.cont2.list1[0].list5"));
156 c = list5Holder.children();
157 MultiInstanceNode list50 = ((MultiInstanceNode) c.get("0"));
158 assertThat(list50.uri(), is("test-yang:cont1.cont2.list1[0].list5[0]"));
159 assertThat(list50.children().containsKey("leaf9"), is(true));
160 l = ((LeafNode) list50.children().get("leaf9"));
161 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list5[0].leaf9"));
162 MultiInstanceNode list51 = ((MultiInstanceNode) c.get("1"));
163 assertThat(list51.uri(), is("test-yang:cont1.cont2.list1[0].list5[1]"));
164 assertThat(list51.children().containsKey("leaf9"), is(true));
165 l = ((LeafNode) list51.children().get("leaf9"));
166 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list5[1].leaf9"));
168 MultiInstanceNode list11 = ((MultiInstanceNode) list1Holder.child("1"));
169 assertThat(list11.uri(), is("test-yang:cont1.cont2.list1[1]"));
170 Map<String, DataNodeChild> list11Child = list11.children();
171 assertThat(list11Child.containsKey("leaf1"), is(true));
172 l = ((LeafNode) list11Child.get("leaf1"));
173 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].leaf1"));
174 assertThat(list11Child.containsKey("leaf2"), is(true));
175 l = ((LeafNode) list11Child.get("leaf2"));
176 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].leaf2"));
177 assertThat(list11Child.containsKey("leaf3"), is(true));
178 l = ((LeafNode) list11Child.get("leaf3"));
179 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].leaf3"));
181 ll1Holder = ((LeafListHolderNode) list11Child.get("ll1"));
182 assertThat(ll1Holder.uri(), is("test-yang:cont1.cont2.list1[1].ll1"));
183 assertThat(ll1Holder.children().containsKey("0"), is(true));
184 l = ((LeafNode) ll1Holder.children().get("0"));
185 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll1[0]"));
186 assertThat(ll1Holder.children().containsKey("1"), is(true));
187 l = ((LeafNode) ll1Holder.children().get("1"));
188 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll1[1]"));
190 ll2Holder = ((LeafListHolderNode) list11Child.get("ll2"));
191 assertThat(ll2Holder.uri(), is("test-yang:cont1.cont2.list1[1].ll2"));
192 assertThat(ll2Holder.children().containsKey("0"), is(true));
193 l = ((LeafNode) ll2Holder.children().get("0"));
194 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll2[0]"));
195 assertThat(ll2Holder.children().containsKey("1"), is(true));
196 l = ((LeafNode) ll2Holder.children().get("1"));
197 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll2[1]"));
199 cont4 = ((SingleInstanceNode) list11Child.get("cont4"));
200 assertThat(cont4.uri(), is("test-yang:cont1.cont2.list1[1].cont4"));
201 assertThat(cont4.children().containsKey("leaf11"), is(true));
202 l = ((LeafNode) cont4.children().get("leaf11"));
203 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].cont4.leaf11"));
205 list4Holder = ((HolderNode) list11Child.get("list4"));
206 assertThat(list4Holder.uri(), is("test-yang:cont1.cont2.list1[1].list4"));
207 c = list4Holder.children();
208 list40 = ((MultiInstanceNode) c.get("0"));
209 assertThat(list40.uri(), is("test-yang:cont1.cont2.list1[1].list4[0]"));
210 assertThat(list40.children().containsKey("leaf8"), is(true));
211 l = ((LeafNode) list40.children().get("leaf8"));
212 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list4[0].leaf8"));
213 list41 = ((MultiInstanceNode) c.get("1"));
214 assertThat(list41.uri(), is("test-yang:cont1.cont2.list1[1].list4[1]"));
215 assertThat(list41.children().containsKey("leaf8"), is(true));
216 l = ((LeafNode) list41.children().get("leaf8"));
217 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list4[1].leaf8"));
219 list5Holder = ((HolderNode) list11Child.get("list5"));
220 assertThat(list5Holder.uri(), is("test-yang:cont1.cont2.list1[1].list5"));
221 c = list5Holder.children();
222 list50 = ((MultiInstanceNode) c.get("0"));
223 assertThat(list50.uri(), is("test-yang:cont1.cont2.list1[1].list5[0]"));
224 assertThat(list50.children().containsKey("leaf9"), is(true));
225 l = ((LeafNode) list50.children().get("leaf9"));
226 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list5[0].leaf9"));
227 list51 = ((MultiInstanceNode) c.get("1"));
228 assertThat(list51.uri(), is("test-yang:cont1.cont2.list1[1].list5[1]"));
229 assertThat(list51.children().containsKey("leaf9"), is(true));
230 l = ((LeafNode) list51.children().get("leaf9"));
231 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list5[1].leaf9"));
233 assertThat(childNodes.containsKey("list2"), is(true));
234 HolderNode list2Holder = ((HolderNode) childNodes.get("list2"));
235 assertThat(list2Holder.uri(), is("test-yang:cont1.cont2.list2"));
236 InnerNode list20 = ((InnerNode) list2Holder.children().get("0"));
237 assertThat(list20.uri(), is("test-yang:cont1.cont2.list2[0]"));
238 assertThat(list20.children().containsKey("leaf4"), is(true));
239 l = ((LeafNode) list20.children().get("leaf4"));
240 assertThat(l.uri(), is("test-yang:cont1.cont2.list2[0].leaf4"));
241 InnerNode list21 = ((InnerNode) list2Holder.children().get("1"));
242 assertThat(list21.uri(), is("test-yang:cont1.cont2.list2[1]"));
243 assertThat(list21.children().containsKey("leaf4"), is(true));
244 l = ((LeafNode) list21.children().get("leaf4"));
245 assertThat(l.uri(), is("test-yang:cont1.cont2.list2[1].leaf4"));
247 assertThat(childNodes.containsKey("leaf5"), is(true));
248 l = ((LeafNode) childNodes.get("leaf5"));
249 assertThat(l.uri(), is("test-yang:cont1.cont2.leaf5"));
250 assertThat(childNodes.containsKey("leaf6"), is(true));
251 l = ((LeafNode) childNodes.get("leaf6"));
252 assertThat(l.uri(), is("test-yang:cont1.cont2.leaf6"));
254 HolderNode ll3Holder = ((HolderNode) childNodes.get("ll3"));
255 assertThat(ll3Holder.uri(), is("test-yang:cont1.cont2.ll3"));
256 assertThat(((LeafNode) ll3Holder.children().get("0")).name(), is("ll3"));
257 l = ((LeafNode) ll3Holder.children().get("0"));
258 assertThat(l.uri(), is("test-yang:cont1.cont2.ll3[0]"));
259 assertThat(((LeafNode) ll3Holder.children().get("1")).name(), is("ll3"));
260 l = ((LeafNode) ll3Holder.children().get("1"));
261 assertThat(l.uri(), is("test-yang:cont1.cont2.ll3[1]"));
263 HolderNode ll4Holder = ((HolderNode) childNodes.get("ll4"));
264 assertThat(ll4Holder.uri(), is("test-yang:cont1.cont2.ll4"));
265 assertThat(((LeafNode) ll4Holder.children().get("0")).name(), is("ll4"));
266 l = ((LeafNode) ll4Holder.children().get("0"));
267 assertThat(l.uri(), is("test-yang:cont1.cont2.ll4[0]"));
268 assertThat(((LeafNode) ll4Holder.children().get("1")).name(), is("ll4"));
269 l = ((LeafNode) ll4Holder.children().get("1"));
270 assertThat(l.uri(), is("test-yang:cont1.cont2.ll4[1]"));
272 Map<String, String> output = ser.decode(node);
273 assertThat(output.size(), is(params.size()));
274 for (Map.Entry<String, String> entry : output.entrySet()) {
275 assertTrue(params.containsKey(entry.getKey()));
280 public void testAugment() throws SvcLogicException {
281 String uri = "test-yang:cont1/cont2";
282 Map<String, String> params = new HashMap<>();
283 params.put("test-yang_cont1.cont2.cont4.leaf10", "abc");
284 params.put("test-yang_cont1.cont2.cont4.test-augment_cont5.leaf13", "abc");
285 params.put("test-yang_cont1.cont2.cont4.test-augment_list7[0].leaf14", "abc");
286 params.put("test-yang_cont1.cont2.cont4.test-augment_list7[1].leaf14", "abc");
287 params.put("test-yang_cont1.cont2.cont4.test-augment_leaf15", "abc");
288 params.put("test-yang_cont1.cont2.cont4.test-augment_ll6[0]", "abc");
289 params.put("test-yang_cont1.cont2.cont4.test-augment_ll6[1]", "abc");
290 params.put("test-yang_cont1.cont2.list6[0].leaf11", "abc");
291 params.put("test-yang_cont1.cont2.list6[1].leaf11", "abc");
292 params.put("test-yang_cont1.cont2.leaf12", "abc");
293 params.put("test-yang_cont1.cont2.ll5[0]", "abc");
294 params.put("test-yang_cont1.cont2.ll5[1]", "abc");
296 InstanceIdentifierContext<?> iCtx = ParserIdentifier
297 .toInstanceIdentifier(uri, context, null);
298 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
299 iCtx.getSchemaNode(), context, uri);
300 PropertiesNode node = ser.encode(params);
302 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
304 assertThat(childNodes.containsKey("cont4"), is(true));
305 SingleInstanceNode cont4 = ((SingleInstanceNode) childNodes.get("cont4"));
306 for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
307 : cont4.augmentations().asMap().entrySet()) {
308 Collection<PropertiesNode> child = augToChild.getValue();
309 if (!child.isEmpty()) {
310 List<String> expectedNodes = new LinkedList<>();
311 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:cont5");
312 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:list7");
313 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:leaf15");
314 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:ll6");
315 assertThat(expectedNodes.size(), is(child.size()));
316 for (PropertiesNode pNode : child) {
317 assertThat(expectedNodes.contains(pNode.uri()), is(true));
318 if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:cont5")) {
319 assertThat(((SingleInstanceNode) pNode).children().containsKey("leaf13"), is(true));
320 LeafNode l = ((LeafNode) ((SingleInstanceNode) pNode).children().get("leaf13"));
321 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont5.leaf13"));
322 } else if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:list7")) {
323 ListHolderNode list7Holder = ((ListHolderNode) pNode);
324 MultiInstanceNode list7 = ((MultiInstanceNode) list7Holder.child("0"));
325 assertThat(list7.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[0]"));
326 Map<String, DataNodeChild> list7Child = list7.children();
327 assertThat(list7Child.containsKey("leaf14"), is(true));
328 LeafNode l = ((LeafNode) list7Child.get("leaf14"));
329 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[0].leaf14"));
330 list7 = ((MultiInstanceNode) list7Holder.child("1"));
331 assertThat(list7.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[1]"));
332 list7Child = list7.children();
333 assertThat(list7Child.containsKey("leaf14"), is(true));
334 l = ((LeafNode) list7Child.get("leaf14"));
335 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[1].leaf14"));
336 } else if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:leaf15")) {
337 LeafNode leaf15 = ((LeafNode) pNode);
338 assertThat(leaf15.name(), is("leaf15"));
339 assertThat(leaf15.uri(), is("test-yang:cont1.cont2.cont4.test-augment:leaf15"));
340 } else if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:ll6")) {
341 LeafListHolderNode ll6Holder = ((LeafListHolderNode) pNode);
342 assertThat(ll6Holder.children().containsKey("0"), is(true));
343 LeafNode l = ((LeafNode) ll6Holder.children().get("0"));
344 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:ll6[0]"));
345 assertThat(ll6Holder.children().containsKey("1"), is(true));
346 l = ((LeafNode) ll6Holder.children().get("1"));
347 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:ll6[1]"));
352 assertThat(cont4.uri(), is("test-yang:cont1.cont2.cont4"));
353 assertThat(cont4.children().containsKey("leaf10"), is(true));
354 LeafNode l = ((LeafNode) cont4.children().get("leaf10"));
355 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.leaf10"));
357 assertThat(childNodes.containsKey("list6"), is(true));
358 HolderNode list6Holder = ((ListHolderNode) childNodes.get("list6"));
359 assertThat(list6Holder.uri(), is("test-yang:cont1.cont2.list6"));
360 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
361 assertThat(list6.uri(), is("test-yang:cont1.cont2.list6[0]"));
362 Map<String, DataNodeChild> list6Child = list6.children();
363 assertThat(list6Child.containsKey("leaf11"), is(true));
364 l = ((LeafNode) list6Child.get("leaf11"));
365 assertThat(l.uri(), is("test-yang:cont1.cont2.list6[0].leaf11"));
366 list6 = ((MultiInstanceNode) list6Holder.child("1"));
367 assertThat(list6.uri(), is("test-yang:cont1.cont2.list6[1]"));
368 list6Child = list6.children();
369 assertThat(list6Child.containsKey("leaf11"), is(true));
370 l = ((LeafNode) list6Child.get("leaf11"));
371 assertThat(l.uri(), is("test-yang:cont1.cont2.list6[1].leaf11"));
373 assertThat(childNodes.containsKey("leaf12"), is(true));
374 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf12"));
375 assertThat(leaf12.name(), is("leaf12"));
376 assertThat(leaf12.uri(), is("test-yang:cont1.cont2.leaf12"));
378 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll5"));
379 assertThat(ll5Holder.uri(), is("test-yang:cont1.cont2.ll5"));
380 assertThat(ll5Holder.children().containsKey("0"), is(true));
381 l = ((LeafNode) ll5Holder.children().get("0"));
382 assertThat(l.uri(), is("test-yang:cont1.cont2.ll5[0]"));
383 assertThat(ll5Holder.children().containsKey("1"), is(true));
384 l = ((LeafNode) ll5Holder.children().get("1"));
385 assertThat(l.uri(), is("test-yang:cont1.cont2.ll5[1]"));
387 Map<String, String> output = ser.decode(node);
388 for (Map.Entry<String, String> entry : output.entrySet()) {
389 assertTrue(params.containsKey(entry.getKey()));
394 public void testChoiceCase1() throws SvcLogicException {
395 String uri = "test-yang:cont8";
396 Map<String, String> params = new HashMap<>();
397 params.put("test-yang_cont8.cont6.leaf16", "abc");
398 params.put("test-yang_cont8.list8[0].leaf18", "abc");
399 params.put("test-yang_cont8.list8[1].leaf18", "abc");
400 params.put("test-yang_cont8.leaf19", "abc");
401 params.put("test-yang_cont8.ll7[0]", "abc");
402 params.put("test-yang_cont8.ll7[1]", "abc");
404 InstanceIdentifierContext<?> iCtx = ParserIdentifier
405 .toInstanceIdentifier(uri, context, null);
406 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
407 iCtx.getSchemaNode(), context, uri);
408 PropertiesNode node = ser.encode(params);
410 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
412 assertThat(childNodes.containsKey("cont6"), is(true));
413 SingleInstanceNode cont6 = ((SingleInstanceNode) childNodes.get("cont6"));
414 assertThat(cont6.uri(), is("test-yang:cont8.cont6"));
415 assertThat(cont6.children().containsKey("leaf16"), is(true));
416 LeafNode l = ((LeafNode) cont6.children().get("leaf16"));
417 assertThat(l.uri(), is("test-yang:cont8.cont6.leaf16"));
419 assertThat(childNodes.containsKey("list8"), is(true));
420 HolderNode list6Holder = ((ListHolderNode) childNodes.get("list8"));
421 assertThat(list6Holder.uri(), is("test-yang:cont8.list8"));
422 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
423 assertThat(list6.uri(), is("test-yang:cont8.list8[0]"));
424 Map<String, DataNodeChild> list6Child = list6.children();
425 assertThat(list6Child.containsKey("leaf18"), is(true));
426 l = ((LeafNode) list6Child.get("leaf18"));
427 assertThat(l.uri(), is("test-yang:cont8.list8[0].leaf18"));
428 list6 = ((MultiInstanceNode) list6Holder.child("1"));
429 list6Child = list6.children();
430 assertThat(list6Child.containsKey("leaf18"), is(true));
431 l = ((LeafNode) list6Child.get("leaf18"));
432 assertThat(l.uri(), is("test-yang:cont8.list8[1].leaf18"));
434 assertThat(childNodes.containsKey("leaf19"), is(true));
435 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf19"));
436 assertThat(leaf12.name(), is("leaf19"));
437 assertThat(leaf12.uri(), is("test-yang:cont8.leaf19"));
439 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll7"));
440 assertThat(ll5Holder.uri(), is("test-yang:cont8.ll7"));
441 assertThat(ll5Holder.children().containsKey("0"), is(true));
442 l = ((LeafNode) ll5Holder.children().get("0"));
443 assertThat(l.uri(), is("test-yang:cont8.ll7[0]"));
444 assertThat(ll5Holder.children().containsKey("1"), is(true));
445 l = ((LeafNode) ll5Holder.children().get("1"));
446 assertThat(l.uri(), is("test-yang:cont8.ll7[1]"));
448 Map<String, String> output = ser.decode(node);
449 assertThat(output.size(), is(params.size()));
450 for (Map.Entry<String, String> entry : output.entrySet()) {
451 assertTrue(params.containsKey(entry.getKey()));
456 public void testChoiceCase2() throws SvcLogicException {
457 String uri = "test-yang:cont9";
458 Map<String, String> params = new HashMap<>();
459 params.put("test-yang_cont9.leaf20", "abc");
460 params.put("test-yang_cont9.ll8[0]", "abc");
461 params.put("test-yang_cont9.cont11.leaf25", "abc");
463 InstanceIdentifierContext<?> iCtx = ParserIdentifier
464 .toInstanceIdentifier(uri, context, null);
465 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
466 iCtx.getSchemaNode(), context, uri);
467 PropertiesNode node = ser.encode(params);
469 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
471 assertThat(childNodes.containsKey("cont11"), is(true));
472 SingleInstanceNode cont4 = ((SingleInstanceNode) childNodes.get("cont11"));
473 assertThat(cont4.uri(), is("test-yang:cont9.cont11"));
474 assertThat(cont4.children().containsKey("leaf25"), is(true));
475 LeafNode l = ((LeafNode) cont4.children().get("leaf25"));
476 assertThat(l.uri(), is("test-yang:cont9.cont11.leaf25"));
478 assertThat(childNodes.containsKey("leaf20"), is(true));
479 l = ((LeafNode) childNodes.get("leaf20"));
480 assertThat(l.uri(), is("test-yang:cont9.leaf20"));
482 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll8"));
483 assertThat(ll5Holder.uri(), is("test-yang:cont9.ll8"));
484 assertThat(ll5Holder.children().containsKey("0"), is(true));
485 l = ((LeafNode) ll5Holder.children().get("0"));
486 assertThat(l.uri(), is("test-yang:cont9.ll8[0]"));
488 Map<String, String> output = ser.decode(node);
489 assertThat(output.size(), is(params.size()));
490 for (Map.Entry<String, String> entry : output.entrySet()) {
491 assertTrue(params.containsKey(entry.getKey()));
496 public void testChoiceCase3() throws SvcLogicException {
497 String uri = "test-yang:cont8/cont6";
498 Map<String, String> params = new HashMap<>();
499 params.put("test-yang_cont8.cont6.test-augment_leaf21", "abc");
501 InstanceIdentifierContext<?> iCtx = ParserIdentifier
502 .toInstanceIdentifier(uri, context, null);
503 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
504 iCtx.getSchemaNode(), context, uri);
505 PropertiesNode node = ser.encode(params);
507 for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
508 : node.augmentations().asMap().entrySet()) {
509 Collection<PropertiesNode> child = augToChild.getValue();
510 if (!child.isEmpty()) {
511 List<String> expectedNodes = new LinkedList<>();
512 expectedNodes.add("test-yang:cont8.cont6.test-augment:leaf21");
513 assertThat(expectedNodes.size(), is(child.size()));
514 for (PropertiesNode pNode : child) {
515 assertThat(expectedNodes.contains(pNode.uri()), is(true));
520 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
522 assertThat(childNodes.containsKey("leaf21"), is(true));
523 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf21"));
524 assertThat(leaf12.name(), is("leaf21"));
525 assertThat(leaf12.uri(), is("test-yang:cont8.cont6.test-augment:leaf21"));
527 Map<String, String> output = ser.decode(node);
528 assertThat(output.size(), is(params.size()));
529 for (Map.Entry<String, String> entry : output.entrySet()) {
530 assertTrue(params.containsKey(entry.getKey()));
535 public void testGrouping() throws SvcLogicException {
536 String uri = "test-yang:cont13";
537 Map<String, String> params = new HashMap<>();
538 params.put("test-yang_cont13.cont12.leaf26", "abc");
539 params.put("test-yang_cont13.list9[0].leaf27", "abc");
540 params.put("test-yang_cont13.leaf28", "abc");
541 params.put("test-yang_cont13.ll9[0]", "abc");
543 InstanceIdentifierContext<?> iCtx = ParserIdentifier
544 .toInstanceIdentifier(uri, context, null);
545 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
546 iCtx.getSchemaNode(), context, uri);
547 PropertiesNode node = ser.encode(params);
549 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
551 assertThat(childNodes.containsKey("cont12"), is(true));
552 SingleInstanceNode cont4 = ((SingleInstanceNode) childNodes.get("cont12"));
553 assertThat(cont4.uri(), is("test-yang:cont13.cont12"));
554 assertThat(cont4.children().containsKey("leaf26"), is(true));
555 LeafNode l = ((LeafNode) cont4.children().get("leaf26"));
556 assertThat(l.uri(), is("test-yang:cont13.cont12.leaf26"));
558 assertThat(childNodes.containsKey("list9"), is(true));
559 HolderNode list6Holder = ((ListHolderNode) childNodes.get("list9"));
560 assertThat(list6Holder.uri(), is("test-yang:cont13.list9"));
561 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
562 assertThat(list6.uri(), is("test-yang:cont13.list9[0]"));
563 Map<String, DataNodeChild> list6Child = list6.children();
564 assertThat(list6Child.containsKey("leaf27"), is(true));
565 l = ((LeafNode) list6Child.get("leaf27"));
566 assertThat(l.uri(), is("test-yang:cont13.list9[0].leaf27"));
568 assertThat(childNodes.containsKey("leaf28"), is(true));
569 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf28"));
570 assertThat(leaf12.name(), is("leaf28"));
571 assertThat(leaf12.uri(), is("test-yang:cont13.leaf28"));
573 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll9"));
574 assertThat(ll5Holder.children().containsKey("0"), is(true));
576 Map<String, String> output = ser.decode(node);
577 assertThat(output.size(), is(params.size()));
578 for (Map.Entry<String, String> entry : output.entrySet()) {
579 assertTrue(params.containsKey(entry.getKey()));
584 public void testGrouping2() throws SvcLogicException {
585 String uri = "test-yang:cont9/cont11";
586 Map<String, String> params = new HashMap<>();
587 params.put("test-yang_cont9.cont11.leaf25", "abc");
588 params.put("test-yang_cont9.cont11.cont13.cont12.leaf26", "abc");
589 params.put("test-yang_cont9.cont11.cont13.list9[0].leaf27", "abc");
590 params.put("test-yang_cont9.cont11.cont13.leaf28", "abc");
591 params.put("test-yang_cont9.cont11.cont13.ll9[0]", "abc");
592 InstanceIdentifierContext<?> iCtx = ParserIdentifier
593 .toInstanceIdentifier(uri, context, null);
594 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
595 iCtx.getSchemaNode(), context, uri);
596 PropertiesNode node = ser.encode(params);
598 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
600 assertThat(childNodes.containsKey("cont13"), is(true));
601 SingleInstanceNode cont13 = ((SingleInstanceNode) childNodes.get("cont13"));
602 assertThat(cont13.uri(), is("test-yang:cont9.cont11.cont13"));
603 SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
604 assertThat(cont12.children().containsKey("leaf26"), is(true));
605 assertThat(cont12.uri(), is("test-yang:cont9.cont11.cont13.cont12"));
606 assertThat(cont12.children().containsKey("leaf26"), is(true));
607 LeafNode l = ((LeafNode) cont12.children().get("leaf26"));
608 assertThat(l.uri(), is("test-yang:cont9.cont11.cont13.cont12.leaf26"));
610 assertThat(cont13.children().containsKey("list9"), is(true));
611 HolderNode list6Holder = ((ListHolderNode) cont13.children().get("list9"));
612 assertThat(list6Holder.uri(), is("test-yang:cont9.cont11.cont13.list9"));
613 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
614 assertThat(list6.uri(), is("test-yang:cont9.cont11.cont13.list9[0]"));
615 Map<String, DataNodeChild> list6Child = list6.children();
616 assertThat(list6Child.containsKey("leaf27"), is(true));
617 l = ((LeafNode) list6Child.get("leaf27"));
618 assertThat(l.uri(), is("test-yang:cont9.cont11.cont13.list9[0].leaf27"));
620 assertThat(cont13.children().containsKey("leaf28"), is(true));
621 LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
622 assertThat(leaf12.name(), is("leaf28"));
623 assertThat(leaf12.uri(), is("test-yang:cont9.cont11.cont13.leaf28"));
625 LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
626 assertThat(ll5Holder.uri(), is("test-yang:cont9.cont11.cont13.ll9"));
627 assertThat(ll5Holder.children().containsKey("0"), is(true));
628 l = ((LeafNode) ll5Holder.children().get("0"));
629 assertThat(l.uri(), is("test-yang:cont9.cont11.cont13.ll9[0]"));
631 Map<String, String> output = ser.decode(node);
632 assertThat(output.size(), is(params.size()));
633 for (Map.Entry<String, String> entry : output.entrySet()) {
634 assertTrue(params.containsKey(entry.getKey()));
639 public void testGrouping3() throws SvcLogicException {
640 String uri = "test-augment:cont13";
641 Map<String, String> params = new HashMap<>();
642 params.put("test-augment_cont13.cont12.leaf26", "abc");
643 params.put("test-augment_cont13.list9[0].leaf27", "abc");
644 params.put("test-augment_cont13.leaf28", "abc");
645 params.put("test-augment_cont13.ll9[0]", "abc");
646 InstanceIdentifierContext<?> iCtx = ParserIdentifier
647 .toInstanceIdentifier(uri, context, null);
648 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
649 iCtx.getSchemaNode(), context, uri);
650 PropertiesNode node = ser.encode(params);
652 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
654 assertThat(childNodes.containsKey("cont12"), is(true));
655 SingleInstanceNode cont12 = ((SingleInstanceNode) childNodes.get("cont12"));
656 assertThat(cont12.uri(), is("test-augment:cont13.cont12"));
657 assertThat(cont12.children().containsKey("leaf26"), is(true));
658 LeafNode l = ((LeafNode) cont12.children().get("leaf26"));
659 assertThat(l.uri(), is("test-augment:cont13.cont12.leaf26"));
661 assertThat(childNodes.containsKey("list9"), is(true));
662 HolderNode list6Holder = ((ListHolderNode) childNodes.get("list9"));
663 assertThat(list6Holder.uri(), is("test-augment:cont13.list9"));
664 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
665 assertThat(list6.uri(), is("test-augment:cont13.list9[0]"));
666 Map<String, DataNodeChild> list6Child = list6.children();
667 assertThat(list6Child.containsKey("leaf27"), is(true));
668 l = ((LeafNode) list6Child.get("leaf27"));
669 assertThat(l.uri(), is("test-augment:cont13.list9[0].leaf27"));
671 assertThat(childNodes.containsKey("leaf28"), is(true));
672 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf28"));
673 assertThat(leaf12.name(), is("leaf28"));
674 assertThat(leaf12.uri(), is("test-augment:cont13.leaf28"));
676 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll9"));
677 assertThat(ll5Holder.uri(), is("test-augment:cont13.ll9"));
678 assertThat(ll5Holder.children().containsKey("0"), is(true));
679 l = ((LeafNode) ll5Holder.children().get("0"));
680 assertThat(l.uri(), is("test-augment:cont13.ll9[0]"));
682 Map<String, String> output = ser.decode(node);
683 assertThat(output.size(), is(params.size()));
684 for (Map.Entry<String, String> entry : output.entrySet()) {
685 assertTrue(params.containsKey(entry.getKey()));
690 public void testGrouping4() throws SvcLogicException {
691 String uri = "test-yang:cont1/cont2/cont4";
692 Map<String, String> params = new HashMap<>();
693 params.put("test-yang_cont1.cont2.cont4.test-augment_cont13.cont12.leaf26", "abc");
694 params.put("test-yang_cont1.cont2.cont4.test-augment_cont13.list9[0].leaf27", "abc");
695 params.put("test-yang_cont1.cont2.cont4.test-augment_cont13.leaf28", "abc");
696 params.put("test-yang_cont1.cont2.cont4.test-augment_cont13.ll9[0]", "abc");
698 InstanceIdentifierContext<?> iCtx = ParserIdentifier
699 .toInstanceIdentifier(uri, context, null);
700 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
701 iCtx.getSchemaNode(), context, uri);
702 PropertiesNode node = ser.encode(params);
704 for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
705 : node.augmentations().asMap().entrySet()) {
706 Collection<PropertiesNode> child = augToChild.getValue();
707 if (!child.isEmpty()) {
708 List<String> expectedNodes = new LinkedList<>();
709 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:cont13");
710 assertThat(expectedNodes.size(), is(child.size()));
711 for (PropertiesNode pNode : child) {
712 assertThat(expectedNodes.contains(pNode.uri()), is(true));
713 SingleInstanceNode cont13 = ((SingleInstanceNode) pNode);
714 assertThat(cont13.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13"));
715 SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
716 assertThat(cont12.children().containsKey("leaf26"), is(true));
717 LeafNode l = ((LeafNode) cont12.children().get("leaf26"));
718 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.cont12.leaf26"));
720 assertThat(cont13.children().containsKey("list9"), is(true));
721 HolderNode list6Holder = ((ListHolderNode) cont13.children().get("list9"));
722 assertThat(list6Holder.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.list9"));
723 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
724 assertThat(list6.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.list9[0]"));
725 Map<String, DataNodeChild> list6Child = list6.children();
726 assertThat(list6Child.containsKey("leaf27"), is(true));
727 l = ((LeafNode) list6Child.get("leaf27"));
728 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.list9[0].leaf27"));
730 assertThat(cont13.children().containsKey("leaf28"), is(true));
731 LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
732 assertThat(leaf12.name(), is("leaf28"));
733 assertThat(leaf12.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.leaf28"));
735 LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
736 assertThat(ll5Holder.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.ll9"));
737 assertThat(ll5Holder.children().containsKey("0"), is(true));
738 l = ((LeafNode) ll5Holder.children().get("0"));
739 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.ll9[0]"));
744 Map<String, String> output = ser.decode(node);
745 assertThat(output.size(), is(params.size()));
746 for (Map.Entry<String, String> entry : output.entrySet()) {
747 assertTrue(params.containsKey(entry.getKey()));
752 public void testRpcInput() throws SvcLogicException {
753 String uri = "test-yang:create-sfc";
754 Map<String, String> params = new HashMap<>();
755 params.put("test-yang_create-sfc.input.cont14.leaf28", "abc");
756 params.put("test-yang_create-sfc.input.list10[0].leaf29", "abc");
757 params.put("test-yang_create-sfc.input.leaf30", "abc");
758 params.put("test-yang_create-sfc.input.ll10[0]", "abc");
759 params.put("test-yang_create-sfc.input.cont15.leaf31", "abc");
760 params.put("test-yang_create-sfc.input.cont13.cont12.leaf26", "abc");
761 params.put("test-yang_create-sfc.input.cont13.list9[0].leaf27", "abc");
762 params.put("test-yang_create-sfc.input.cont13.leaf28", "abc");
763 params.put("test-yang_create-sfc.input.cont13.ll9[0]", "abc");
764 params.put("test-yang_create-sfc.input.test-augment_leaf36", "abc");
766 InstanceIdentifierContext<?> iCtx = ParserIdentifier
767 .toInstanceIdentifier(uri, context, null);
768 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
769 iCtx.getSchemaNode(), context, uri);
770 PropertiesNode node = ser.encode(params);
772 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
774 PropertiesNode input = childNodes.get("input");
775 assertThat(input.uri(), is("test-yang:create-sfc.input"));
776 for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
777 : node.augmentations().asMap().entrySet()) {
778 Collection<PropertiesNode> child = augToChild.getValue();
779 if (!child.isEmpty()) {
780 List<String> expectedNodes = new LinkedList<>();
781 expectedNodes.add("test-yang:create-sfc.input.test-augment:leaf36");
782 assertThat(expectedNodes.size(), is(child.size()));
783 for (PropertiesNode pNode : child) {
784 assertThat(expectedNodes.contains(pNode.uri()), is(true));
785 LeafNode leaf37 = ((LeafNode) pNode);
786 assertThat(leaf37.name(), is("leaf36"));
787 assertThat(leaf37.uri(), is("test-yang:create-sfc.input.test-augment:leaf36"));
791 childNodes = ((InnerNode) input).children();
793 assertThat(childNodes.containsKey("cont14"), is(true));
794 SingleInstanceNode cont14 = ((SingleInstanceNode) childNodes.get("cont14"));
795 assertThat(cont14.uri(), is("test-yang:create-sfc.input.cont14"));
796 assertThat(cont14.children().containsKey("leaf28"), is(true));
797 LeafNode l = ((LeafNode) cont14.children().get("leaf28"));
798 assertThat(l.uri(), is("test-yang:create-sfc.input.cont14.leaf28"));
800 assertThat(childNodes.containsKey("list10"), is(true));
801 HolderNode list10Holder = ((ListHolderNode) childNodes.get("list10"));
802 assertThat(list10Holder.uri(), is("test-yang:create-sfc.input.list10"));
803 MultiInstanceNode list10 = ((MultiInstanceNode) list10Holder.child("0"));
804 assertThat(list10.uri(), is("test-yang:create-sfc.input.list10[0]"));
805 Map<String, DataNodeChild> list10Child = list10.children();
806 assertThat(list10Child.containsKey("leaf29"), is(true));
807 l = ((LeafNode) list10Child.get("leaf29"));
808 assertThat(l.uri(), is("test-yang:create-sfc.input.list10[0].leaf29"));
810 assertThat(childNodes.containsKey("leaf30"), is(true));
811 LeafNode leaf30 = ((LeafNode) childNodes.get("leaf30"));
812 assertThat(leaf30.name(), is("leaf30"));
813 assertThat(leaf30.uri(), is("test-yang:create-sfc.input.leaf30"));
815 LeafListHolderNode ll10Holder = ((LeafListHolderNode) childNodes.get("ll10"));
816 assertThat(ll10Holder.uri(), is("test-yang:create-sfc.input.ll10"));
817 assertThat(ll10Holder.children().containsKey("0"), is(true));
818 l = ((LeafNode) ll10Holder.children().get("0"));
819 assertThat(l.uri(), is("test-yang:create-sfc.input.ll10[0]"));
821 assertThat(childNodes.containsKey("cont15"), is(true));
822 SingleInstanceNode cont15 = ((SingleInstanceNode) childNodes.get("cont15"));
823 assertThat(cont15.uri(), is("test-yang:create-sfc.input.cont15"));
824 assertThat(cont15.children().containsKey("leaf31"), is(true));
825 l = ((LeafNode) cont15.children().get("leaf31"));
826 assertThat(l.uri(), is("test-yang:create-sfc.input.cont15.leaf31"));
828 assertThat(childNodes.containsKey("cont13"), is(true));
829 SingleInstanceNode cont13 = ((SingleInstanceNode) childNodes.get("cont13"));
830 assertThat(cont13.uri(), is("test-yang:create-sfc.input.cont13"));
831 SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
832 assertThat(cont12.uri(), is("test-yang:create-sfc.input.cont13.cont12"));
833 assertThat(cont12.children().containsKey("leaf26"), is(true));
834 l = ((LeafNode) cont12.children().get("leaf26"));
835 assertThat(l.uri(), is("test-yang:create-sfc.input.cont13.cont12.leaf26"));
837 assertThat(cont13.children().containsKey("list9"), is(true));
838 HolderNode list9Holder = ((ListHolderNode) cont13.children().get("list9"));
839 assertThat(list9Holder.uri(), is("test-yang:create-sfc.input.cont13.list9"));
840 MultiInstanceNode list9 = ((MultiInstanceNode) list9Holder.child("0"));
841 assertThat(list9.uri(), is("test-yang:create-sfc.input.cont13.list9[0]"));
842 Map<String, DataNodeChild> list6Child = list9.children();
843 assertThat(list6Child.containsKey("leaf27"), is(true));
844 l = ((LeafNode) list6Child.get("leaf27"));
845 assertThat(l.uri(), is("test-yang:create-sfc.input.cont13.list9[0].leaf27"));
847 assertThat(cont13.children().containsKey("leaf28"), is(true));
848 LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
849 assertThat(leaf12.name(), is("leaf28"));
850 assertThat(leaf12.uri(), is("test-yang:create-sfc.input.cont13.leaf28"));
852 LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
853 assertThat(ll5Holder.uri(), is("test-yang:create-sfc.input.cont13.ll9"));
854 assertThat(ll5Holder.children().containsKey("0"), is(true));
855 l = ((LeafNode) ll5Holder.children().get("0"));
856 assertThat(l.uri(), is("test-yang:create-sfc.input.cont13.ll9[0]"));
858 Map<String, String> output = ser.decode(node);
859 assertThat(output.size(), is(params.size()));
860 for (Map.Entry<String, String> entry : output.entrySet()) {
861 assertTrue(params.containsKey(entry.getKey()));
866 public void testRpcOutput() throws SvcLogicException {
867 String uri = "test-yang:create-sfc";
868 Map<String, String> params = new HashMap<>();
869 params.put("test-yang_create-sfc.output.cont16.leaf32", "abc");
870 params.put("test-yang_create-sfc.output.list11[0].leaf33", "abc");
871 params.put("test-yang_create-sfc.output.leaf34", "abc");
872 params.put("test-yang_create-sfc.output.ll11[0]", "abc");
873 params.put("test-yang_create-sfc.output.cont17.leaf35", "abc");
874 params.put("test-yang_create-sfc.output.cont13.cont12.leaf26", "abc");
875 params.put("test-yang_create-sfc.output.cont13.list9[0].leaf27", "abc");
876 params.put("test-yang_create-sfc.output.cont13.leaf28", "abc");
877 params.put("test-yang_create-sfc.output.cont13.ll9[0]", "abc");
878 params.put("test-yang_create-sfc.output.test-augment_leaf37", "abc");
880 InstanceIdentifierContext<?> iCtx = ParserIdentifier
881 .toInstanceIdentifier(uri, context, null);
882 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
883 iCtx.getSchemaNode(), context, uri);
884 PropertiesNode node = ser.encode(params);
886 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
888 PropertiesNode output = childNodes.get("output");
889 assertThat(output.uri(), is("test-yang:create-sfc.output"));
890 for (Map.Entry<Object, Collection<PropertiesNode>> augmentationToChild :
891 node.augmentations().asMap().entrySet()) {
892 Collection<PropertiesNode> c = augmentationToChild.getValue();
894 List<String> expectedNodes = new LinkedList<>();
895 expectedNodes.add("test-yang:create-sfc.output.test-augment:leaf37");
896 assertThat(expectedNodes.size(), is(expectedNodes));
897 for (PropertiesNode pNode : c) {
898 assertThat(expectedNodes.contains(pNode.uri()), is(true));
899 LeafNode leaf37 = ((LeafNode) pNode);
900 assertThat(leaf37.name(), is("leaf37"));
901 assertThat(leaf37.uri(), is("test-yang:create-sfc.output.test-augment:leaf37"));
905 childNodes = ((InnerNode) output).children();
907 assertThat(childNodes.containsKey("cont16"), is(true));
908 SingleInstanceNode cont16 = ((SingleInstanceNode) childNodes.get("cont16"));
909 assertThat(cont16.uri(), is("test-yang:create-sfc.output.cont16"));
910 assertThat(cont16.children().containsKey("leaf32"), is(true));
911 LeafNode l = ((LeafNode) cont16.children().get("leaf32"));
912 assertThat(l.uri(), is("test-yang:create-sfc.output.cont16.leaf32"));
914 assertThat(childNodes.containsKey("list11"), is(true));
915 HolderNode list11Holder = ((ListHolderNode) childNodes.get("list11"));
916 assertThat(list11Holder.uri(), is("test-yang:create-sfc.output.list11"));
917 MultiInstanceNode list11 = ((MultiInstanceNode) list11Holder.child("0"));
918 assertThat(list11.uri(), is("test-yang:create-sfc.output.list11[0]"));
919 Map<String, DataNodeChild> list11Child = list11.children();
920 assertThat(list11Child.containsKey("leaf33"), is(true));
921 l = ((LeafNode) list11Child.get("leaf33"));
922 assertThat(l.uri(), is("test-yang:create-sfc.output.list11[0].leaf33"));
924 assertThat(childNodes.containsKey("leaf34"), is(true));
925 LeafNode leaf34 = ((LeafNode) childNodes.get("leaf34"));
926 assertThat(leaf34.name(), is("leaf34"));
927 assertThat(leaf34.uri(), is("test-yang:create-sfc.output.leaf34"));
929 LeafListHolderNode ll10Holder = ((LeafListHolderNode) childNodes.get("ll11"));
930 assertThat(ll10Holder.uri(), is("test-yang:create-sfc.output.ll11"));
931 assertThat(ll10Holder.children().containsKey("0"), is(true));
932 l = ((LeafNode) ll10Holder.children().get("0"));
933 assertThat(l.uri(), is("test-yang:create-sfc.output.ll11[0]"));
935 assertThat(childNodes.containsKey("cont17"), is(true));
936 SingleInstanceNode cont17 = ((SingleInstanceNode) childNodes.get("cont17"));
937 assertThat(cont17.uri(), is("test-yang:create-sfc.output.cont17"));
938 assertThat(cont17.children().containsKey("leaf35"), is(true));
939 l = ((LeafNode) cont17.children().get("leaf35"));
940 assertThat(l.uri(), is("test-yang:create-sfc.output.cont17.leaf35"));
942 assertThat(childNodes.containsKey("cont13"), is(true));
943 SingleInstanceNode cont13 = ((SingleInstanceNode) childNodes.get("cont13"));
944 assertThat(cont13.uri(), is("test-yang:create-sfc.output.cont13"));
945 SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
946 assertThat(cont12.uri(), is("test-yang:create-sfc.output.cont13.cont12"));
947 assertThat(cont12.children().containsKey("leaf26"), is(true));
948 l = ((LeafNode) cont12.children().get("leaf26"));
949 assertThat(l.uri(), is("test-yang:create-sfc.output.cont13.cont12.leaf26"));
951 assertThat(cont13.children().containsKey("list9"), is(true));
952 HolderNode list9Holder = ((ListHolderNode) cont13.children().get("list9"));
953 assertThat(list9Holder.uri(), is("test-yang:create-sfc.output.cont13.list9"));
954 MultiInstanceNode list9 = ((MultiInstanceNode) list9Holder.child("0"));
955 assertThat(list9.uri(), is("test-yang:create-sfc.output.cont13.list9[0]"));
956 Map<String, DataNodeChild> list6Child = list9.children();
957 assertThat(list6Child.containsKey("leaf27"), is(true));
958 l = ((LeafNode) list6Child.get("leaf27"));
959 assertThat(l.uri(), is("test-yang:create-sfc.output.cont13.list9[0].leaf27"));
961 assertThat(cont13.children().containsKey("leaf28"), is(true));
962 LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
963 assertThat(leaf12.name(), is("leaf28"));
964 assertThat(leaf12.uri(), is("test-yang:create-sfc.output.cont13.leaf28"));
966 LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
967 assertThat(ll5Holder.uri(), is("test-yang:create-sfc.output.cont13.ll9"));
968 assertThat(ll5Holder.children().containsKey("0"), is(true));
969 l = ((LeafNode) ll5Holder.children().get("0"));
970 assertThat(l.uri(), is("test-yang:create-sfc.output.cont13.ll9[0]"));
972 Map<String, String> output1 = ser.decode(node);
973 assertThat(output1.size(), is(params.size()));
974 for (Map.Entry<String, String> entry : output1.entrySet()) {
975 assertTrue(params.containsKey(entry.getKey()));
980 public void testContainerSameName() throws SvcLogicException {
981 String uri = "test-yang:cont18";
982 Map<String, String> params = new HashMap<>();
983 params.put("test-yang_cont18.cont18.list12[0].list12[0].leaf36", "abc");
984 params.put("test-yang_cont18.cont18.list12[0].leaf36", "hi");
985 params.put("test-yang_cont18.cont18.list12[1].list12[0].leaf36", "xyz");
986 params.put("test-yang_cont18.cont18.list12[1].list12[1].leaf36", "hey!");
988 InstanceIdentifierContext<?> iCtx = ParserIdentifier
989 .toInstanceIdentifier(uri, context, null);
990 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
991 iCtx.getSchemaNode(), context, uri);
992 PropertiesNode node = ser.encode(params);
994 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
996 assertThat(childNodes.containsKey("cont18"), is(true));
997 node = childNodes.get("cont18");
998 assertThat(node.uri(), is("test-yang:cont18.cont18"));
999 childNodes = ((InnerNode) node).children();
1001 assertThat(childNodes.containsKey("list12"), is(true));
1002 HolderNode holder = ((ListHolderNode) childNodes.get("list12"));
1003 assertThat(holder.uri(), is("test-yang:cont18.cont18.list12"));
1004 MultiInstanceNode node1 = ((MultiInstanceNode) holder.child("0"));
1005 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[0]"));
1006 Map<String, DataNodeChild> list12Child = node1.children();
1008 assertThat(list12Child.containsKey("leaf36"), is(true));
1009 LeafNode leaf = ((LeafNode) list12Child.get("leaf36"));
1010 assertThat(leaf.value(), is("hi"));
1011 assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[0].leaf36"));
1013 assertThat(list12Child.containsKey("list12"), is(true));
1014 HolderNode holder1 = ((ListHolderNode) list12Child.get("list12"));
1015 assertThat(holder1.uri(), is("test-yang:cont18.cont18.list12[0].list12"));
1016 node1 = ((MultiInstanceNode) holder1.child("0"));
1017 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[0].list12[0]"));
1018 list12Child = node1.children();
1019 assertThat(list12Child.containsKey("leaf36"), is(true));
1020 leaf = ((LeafNode) list12Child.get("leaf36"));
1021 assertThat(leaf.value(), is("abc"));
1022 assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[0].list12[0].leaf36"));
1024 node1 = ((MultiInstanceNode) holder.child("1"));
1025 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[1]"));
1026 list12Child = node1.children();
1027 assertThat(list12Child.containsKey("list12"), is(true));
1028 holder = ((ListHolderNode) list12Child.get("list12"));
1029 assertThat(holder.uri(), is("test-yang:cont18.cont18.list12[1].list12"));
1030 node1 = ((MultiInstanceNode) holder.child("0"));
1031 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[1].list12[0]"));
1032 assertThat(node1.children().containsKey("leaf36"), is(true));
1033 leaf = ((LeafNode) node1.children().get("leaf36"));
1034 assertThat(leaf.value(), is("xyz"));
1035 assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[1].list12[0].leaf36"));
1037 node1 = ((MultiInstanceNode) holder.child("1"));
1038 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[1].list12[1]"));
1039 assertThat(node1.children().containsKey("leaf36"), is(true));
1040 leaf = ((LeafNode) node1.children().get("leaf36"));
1041 assertThat(leaf.value(), is("hey!"));
1042 assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[1].list12[1].leaf36"));
1044 Map<String, String> output1 = ser.decode(node);
1045 assertThat(output1.size(), is(params.size()));
1046 for (Map.Entry<String, String> entry : output1.entrySet()) {
1047 assertTrue(params.containsKey(entry.getKey()));
1052 public void testPropertiesWithoutSchema() throws SvcLogicException {
1053 String uri = "test-yang:cont18";
1054 Map<String, String> params = new HashMap<>();
1055 params.put("test-yang_cont18.leaf40", "abc");
1056 params.put("leaf41", "hi");
1057 params.put("test-yang_cont18.leaf41", "abc");
1059 InstanceIdentifierContext<?> iCtx = ParserIdentifier
1060 .toInstanceIdentifier(uri, context, null);
1061 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
1062 iCtx.getSchemaNode(), context, uri);
1063 PropertiesNode node = ser.encode(params);
1065 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
1066 assertThat(childNodes.containsKey("leaf40"), is(true));
1067 node = childNodes.get("leaf40");
1068 assertThat(node.uri(), is("test-yang:cont18.leaf40"));
1072 public void testIdentityRef() throws SvcLogicException {
1073 String uri = "identity-test:test";
1074 Map<String, String> params = new HashMap<>();
1075 params.put("identity-test_test.con1.interface", "identity-types" +
1077 params.put("identity-test_test.con1.interfaces.int-list[0].iden", "identity-test:Giga");
1078 params.put("identity-test_test.con1.interfaces.int-list[0].available.ll[0]", "identity-types:Loopback");
1079 params.put("identity-test_test.con1.interfaces.int-list[0].available.leaf1", "identity-types-second:Ethernet");
1080 params.put("identity-test_test.con1.interfaces.int-list[0].available.leaf2", "identity-types-second:iden2");
1081 InstanceIdentifierContext<?> iCtx = ParserIdentifier
1082 .toInstanceIdentifier(uri, context, null);
1084 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
1085 iCtx.getSchemaNode(), context, uri);
1086 PropertiesNode node = ser.encode(params);
1087 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
1088 assertThat(childNodes.containsKey("con1"), is(true));
1089 node = childNodes.get("con1");
1090 assertThat(node.uri(), is("identity-test:test.con1"));
1091 LeafNode l = ((LeafNode) ((SingleInstanceNode) node).children().get("interface"));
1092 assertThat(l.uri(), is("identity-test:test.con1.interface"));
1093 assertThat(l.valueNs().moduleName(), is("identity-types"));
1094 assertThat(l.valueNs().moduleNs().toString(), is("identity:list:ns:test:json:ser"));
1096 // identity type inside union
1097 node = ((SingleInstanceNode) ((SingleInstanceNode) node).children().get("interfaces"));
1098 node = ((ListHolderNode) ((SingleInstanceNode) node).children().get("int-list"));
1099 node = ((MultiInstanceNode) ((ListHolderNode) node).children().get("0"));
1100 l = ((LeafNode) ((MultiInstanceNode) node).children().get("iden"));
1101 assertThat(l.uri(), is("identity-test:test.con1.interfaces.int-list[0].iden"));
1102 assertThat(l.valueNs().moduleName(), is("identity-test"));
1103 assertThat(l.valueNs().moduleNs().toString(), is("identity:ns:test:json:ser"));
1106 node = (SingleInstanceNode) ((MultiInstanceNode) node).children().get("available");
1107 LeafListHolderNode holder = (LeafListHolderNode) ((SingleInstanceNode) node).children().get("ll");
1108 l = ((LeafNode) holder.children().get("0"));
1109 assertThat(l.uri(), is("identity-test:test.con1.interfaces.int-list[0].available.ll[0]"));
1110 assertThat(l.valueNs().moduleName(), is("identity-types"));
1111 assertThat(l.valueNs().moduleNs().toString(), is("identity:list:ns:test:json:ser"));
1114 l = ((LeafNode) ((SingleInstanceNode) node).children().get("leaf1"));
1115 assertThat(l.uri(), is("identity-test:test.con1.interfaces.int-list[0].available.leaf1"));
1116 assertThat(l.valueNs().moduleName(), is("identity-types-second"));
1117 assertThat(l.valueNs().moduleNs().toString(), is("identity:list:second:ns:test:json:ser"));
1119 // list of base identity test
1120 l = ((LeafNode) ((SingleInstanceNode) node).children().get("leaf2"));
1121 assertThat(l.uri(), is("identity-test:test.con1.interfaces.int-list[0].available.leaf2"));
1122 assertThat(l.valueNs().moduleName(), is("identity-types-second"));
1123 assertThat(l.valueNs().moduleNs().toString(), is("identity:list:second:ns:test:json:ser"));
1126 public static EffectiveModelContext compileYangFile() throws FileNotFoundException {
1127 String path = PropertiesSerializerTest.class.getResource("/yang").getPath();
1128 File dir = new File(path);
1129 String[] fileList = dir.list();
1130 List<File> yangFiles = new ArrayList<File>();
1131 if (fileList == null) {
1132 throw new FileNotFoundException("/yang");
1134 for (int i = 0; i < fileList.length; i++) {
1135 final String fileName = fileList[i];
1136 if (new File(dir, fileName).isDirectory() == false) {
1137 yangFiles.add(new File(dir, fileName));
1140 return YangParserTestUtils.parseYangFiles(yangFiles);