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 org.junit.Before;
23 import org.junit.Test;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
26 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
27 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
28 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
29 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
32 import java.io.FileNotFoundException;
33 import java.util.ArrayList;
34 import java.util.Collection;
35 import java.util.HashMap;
36 import java.util.LinkedList;
37 import java.util.List;
40 import static org.hamcrest.MatcherAssert.assertThat;
41 import static org.hamcrest.Matchers.is;
42 import static org.junit.Assert.assertTrue;
44 public final class PropertiesSerializerTest {
45 private SchemaContext context;
48 public void initialization() throws FileNotFoundException {
49 context = compileYangFile();
53 public void testBasicConstructs() throws SvcLogicException {
54 String uri = "test-yang:cont1/cont2";
55 Map<String, String> params = new HashMap<>();
56 params.put("test-yang:cont1.cont2.cont3.leaf10", "abc");
57 params.put("test-yang:cont1.cont2.list1[0].leaf1", "abc");
58 params.put("test-yang:cont1.cont2.list1[0].leaf2", "abc");
59 params.put("test-yang:cont1.cont2.list1[0].leaf3", "abc");
60 params.put("test-yang:cont1.cont2.list1[0].ll1[0]", "abc");
61 params.put("test-yang:cont1.cont2.list1[0].ll1[1]", "abc");
62 params.put("test-yang:cont1.cont2.list1[0].ll2[0]", "abc");
63 params.put("test-yang:cont1.cont2.list1[0].ll2[1]", "abc");
64 params.put("test-yang:cont1.cont2.list1[0].cont4.leaf11", "abc");
65 params.put("test-yang:cont1.cont2.list1[0].list4[0].leaf8", "abc");
66 params.put("test-yang:cont1.cont2.list1[0].list4[1].leaf8", "abc");
67 params.put("test-yang:cont1.cont2.list1[0].list5[0].leaf9", "abc");
68 params.put("test-yang:cont1.cont2.list1[0].list5[1].leaf9", "abc");
69 params.put("test-yang:cont1.cont2.list1[1].leaf1", "abc");
70 params.put("test-yang:cont1.cont2.list1[1].leaf2", "abc");
71 params.put("test-yang:cont1.cont2.list1[1].leaf3", "abc");
72 params.put("test-yang:cont1.cont2.list1[1].ll1[0]", "abc");
73 params.put("test-yang:cont1.cont2.list1[1].ll1[1]", "abc");
74 params.put("test-yang:cont1.cont2.list1[1].ll2[0]", "abc");
75 params.put("test-yang:cont1.cont2.list1[1].ll2[1]", "abc");
76 params.put("test-yang:cont1.cont2.list1[1].cont4.leaf11", "abc");
77 params.put("test-yang:cont1.cont2.list1[1].list4[0].leaf8", "abc");
78 params.put("test-yang:cont1.cont2.list1[1].list4[1].leaf8", "abc");
79 params.put("test-yang:cont1.cont2.list1[1].list5[0].leaf9", "abc");
80 params.put("test-yang:cont1.cont2.list1[1].list5[1].leaf9", "abc");
81 params.put("test-yang:cont1.cont2.list2[0].leaf4", "abc");
82 params.put("test-yang:cont1.cont2.list2[1].leaf4", "abc");
83 params.put("test-yang:cont1.cont2.leaf5", "abc");
84 params.put("test-yang:cont1.cont2.leaf6", "abc");
85 params.put("test-yang:cont1.cont2.ll3[0]", "abc");
86 params.put("test-yang:cont1.cont2.ll3[1]", "abc");
87 params.put("test-yang:cont1.cont2.ll4[0]", "abc");
88 params.put("test-yang:cont1.cont2.ll4[1]", "abc");
89 InstanceIdentifierContext<?> iCtx = ParserIdentifier
90 .toInstanceIdentifier(uri, context, null);
92 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
93 iCtx.getSchemaNode(), context, uri);
94 PropertiesNode node = ser.encode(params);
96 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
98 assertThat(childNodes.containsKey("cont3"), is(true));
99 SingleInstanceNode cont3 = ((SingleInstanceNode) childNodes.get("cont3"));
100 assertThat(cont3.uri(), is("test-yang:cont1.cont2.cont3"));
101 assertThat(cont3.children().containsKey("leaf10"), is(true));
103 assertThat(childNodes.containsKey("list1"), is(true));
104 HolderNode list1Holder = ((ListHolderNode) childNodes.get("list1"));
105 assertThat(list1Holder.uri(), is("test-yang:cont1.cont2.list1"));
106 MultiInstanceNode list10 = ((MultiInstanceNode) list1Holder.child("0"));
107 assertThat(list10.uri(), is("test-yang:cont1.cont2.list1[0]"));
108 Map<String, DataNodeChild> list10Child = list10.children();
109 assertThat(list10Child.containsKey("leaf1"), is(true));
110 LeafNode l = ((LeafNode) list10Child.get("leaf1"));
111 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].leaf1"));
112 assertThat(list10Child.containsKey("leaf2"), is(true));
113 l = ((LeafNode) list10Child.get("leaf2"));
114 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].leaf2"));
115 assertThat(list10Child.containsKey("leaf2"), is(true));
116 l = ((LeafNode) list10Child.get("leaf3"));
117 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].leaf3"));
119 LeafListHolderNode ll1Holder = ((LeafListHolderNode) list10Child.get("ll1"));
120 assertThat(ll1Holder.uri(), is("test-yang:cont1.cont2.list1[0].ll1"));
121 assertThat(ll1Holder.children().containsKey("0"), is(true));
122 l = ((LeafNode) ll1Holder.child("0"));
123 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll1[0]"));
124 assertThat(ll1Holder.children().containsKey("1"), is(true));
125 l = ((LeafNode) ll1Holder.child("1"));
126 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll1[1]"));
128 LeafListHolderNode ll2Holder = ((LeafListHolderNode) list10Child.get("ll2"));
129 assertThat(ll2Holder.uri(), is("test-yang:cont1.cont2.list1[0].ll2"));
130 assertThat(ll2Holder.children().containsKey("0"), is(true));
131 l = ((LeafNode) ll2Holder.child("0"));
132 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll2[0]"));
133 assertThat(ll2Holder.children().containsKey("1"), is(true));
134 l = ((LeafNode) ll2Holder.child("1"));
135 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll2[1]"));
137 SingleInstanceNode cont4 = ((SingleInstanceNode) list10Child.get("cont4"));
138 assertThat(cont4.uri(), is("test-yang:cont1.cont2.list1[0].cont4"));
139 assertThat(cont4.children().containsKey("leaf11"), is(true));
140 l = ((LeafNode) cont4.children().get("leaf11"));
141 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].cont4.leaf11"));
143 HolderNode list4Holder = ((HolderNode) list10Child.get("list4"));
144 assertThat(list4Holder.uri(), is("test-yang:cont1.cont2.list1[0].list4"));
145 Map<String, PropertiesNode> c = list4Holder.children();
146 MultiInstanceNode list40 = ((MultiInstanceNode) c.get("0"));
147 assertThat(list40.uri(), is("test-yang:cont1.cont2.list1[0].list4[0]"));
148 assertThat(list40.children().containsKey("leaf8"), is(true));
149 l = ((LeafNode) list40.children().get("leaf8"));
150 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list4[0].leaf8"));
151 MultiInstanceNode list41 = ((MultiInstanceNode) c.get("1"));
152 assertThat(list41.uri(), is("test-yang:cont1.cont2.list1[0].list4[1]"));
153 assertThat(list41.children().containsKey("leaf8"), is(true));
154 l = ((LeafNode) list41.children().get("leaf8"));
155 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list4[1].leaf8"));
157 HolderNode list5Holder = ((HolderNode) list10Child.get("list5"));
158 assertThat(list5Holder.uri(), is("test-yang:cont1.cont2.list1[0].list5"));
159 c = list5Holder.children();
160 MultiInstanceNode list50 = ((MultiInstanceNode) c.get("0"));
161 assertThat(list50.uri(), is("test-yang:cont1.cont2.list1[0].list5[0]"));
162 assertThat(list50.children().containsKey("leaf9"), is(true));
163 l = ((LeafNode) list50.children().get("leaf9"));
164 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list5[0].leaf9"));
165 MultiInstanceNode list51 = ((MultiInstanceNode) c.get("1"));
166 assertThat(list51.uri(), is("test-yang:cont1.cont2.list1[0].list5[1]"));
167 assertThat(list51.children().containsKey("leaf9"), is(true));
168 l = ((LeafNode) list51.children().get("leaf9"));
169 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list5[1].leaf9"));
171 MultiInstanceNode list11 = ((MultiInstanceNode) list1Holder.child("1"));
172 assertThat(list11.uri(), is("test-yang:cont1.cont2.list1[1]"));
173 Map<String, DataNodeChild> list11Child = list11.children();
174 assertThat(list11Child.containsKey("leaf1"), is(true));
175 l = ((LeafNode) list11Child.get("leaf1"));
176 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].leaf1"));
177 assertThat(list11Child.containsKey("leaf2"), is(true));
178 l = ((LeafNode) list11Child.get("leaf2"));
179 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].leaf2"));
180 assertThat(list11Child.containsKey("leaf3"), is(true));
181 l = ((LeafNode) list11Child.get("leaf3"));
182 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].leaf3"));
184 ll1Holder = ((LeafListHolderNode) list11Child.get("ll1"));
185 assertThat(ll1Holder.uri(), is("test-yang:cont1.cont2.list1[1].ll1"));
186 assertThat(ll1Holder.children().containsKey("0"), is(true));
187 l = ((LeafNode) ll1Holder.children().get("0"));
188 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll1[0]"));
189 assertThat(ll1Holder.children().containsKey("1"), is(true));
190 l = ((LeafNode) ll1Holder.children().get("1"));
191 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll1[1]"));
193 ll2Holder = ((LeafListHolderNode) list11Child.get("ll2"));
194 assertThat(ll2Holder.uri(), is("test-yang:cont1.cont2.list1[1].ll2"));
195 assertThat(ll2Holder.children().containsKey("0"), is(true));
196 l = ((LeafNode) ll2Holder.children().get("0"));
197 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll2[0]"));
198 assertThat(ll2Holder.children().containsKey("1"), is(true));
199 l = ((LeafNode) ll2Holder.children().get("1"));
200 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll2[1]"));
202 cont4 = ((SingleInstanceNode) list11Child.get("cont4"));
203 assertThat(cont4.uri(), is("test-yang:cont1.cont2.list1[1].cont4"));
204 assertThat(cont4.children().containsKey("leaf11"), is(true));
205 l = ((LeafNode) cont4.children().get("leaf11"));
206 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].cont4.leaf11"));
208 list4Holder = ((HolderNode) list11Child.get("list4"));
209 assertThat(list4Holder.uri(), is("test-yang:cont1.cont2.list1[1].list4"));
210 c = list4Holder.children();
211 list40 = ((MultiInstanceNode) c.get("0"));
212 assertThat(list40.uri(), is("test-yang:cont1.cont2.list1[1].list4[0]"));
213 assertThat(list40.children().containsKey("leaf8"), is(true));
214 l = ((LeafNode) list40.children().get("leaf8"));
215 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list4[0].leaf8"));
216 list41 = ((MultiInstanceNode) c.get("1"));
217 assertThat(list41.uri(), is("test-yang:cont1.cont2.list1[1].list4[1]"));
218 assertThat(list41.children().containsKey("leaf8"), is(true));
219 l = ((LeafNode) list41.children().get("leaf8"));
220 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list4[1].leaf8"));
222 list5Holder = ((HolderNode) list11Child.get("list5"));
223 assertThat(list5Holder.uri(), is("test-yang:cont1.cont2.list1[1].list5"));
224 c = list5Holder.children();
225 list50 = ((MultiInstanceNode) c.get("0"));
226 assertThat(list50.uri(), is("test-yang:cont1.cont2.list1[1].list5[0]"));
227 assertThat(list50.children().containsKey("leaf9"), is(true));
228 l = ((LeafNode) list50.children().get("leaf9"));
229 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list5[0].leaf9"));
230 list51 = ((MultiInstanceNode) c.get("1"));
231 assertThat(list51.uri(), is("test-yang:cont1.cont2.list1[1].list5[1]"));
232 assertThat(list51.children().containsKey("leaf9"), is(true));
233 l = ((LeafNode) list51.children().get("leaf9"));
234 assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list5[1].leaf9"));
236 assertThat(childNodes.containsKey("list2"), is(true));
237 HolderNode list2Holder = ((HolderNode) childNodes.get("list2"));
238 assertThat(list2Holder.uri(), is("test-yang:cont1.cont2.list2"));
239 InnerNode list20 = ((InnerNode) list2Holder.children().get("0"));
240 assertThat(list20.uri(), is("test-yang:cont1.cont2.list2[0]"));
241 assertThat(list20.children().containsKey("leaf4"), is(true));
242 l = ((LeafNode) list20.children().get("leaf4"));
243 assertThat(l.uri(), is("test-yang:cont1.cont2.list2[0].leaf4"));
244 InnerNode list21 = ((InnerNode) list2Holder.children().get("1"));
245 assertThat(list21.uri(), is("test-yang:cont1.cont2.list2[1]"));
246 assertThat(list21.children().containsKey("leaf4"), is(true));
247 l = ((LeafNode) list21.children().get("leaf4"));
248 assertThat(l.uri(), is("test-yang:cont1.cont2.list2[1].leaf4"));
250 assertThat(childNodes.containsKey("leaf5"), is(true));
251 l = ((LeafNode) childNodes.get("leaf5"));
252 assertThat(l.uri(), is("test-yang:cont1.cont2.leaf5"));
253 assertThat(childNodes.containsKey("leaf6"), is(true));
254 l = ((LeafNode) childNodes.get("leaf6"));
255 assertThat(l.uri(), is("test-yang:cont1.cont2.leaf6"));
257 HolderNode ll3Holder = ((HolderNode) childNodes.get("ll3"));
258 assertThat(ll3Holder.uri(), is("test-yang:cont1.cont2.ll3"));
259 assertThat(((LeafNode) ll3Holder.children().get("0")).name(), is("ll3"));
260 l = ((LeafNode) ll3Holder.children().get("0"));
261 assertThat(l.uri(), is("test-yang:cont1.cont2.ll3[0]"));
262 assertThat(((LeafNode) ll3Holder.children().get("1")).name(), is("ll3"));
263 l = ((LeafNode) ll3Holder.children().get("1"));
264 assertThat(l.uri(), is("test-yang:cont1.cont2.ll3[1]"));
266 HolderNode ll4Holder = ((HolderNode) childNodes.get("ll4"));
267 assertThat(ll4Holder.uri(), is("test-yang:cont1.cont2.ll4"));
268 assertThat(((LeafNode) ll4Holder.children().get("0")).name(), is("ll4"));
269 l = ((LeafNode) ll4Holder.children().get("0"));
270 assertThat(l.uri(), is("test-yang:cont1.cont2.ll4[0]"));
271 assertThat(((LeafNode) ll4Holder.children().get("1")).name(), is("ll4"));
272 l = ((LeafNode) ll4Holder.children().get("1"));
273 assertThat(l.uri(), is("test-yang:cont1.cont2.ll4[1]"));
275 Map<String, String> output = ser.decode(node);
276 assertThat(output.size(), is(params.size()));
277 for (Map.Entry<String, String> entry : output.entrySet()) {
278 assertTrue(params.containsKey(entry.getKey()));
283 public void testAugment() throws SvcLogicException {
284 String uri = "test-yang:cont1/cont2";
285 Map<String, String> params = new HashMap<>();
286 params.put("test-yang:cont1.cont2.cont4.leaf10", "abc");
287 params.put("test-yang:cont1.cont2.cont4.test-augment:cont5.leaf13", "abc");
288 params.put("test-yang:cont1.cont2.cont4.test-augment:list7[0].leaf14", "abc");
289 params.put("test-yang:cont1.cont2.cont4.test-augment:list7[1].leaf14", "abc");
290 params.put("test-yang:cont1.cont2.cont4.test-augment:leaf15", "abc");
291 params.put("test-yang:cont1.cont2.cont4.test-augment:ll6[0]", "abc");
292 params.put("test-yang:cont1.cont2.cont4.test-augment:ll6[1]", "abc");
293 params.put("test-yang:cont1.cont2.list6[0].leaf11", "abc");
294 params.put("test-yang:cont1.cont2.list6[1].leaf11", "abc");
295 params.put("test-yang:cont1.cont2.leaf12", "abc");
296 params.put("test-yang:cont1.cont2.ll5[0]", "abc");
297 params.put("test-yang:cont1.cont2.ll5[1]", "abc");
299 InstanceIdentifierContext<?> iCtx = ParserIdentifier
300 .toInstanceIdentifier(uri, context, null);
301 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
302 iCtx.getSchemaNode(), context, uri);
303 PropertiesNode node = ser.encode(params);
305 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
307 assertThat(childNodes.containsKey("cont4"), is(true));
308 SingleInstanceNode cont4 = ((SingleInstanceNode) childNodes.get("cont4"));
309 for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
310 : cont4.augmentations().asMap().entrySet()) {
311 Collection<PropertiesNode> child = augToChild.getValue();
312 if (!child.isEmpty()) {
313 List<String> expectedNodes = new LinkedList<>();
314 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:cont5");
315 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:list7");
316 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:leaf15");
317 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:ll6");
318 assertThat(expectedNodes.size(), is(child.size()));
319 for (PropertiesNode pNode : child) {
320 assertThat(expectedNodes.contains(pNode.uri()), is(true));
321 if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:cont5")) {
322 assertThat(((SingleInstanceNode) pNode).children().containsKey("leaf13"), is(true));
323 LeafNode l = ((LeafNode) ((SingleInstanceNode) pNode).children().get("leaf13"));
324 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont5.leaf13"));
325 } else if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:list7")) {
326 ListHolderNode list7Holder = ((ListHolderNode) pNode);
327 MultiInstanceNode list7 = ((MultiInstanceNode) list7Holder.child("0"));
328 assertThat(list7.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[0]"));
329 Map<String, DataNodeChild> list7Child = list7.children();
330 assertThat(list7Child.containsKey("leaf14"), is(true));
331 LeafNode l = ((LeafNode) list7Child.get("leaf14"));
332 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[0].leaf14"));
333 list7 = ((MultiInstanceNode) list7Holder.child("1"));
334 assertThat(list7.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[1]"));
335 list7Child = list7.children();
336 assertThat(list7Child.containsKey("leaf14"), is(true));
337 l = ((LeafNode) list7Child.get("leaf14"));
338 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[1].leaf14"));
339 } else if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:leaf15")) {
340 LeafNode leaf15 = ((LeafNode) pNode);
341 assertThat(leaf15.name(), is("leaf15"));
342 assertThat(leaf15.uri(), is("test-yang:cont1.cont2.cont4.test-augment:leaf15"));
343 } else if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:ll6")) {
344 LeafListHolderNode ll6Holder = ((LeafListHolderNode) pNode);
345 assertThat(ll6Holder.children().containsKey("0"), is(true));
346 LeafNode l = ((LeafNode) ll6Holder.children().get("0"));
347 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:ll6[0]"));
348 assertThat(ll6Holder.children().containsKey("1"), is(true));
349 l = ((LeafNode) ll6Holder.children().get("1"));
350 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:ll6[1]"));
355 assertThat(cont4.uri(), is("test-yang:cont1.cont2.cont4"));
356 assertThat(cont4.children().containsKey("leaf10"), is(true));
357 LeafNode l = ((LeafNode) cont4.children().get("leaf10"));
358 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.leaf10"));
360 assertThat(childNodes.containsKey("list6"), is(true));
361 HolderNode list6Holder = ((ListHolderNode) childNodes.get("list6"));
362 assertThat(list6Holder.uri(), is("test-yang:cont1.cont2.list6"));
363 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
364 assertThat(list6.uri(), is("test-yang:cont1.cont2.list6[0]"));
365 Map<String, DataNodeChild> list6Child = list6.children();
366 assertThat(list6Child.containsKey("leaf11"), is(true));
367 l = ((LeafNode) list6Child.get("leaf11"));
368 assertThat(l.uri(), is("test-yang:cont1.cont2.list6[0].leaf11"));
369 list6 = ((MultiInstanceNode) list6Holder.child("1"));
370 assertThat(list6.uri(), is("test-yang:cont1.cont2.list6[1]"));
371 list6Child = list6.children();
372 assertThat(list6Child.containsKey("leaf11"), is(true));
373 l = ((LeafNode) list6Child.get("leaf11"));
374 assertThat(l.uri(), is("test-yang:cont1.cont2.list6[1].leaf11"));
376 assertThat(childNodes.containsKey("leaf12"), is(true));
377 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf12"));
378 assertThat(leaf12.name(), is("leaf12"));
379 assertThat(leaf12.uri(), is("test-yang:cont1.cont2.leaf12"));
381 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll5"));
382 assertThat(ll5Holder.uri(), is("test-yang:cont1.cont2.ll5"));
383 assertThat(ll5Holder.children().containsKey("0"), is(true));
384 l = ((LeafNode) ll5Holder.children().get("0"));
385 assertThat(l.uri(), is("test-yang:cont1.cont2.ll5[0]"));
386 assertThat(ll5Holder.children().containsKey("1"), is(true));
387 l = ((LeafNode) ll5Holder.children().get("1"));
388 assertThat(l.uri(), is("test-yang:cont1.cont2.ll5[1]"));
390 Map<String, String> output = ser.decode(node);
391 for (Map.Entry<String, String> entry : output.entrySet()) {
392 assertTrue(params.containsKey(entry.getKey()));
397 public void testChoiceCase1() throws SvcLogicException {
398 String uri = "test-yang:cont8";
399 Map<String, String> params = new HashMap<>();
400 params.put("test-yang:cont8.cont6.leaf16", "abc");
401 params.put("test-yang:cont8.list8[0].leaf18", "abc");
402 params.put("test-yang:cont8.list8[1].leaf18", "abc");
403 params.put("test-yang:cont8.leaf19", "abc");
404 params.put("test-yang:cont8.ll7[0]", "abc");
405 params.put("test-yang:cont8.ll7[1]", "abc");
407 InstanceIdentifierContext<?> iCtx = ParserIdentifier
408 .toInstanceIdentifier(uri, context, null);
409 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
410 iCtx.getSchemaNode(), context, uri);
411 PropertiesNode node = ser.encode(params);
413 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
415 assertThat(childNodes.containsKey("cont6"), is(true));
416 SingleInstanceNode cont6 = ((SingleInstanceNode) childNodes.get("cont6"));
417 assertThat(cont6.uri(), is("test-yang:cont8.cont6"));
418 assertThat(cont6.children().containsKey("leaf16"), is(true));
419 LeafNode l = ((LeafNode) cont6.children().get("leaf16"));
420 assertThat(l.uri(), is("test-yang:cont8.cont6.leaf16"));
422 assertThat(childNodes.containsKey("list8"), is(true));
423 HolderNode list6Holder = ((ListHolderNode) childNodes.get("list8"));
424 assertThat(list6Holder.uri(), is("test-yang:cont8.list8"));
425 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
426 assertThat(list6.uri(), is("test-yang:cont8.list8[0]"));
427 Map<String, DataNodeChild> list6Child = list6.children();
428 assertThat(list6Child.containsKey("leaf18"), is(true));
429 l = ((LeafNode) list6Child.get("leaf18"));
430 assertThat(l.uri(), is("test-yang:cont8.list8[0].leaf18"));
431 list6 = ((MultiInstanceNode) list6Holder.child("1"));
432 list6Child = list6.children();
433 assertThat(list6Child.containsKey("leaf18"), is(true));
434 l = ((LeafNode) list6Child.get("leaf18"));
435 assertThat(l.uri(), is("test-yang:cont8.list8[1].leaf18"));
437 assertThat(childNodes.containsKey("leaf19"), is(true));
438 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf19"));
439 assertThat(leaf12.name(), is("leaf19"));
440 assertThat(leaf12.uri(), is("test-yang:cont8.leaf19"));
442 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll7"));
443 assertThat(ll5Holder.uri(), is("test-yang:cont8.ll7"));
444 assertThat(ll5Holder.children().containsKey("0"), is(true));
445 l = ((LeafNode) ll5Holder.children().get("0"));
446 assertThat(l.uri(), is("test-yang:cont8.ll7[0]"));
447 assertThat(ll5Holder.children().containsKey("1"), is(true));
448 l = ((LeafNode) ll5Holder.children().get("1"));
449 assertThat(l.uri(), is("test-yang:cont8.ll7[1]"));
451 Map<String, String> output = ser.decode(node);
452 assertThat(output.size(), is(params.size()));
453 for (Map.Entry<String, String> entry : output.entrySet()) {
454 assertTrue(params.containsKey(entry.getKey()));
459 public void testChoiceCase2() throws SvcLogicException {
460 String uri = "test-yang:cont9";
461 Map<String, String> params = new HashMap<>();
462 params.put("test-yang:cont9.leaf20", "abc");
463 params.put("test-yang:cont9.ll8[0]", "abc");
464 params.put("test-yang:cont9.cont11.leaf25", "abc");
466 InstanceIdentifierContext<?> iCtx = ParserIdentifier
467 .toInstanceIdentifier(uri, context, null);
468 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
469 iCtx.getSchemaNode(), context, uri);
470 PropertiesNode node = ser.encode(params);
472 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
474 assertThat(childNodes.containsKey("cont11"), is(true));
475 SingleInstanceNode cont4 = ((SingleInstanceNode) childNodes.get("cont11"));
476 assertThat(cont4.uri(), is("test-yang:cont9.cont11"));
477 assertThat(cont4.children().containsKey("leaf25"), is(true));
478 LeafNode l = ((LeafNode) cont4.children().get("leaf25"));
479 assertThat(l.uri(), is("test-yang:cont9.cont11.leaf25"));
481 assertThat(childNodes.containsKey("leaf20"), is(true));
482 l = ((LeafNode) childNodes.get("leaf20"));
483 assertThat(l.uri(), is("test-yang:cont9.leaf20"));
485 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll8"));
486 assertThat(ll5Holder.uri(), is("test-yang:cont9.ll8"));
487 assertThat(ll5Holder.children().containsKey("0"), is(true));
488 l = ((LeafNode) ll5Holder.children().get("0"));
489 assertThat(l.uri(), is("test-yang:cont9.ll8[0]"));
491 Map<String, String> output = ser.decode(node);
492 assertThat(output.size(), is(params.size()));
493 for (Map.Entry<String, String> entry : output.entrySet()) {
494 assertTrue(params.containsKey(entry.getKey()));
499 public void testChoiceCase3() throws SvcLogicException {
500 String uri = "test-yang:cont8/cont6";
501 Map<String, String> params = new HashMap<>();
502 params.put("test-yang:cont8.cont6.test-augment:leaf21", "abc");
504 InstanceIdentifierContext<?> iCtx = ParserIdentifier
505 .toInstanceIdentifier(uri, context, null);
506 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
507 iCtx.getSchemaNode(), context, uri);
508 PropertiesNode node = ser.encode(params);
510 for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
511 : node.augmentations().asMap().entrySet()) {
512 Collection<PropertiesNode> child = augToChild.getValue();
513 if (!child.isEmpty()) {
514 List<String> expectedNodes = new LinkedList<>();
515 expectedNodes.add("test-yang:cont8.cont6.test-augment:leaf21");
516 assertThat(expectedNodes.size(), is(child.size()));
517 for (PropertiesNode pNode : child) {
518 assertThat(expectedNodes.contains(pNode.uri()), is(true));
523 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
525 assertThat(childNodes.containsKey("leaf21"), is(true));
526 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf21"));
527 assertThat(leaf12.name(), is("leaf21"));
528 assertThat(leaf12.uri(), is("test-yang:cont8.cont6.test-augment:leaf21"));
530 Map<String, String> output = ser.decode(node);
531 assertThat(output.size(), is(params.size()));
532 for (Map.Entry<String, String> entry : output.entrySet()) {
533 assertTrue(params.containsKey(entry.getKey()));
538 public void testGrouping() throws SvcLogicException {
539 String uri = "test-yang:cont13";
540 Map<String, String> params = new HashMap<>();
541 params.put("test-yang:cont13.cont12.leaf26", "abc");
542 params.put("test-yang:cont13.list9[0].leaf27", "abc");
543 params.put("test-yang:cont13.leaf28", "abc");
544 params.put("test-yang:cont13.ll9[0]", "abc");
546 InstanceIdentifierContext<?> iCtx = ParserIdentifier
547 .toInstanceIdentifier(uri, context, null);
548 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
549 iCtx.getSchemaNode(), context, uri);
550 PropertiesNode node = ser.encode(params);
552 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
554 assertThat(childNodes.containsKey("cont12"), is(true));
555 SingleInstanceNode cont4 = ((SingleInstanceNode) childNodes.get("cont12"));
556 assertThat(cont4.uri(), is("test-yang:cont13.cont12"));
557 assertThat(cont4.children().containsKey("leaf26"), is(true));
558 LeafNode l = ((LeafNode) cont4.children().get("leaf26"));
559 assertThat(l.uri(), is("test-yang:cont13.cont12.leaf26"));
561 assertThat(childNodes.containsKey("list9"), is(true));
562 HolderNode list6Holder = ((ListHolderNode) childNodes.get("list9"));
563 assertThat(list6Holder.uri(), is("test-yang:cont13.list9"));
564 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
565 assertThat(list6.uri(), is("test-yang:cont13.list9[0]"));
566 Map<String, DataNodeChild> list6Child = list6.children();
567 assertThat(list6Child.containsKey("leaf27"), is(true));
568 l = ((LeafNode) list6Child.get("leaf27"));
569 assertThat(l.uri(), is("test-yang:cont13.list9[0].leaf27"));
571 assertThat(childNodes.containsKey("leaf28"), is(true));
572 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf28"));
573 assertThat(leaf12.name(), is("leaf28"));
574 assertThat(leaf12.uri(), is("test-yang:cont13.leaf28"));
576 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll9"));
577 assertThat(ll5Holder.children().containsKey("0"), is(true));
579 Map<String, String> output = ser.decode(node);
580 assertThat(output.size(), is(params.size()));
581 for (Map.Entry<String, String> entry : output.entrySet()) {
582 assertTrue(params.containsKey(entry.getKey()));
587 public void testGrouping2() throws SvcLogicException {
588 String uri = "test-yang:cont9/cont11";
589 Map<String, String> params = new HashMap<>();
590 params.put("test-yang:cont9.cont11.leaf25", "abc");
591 params.put("test-yang:cont9.cont11.cont13.cont12.leaf26", "abc");
592 params.put("test-yang:cont9.cont11.cont13.list9[0].leaf27", "abc");
593 params.put("test-yang:cont9.cont11.cont13.leaf28", "abc");
594 params.put("test-yang:cont9.cont11.cont13.ll9[0]", "abc");
595 InstanceIdentifierContext<?> iCtx = ParserIdentifier
596 .toInstanceIdentifier(uri, context, null);
597 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
598 iCtx.getSchemaNode(), context, uri);
599 PropertiesNode node = ser.encode(params);
601 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
603 assertThat(childNodes.containsKey("cont13"), is(true));
604 SingleInstanceNode cont13 = ((SingleInstanceNode) childNodes.get("cont13"));
605 assertThat(cont13.uri(), is("test-yang:cont9.cont11.cont13"));
606 SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
607 assertThat(cont12.children().containsKey("leaf26"), is(true));
608 assertThat(cont12.uri(), is("test-yang:cont9.cont11.cont13.cont12"));
609 assertThat(cont12.children().containsKey("leaf26"), is(true));
610 LeafNode l = ((LeafNode) cont12.children().get("leaf26"));
611 assertThat(l.uri(), is("test-yang:cont9.cont11.cont13.cont12.leaf26"));
613 assertThat(cont13.children().containsKey("list9"), is(true));
614 HolderNode list6Holder = ((ListHolderNode) cont13.children().get("list9"));
615 assertThat(list6Holder.uri(), is("test-yang:cont9.cont11.cont13.list9"));
616 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
617 assertThat(list6.uri(), is("test-yang:cont9.cont11.cont13.list9[0]"));
618 Map<String, DataNodeChild> list6Child = list6.children();
619 assertThat(list6Child.containsKey("leaf27"), is(true));
620 l = ((LeafNode) list6Child.get("leaf27"));
621 assertThat(l.uri(), is("test-yang:cont9.cont11.cont13.list9[0].leaf27"));
623 assertThat(cont13.children().containsKey("leaf28"), is(true));
624 LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
625 assertThat(leaf12.name(), is("leaf28"));
626 assertThat(leaf12.uri(), is("test-yang:cont9.cont11.cont13.leaf28"));
628 LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
629 assertThat(ll5Holder.uri(), is("test-yang:cont9.cont11.cont13.ll9"));
630 assertThat(ll5Holder.children().containsKey("0"), is(true));
631 l = ((LeafNode) ll5Holder.children().get("0"));
632 assertThat(l.uri(), is("test-yang:cont9.cont11.cont13.ll9[0]"));
634 Map<String, String> output = ser.decode(node);
635 assertThat(output.size(), is(params.size()));
636 for (Map.Entry<String, String> entry : output.entrySet()) {
637 assertTrue(params.containsKey(entry.getKey()));
642 public void testGrouping3() throws SvcLogicException {
643 String uri = "test-augment:cont13";
644 Map<String, String> params = new HashMap<>();
645 params.put("test-augment:cont13.cont12.leaf26", "abc");
646 params.put("test-augment:cont13.list9[0].leaf27", "abc");
647 params.put("test-augment:cont13.leaf28", "abc");
648 params.put("test-augment:cont13.ll9[0]", "abc");
649 InstanceIdentifierContext<?> iCtx = ParserIdentifier
650 .toInstanceIdentifier(uri, context, null);
651 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
652 iCtx.getSchemaNode(), context, uri);
653 PropertiesNode node = ser.encode(params);
655 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
657 assertThat(childNodes.containsKey("cont12"), is(true));
658 SingleInstanceNode cont12 = ((SingleInstanceNode) childNodes.get("cont12"));
659 assertThat(cont12.uri(), is("test-augment:cont13.cont12"));
660 assertThat(cont12.children().containsKey("leaf26"), is(true));
661 LeafNode l = ((LeafNode) cont12.children().get("leaf26"));
662 assertThat(l.uri(), is("test-augment:cont13.cont12.leaf26"));
664 assertThat(childNodes.containsKey("list9"), is(true));
665 HolderNode list6Holder = ((ListHolderNode) childNodes.get("list9"));
666 assertThat(list6Holder.uri(), is("test-augment:cont13.list9"));
667 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
668 assertThat(list6.uri(), is("test-augment:cont13.list9[0]"));
669 Map<String, DataNodeChild> list6Child = list6.children();
670 assertThat(list6Child.containsKey("leaf27"), is(true));
671 l = ((LeafNode) list6Child.get("leaf27"));
672 assertThat(l.uri(), is("test-augment:cont13.list9[0].leaf27"));
674 assertThat(childNodes.containsKey("leaf28"), is(true));
675 LeafNode leaf12 = ((LeafNode) childNodes.get("leaf28"));
676 assertThat(leaf12.name(), is("leaf28"));
677 assertThat(leaf12.uri(), is("test-augment:cont13.leaf28"));
679 LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll9"));
680 assertThat(ll5Holder.uri(), is("test-augment:cont13.ll9"));
681 assertThat(ll5Holder.children().containsKey("0"), is(true));
682 l = ((LeafNode) ll5Holder.children().get("0"));
683 assertThat(l.uri(), is("test-augment:cont13.ll9[0]"));
685 Map<String, String> output = ser.decode(node);
686 assertThat(output.size(), is(params.size()));
687 for (Map.Entry<String, String> entry : output.entrySet()) {
688 assertTrue(params.containsKey(entry.getKey()));
693 public void testGrouping4() throws SvcLogicException {
694 String uri = "test-yang:cont1/cont2/cont4";
695 Map<String, String> params = new HashMap<>();
696 params.put("test-yang:cont1.cont2.cont4.test-augment:cont13.cont12.leaf26", "abc");
697 params.put("test-yang:cont1.cont2.cont4.test-augment:cont13.list9[0].leaf27", "abc");
698 params.put("test-yang:cont1.cont2.cont4.test-augment:cont13.leaf28", "abc");
699 params.put("test-yang:cont1.cont2.cont4.test-augment:cont13.ll9[0]", "abc");
701 InstanceIdentifierContext<?> iCtx = ParserIdentifier
702 .toInstanceIdentifier(uri, context, null);
703 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
704 iCtx.getSchemaNode(), context, uri);
705 PropertiesNode node = ser.encode(params);
707 for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
708 : node.augmentations().asMap().entrySet()) {
709 Collection<PropertiesNode> child = augToChild.getValue();
710 if (!child.isEmpty()) {
711 List<String> expectedNodes = new LinkedList<>();
712 expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:cont13");
713 assertThat(expectedNodes.size(), is(child.size()));
714 for (PropertiesNode pNode : child) {
715 assertThat(expectedNodes.contains(pNode.uri()), is(true));
716 SingleInstanceNode cont13 = ((SingleInstanceNode) pNode);
717 assertThat(cont13.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13"));
718 SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
719 assertThat(cont12.children().containsKey("leaf26"), is(true));
720 LeafNode l = ((LeafNode) cont12.children().get("leaf26"));
721 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.cont12.leaf26"));
723 assertThat(cont13.children().containsKey("list9"), is(true));
724 HolderNode list6Holder = ((ListHolderNode) cont13.children().get("list9"));
725 assertThat(list6Holder.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.list9"));
726 MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
727 assertThat(list6.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.list9[0]"));
728 Map<String, DataNodeChild> list6Child = list6.children();
729 assertThat(list6Child.containsKey("leaf27"), is(true));
730 l = ((LeafNode) list6Child.get("leaf27"));
731 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.list9[0].leaf27"));
733 assertThat(cont13.children().containsKey("leaf28"), is(true));
734 LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
735 assertThat(leaf12.name(), is("leaf28"));
736 assertThat(leaf12.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.leaf28"));
738 LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
739 assertThat(ll5Holder.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.ll9"));
740 assertThat(ll5Holder.children().containsKey("0"), is(true));
741 l = ((LeafNode) ll5Holder.children().get("0"));
742 assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.ll9[0]"));
747 Map<String, String> output = ser.decode(node);
748 assertThat(output.size(), is(params.size()));
749 for (Map.Entry<String, String> entry : output.entrySet()) {
750 assertTrue(params.containsKey(entry.getKey()));
755 public void testRpcInput() throws SvcLogicException {
756 String uri = "test-yang:create-sfc";
757 Map<String, String> params = new HashMap<>();
758 params.put("test-yang:create-sfc.input.cont14.leaf28", "abc");
759 params.put("test-yang:create-sfc.input.list10[0].leaf29", "abc");
760 params.put("test-yang:create-sfc.input.leaf30", "abc");
761 params.put("test-yang:create-sfc.input.ll10[0]", "abc");
762 params.put("test-yang:create-sfc.input.cont15.leaf31", "abc");
763 params.put("test-yang:create-sfc.input.cont13.cont12.leaf26", "abc");
764 params.put("test-yang:create-sfc.input.cont13.list9[0].leaf27", "abc");
765 params.put("test-yang:create-sfc.input.cont13.leaf28", "abc");
766 params.put("test-yang:create-sfc.input.cont13.ll9[0]", "abc");
767 params.put("test-yang:create-sfc.input.test-augment:leaf36", "abc");
769 InstanceIdentifierContext<?> iCtx = ParserIdentifier
770 .toInstanceIdentifier(uri, context, null);
771 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
772 iCtx.getSchemaNode(), context, uri);
773 PropertiesNode node = ser.encode(params);
775 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
777 PropertiesNode input = childNodes.get("input");
778 assertThat(input.uri(), is("test-yang:create-sfc.input"));
779 for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
780 : node.augmentations().asMap().entrySet()) {
781 Collection<PropertiesNode> child = augToChild.getValue();
782 if (!child.isEmpty()) {
783 List<String> expectedNodes = new LinkedList<>();
784 expectedNodes.add("test-yang:create-sfc.input.test-augment:leaf36");
785 assertThat(expectedNodes.size(), is(child.size()));
786 for (PropertiesNode pNode : child) {
787 assertThat(expectedNodes.contains(pNode.uri()), is(true));
788 LeafNode leaf37 = ((LeafNode) pNode);
789 assertThat(leaf37.name(), is("leaf36"));
790 assertThat(leaf37.uri(), is("test-yang:create-sfc.input.test-augment:leaf36"));
794 childNodes = ((InnerNode) input).children();
796 assertThat(childNodes.containsKey("cont14"), is(true));
797 SingleInstanceNode cont14 = ((SingleInstanceNode) childNodes.get("cont14"));
798 assertThat(cont14.uri(), is("test-yang:create-sfc.input.cont14"));
799 assertThat(cont14.children().containsKey("leaf28"), is(true));
800 LeafNode l = ((LeafNode) cont14.children().get("leaf28"));
801 assertThat(l.uri(), is("test-yang:create-sfc.input.cont14.leaf28"));
803 assertThat(childNodes.containsKey("list10"), is(true));
804 HolderNode list10Holder = ((ListHolderNode) childNodes.get("list10"));
805 assertThat(list10Holder.uri(), is("test-yang:create-sfc.input.list10"));
806 MultiInstanceNode list10 = ((MultiInstanceNode) list10Holder.child("0"));
807 assertThat(list10.uri(), is("test-yang:create-sfc.input.list10[0]"));
808 Map<String, DataNodeChild> list10Child = list10.children();
809 assertThat(list10Child.containsKey("leaf29"), is(true));
810 l = ((LeafNode) list10Child.get("leaf29"));
811 assertThat(l.uri(), is("test-yang:create-sfc.input.list10[0].leaf29"));
813 assertThat(childNodes.containsKey("leaf30"), is(true));
814 LeafNode leaf30 = ((LeafNode) childNodes.get("leaf30"));
815 assertThat(leaf30.name(), is("leaf30"));
816 assertThat(leaf30.uri(), is("test-yang:create-sfc.input.leaf30"));
818 LeafListHolderNode ll10Holder = ((LeafListHolderNode) childNodes.get("ll10"));
819 assertThat(ll10Holder.uri(), is("test-yang:create-sfc.input.ll10"));
820 assertThat(ll10Holder.children().containsKey("0"), is(true));
821 l = ((LeafNode) ll10Holder.children().get("0"));
822 assertThat(l.uri(), is("test-yang:create-sfc.input.ll10[0]"));
824 assertThat(childNodes.containsKey("cont15"), is(true));
825 SingleInstanceNode cont15 = ((SingleInstanceNode) childNodes.get("cont15"));
826 assertThat(cont15.uri(), is("test-yang:create-sfc.input.cont15"));
827 assertThat(cont15.children().containsKey("leaf31"), is(true));
828 l = ((LeafNode) cont15.children().get("leaf31"));
829 assertThat(l.uri(), is("test-yang:create-sfc.input.cont15.leaf31"));
831 assertThat(childNodes.containsKey("cont13"), is(true));
832 SingleInstanceNode cont13 = ((SingleInstanceNode) childNodes.get("cont13"));
833 assertThat(cont13.uri(), is("test-yang:create-sfc.input.cont13"));
834 SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
835 assertThat(cont12.uri(), is("test-yang:create-sfc.input.cont13.cont12"));
836 assertThat(cont12.children().containsKey("leaf26"), is(true));
837 l = ((LeafNode) cont12.children().get("leaf26"));
838 assertThat(l.uri(), is("test-yang:create-sfc.input.cont13.cont12.leaf26"));
840 assertThat(cont13.children().containsKey("list9"), is(true));
841 HolderNode list9Holder = ((ListHolderNode) cont13.children().get("list9"));
842 assertThat(list9Holder.uri(), is("test-yang:create-sfc.input.cont13.list9"));
843 MultiInstanceNode list9 = ((MultiInstanceNode) list9Holder.child("0"));
844 assertThat(list9.uri(), is("test-yang:create-sfc.input.cont13.list9[0]"));
845 Map<String, DataNodeChild> list6Child = list9.children();
846 assertThat(list6Child.containsKey("leaf27"), is(true));
847 l = ((LeafNode) list6Child.get("leaf27"));
848 assertThat(l.uri(), is("test-yang:create-sfc.input.cont13.list9[0].leaf27"));
850 assertThat(cont13.children().containsKey("leaf28"), is(true));
851 LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
852 assertThat(leaf12.name(), is("leaf28"));
853 assertThat(leaf12.uri(), is("test-yang:create-sfc.input.cont13.leaf28"));
855 LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
856 assertThat(ll5Holder.uri(), is("test-yang:create-sfc.input.cont13.ll9"));
857 assertThat(ll5Holder.children().containsKey("0"), is(true));
858 l = ((LeafNode) ll5Holder.children().get("0"));
859 assertThat(l.uri(), is("test-yang:create-sfc.input.cont13.ll9[0]"));
861 Map<String, String> output = ser.decode(node);
862 assertThat(output.size(), is(params.size()));
863 for (Map.Entry<String, String> entry : output.entrySet()) {
864 assertTrue(params.containsKey(entry.getKey()));
869 public void testRpcOutput() throws SvcLogicException {
870 String uri = "test-yang:create-sfc";
871 Map<String, String> params = new HashMap<>();
872 params.put("test-yang:create-sfc.output.cont16.leaf32", "abc");
873 params.put("test-yang:create-sfc.output.list11[0].leaf33", "abc");
874 params.put("test-yang:create-sfc.output.leaf34", "abc");
875 params.put("test-yang:create-sfc.output.ll11[0]", "abc");
876 params.put("test-yang:create-sfc.output.cont17.leaf35", "abc");
877 params.put("test-yang:create-sfc.output.cont13.cont12.leaf26", "abc");
878 params.put("test-yang:create-sfc.output.cont13.list9[0].leaf27", "abc");
879 params.put("test-yang:create-sfc.output.cont13.leaf28", "abc");
880 params.put("test-yang:create-sfc.output.cont13.ll9[0]", "abc");
881 params.put("test-yang:create-sfc.output.test-augment:leaf37", "abc");
883 InstanceIdentifierContext<?> iCtx = ParserIdentifier
884 .toInstanceIdentifier(uri, context, null);
885 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
886 iCtx.getSchemaNode(), context, uri);
887 PropertiesNode node = ser.encode(params);
889 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
891 PropertiesNode output = childNodes.get("output");
892 assertThat(output.uri(), is("test-yang:create-sfc.output"));
893 for (Map.Entry<Object, Collection<PropertiesNode>> augmentationToChild :
894 node.augmentations().asMap().entrySet()) {
895 Collection<PropertiesNode> c = augmentationToChild.getValue();
897 List<String> expectedNodes = new LinkedList<>();
898 expectedNodes.add("test-yang:create-sfc.output.test-augment:leaf37");
899 assertThat(expectedNodes.size(), is(expectedNodes));
900 for (PropertiesNode pNode : c) {
901 assertThat(expectedNodes.contains(pNode.uri()), is(true));
902 LeafNode leaf37 = ((LeafNode) pNode);
903 assertThat(leaf37.name(), is("leaf37"));
904 assertThat(leaf37.uri(), is("test-yang:create-sfc.output.test-augment:leaf37"));
908 childNodes = ((InnerNode) output).children();
910 assertThat(childNodes.containsKey("cont16"), is(true));
911 SingleInstanceNode cont16 = ((SingleInstanceNode) childNodes.get("cont16"));
912 assertThat(cont16.uri(), is("test-yang:create-sfc.output.cont16"));
913 assertThat(cont16.children().containsKey("leaf32"), is(true));
914 LeafNode l = ((LeafNode) cont16.children().get("leaf32"));
915 assertThat(l.uri(), is("test-yang:create-sfc.output.cont16.leaf32"));
917 assertThat(childNodes.containsKey("list11"), is(true));
918 HolderNode list11Holder = ((ListHolderNode) childNodes.get("list11"));
919 assertThat(list11Holder.uri(), is("test-yang:create-sfc.output.list11"));
920 MultiInstanceNode list11 = ((MultiInstanceNode) list11Holder.child("0"));
921 assertThat(list11.uri(), is("test-yang:create-sfc.output.list11[0]"));
922 Map<String, DataNodeChild> list11Child = list11.children();
923 assertThat(list11Child.containsKey("leaf33"), is(true));
924 l = ((LeafNode) list11Child.get("leaf33"));
925 assertThat(l.uri(), is("test-yang:create-sfc.output.list11[0].leaf33"));
927 assertThat(childNodes.containsKey("leaf34"), is(true));
928 LeafNode leaf34 = ((LeafNode) childNodes.get("leaf34"));
929 assertThat(leaf34.name(), is("leaf34"));
930 assertThat(leaf34.uri(), is("test-yang:create-sfc.output.leaf34"));
932 LeafListHolderNode ll10Holder = ((LeafListHolderNode) childNodes.get("ll11"));
933 assertThat(ll10Holder.uri(), is("test-yang:create-sfc.output.ll11"));
934 assertThat(ll10Holder.children().containsKey("0"), is(true));
935 l = ((LeafNode) ll10Holder.children().get("0"));
936 assertThat(l.uri(), is("test-yang:create-sfc.output.ll11[0]"));
938 assertThat(childNodes.containsKey("cont17"), is(true));
939 SingleInstanceNode cont17 = ((SingleInstanceNode) childNodes.get("cont17"));
940 assertThat(cont17.uri(), is("test-yang:create-sfc.output.cont17"));
941 assertThat(cont17.children().containsKey("leaf35"), is(true));
942 l = ((LeafNode) cont17.children().get("leaf35"));
943 assertThat(l.uri(), is("test-yang:create-sfc.output.cont17.leaf35"));
945 assertThat(childNodes.containsKey("cont13"), is(true));
946 SingleInstanceNode cont13 = ((SingleInstanceNode) childNodes.get("cont13"));
947 assertThat(cont13.uri(), is("test-yang:create-sfc.output.cont13"));
948 SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
949 assertThat(cont12.uri(), is("test-yang:create-sfc.output.cont13.cont12"));
950 assertThat(cont12.children().containsKey("leaf26"), is(true));
951 l = ((LeafNode) cont12.children().get("leaf26"));
952 assertThat(l.uri(), is("test-yang:create-sfc.output.cont13.cont12.leaf26"));
954 assertThat(cont13.children().containsKey("list9"), is(true));
955 HolderNode list9Holder = ((ListHolderNode) cont13.children().get("list9"));
956 assertThat(list9Holder.uri(), is("test-yang:create-sfc.output.cont13.list9"));
957 MultiInstanceNode list9 = ((MultiInstanceNode) list9Holder.child("0"));
958 assertThat(list9.uri(), is("test-yang:create-sfc.output.cont13.list9[0]"));
959 Map<String, DataNodeChild> list6Child = list9.children();
960 assertThat(list6Child.containsKey("leaf27"), is(true));
961 l = ((LeafNode) list6Child.get("leaf27"));
962 assertThat(l.uri(), is("test-yang:create-sfc.output.cont13.list9[0].leaf27"));
964 assertThat(cont13.children().containsKey("leaf28"), is(true));
965 LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
966 assertThat(leaf12.name(), is("leaf28"));
967 assertThat(leaf12.uri(), is("test-yang:create-sfc.output.cont13.leaf28"));
969 LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
970 assertThat(ll5Holder.uri(), is("test-yang:create-sfc.output.cont13.ll9"));
971 assertThat(ll5Holder.children().containsKey("0"), is(true));
972 l = ((LeafNode) ll5Holder.children().get("0"));
973 assertThat(l.uri(), is("test-yang:create-sfc.output.cont13.ll9[0]"));
975 Map<String, String> output1 = ser.decode(node);
976 assertThat(output1.size(), is(params.size()));
977 for (Map.Entry<String, String> entry : output1.entrySet()) {
978 assertTrue(params.containsKey(entry.getKey()));
983 public void testContainerSameName() throws SvcLogicException {
984 String uri = "test-yang:cont18";
985 Map<String, String> params = new HashMap<>();
986 params.put("test-yang:cont18.cont18.list12[0].list12[0].leaf36", "abc");
987 params.put("test-yang:cont18.cont18.list12[0].leaf36", "hi");
988 params.put("test-yang:cont18.cont18.list12[1].list12[0].leaf36", "xyz");
989 params.put("test-yang:cont18.cont18.list12[1].list12[1].leaf36", "hey!");
991 InstanceIdentifierContext<?> iCtx = ParserIdentifier
992 .toInstanceIdentifier(uri, context, null);
993 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
994 iCtx.getSchemaNode(), context, uri);
995 PropertiesNode node = ser.encode(params);
997 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
999 assertThat(childNodes.containsKey("cont18"), is(true));
1000 node = childNodes.get("cont18");
1001 assertThat(node.uri(), is("test-yang:cont18.cont18"));
1002 childNodes = ((InnerNode) node).children();
1004 assertThat(childNodes.containsKey("list12"), is(true));
1005 HolderNode holder = ((ListHolderNode) childNodes.get("list12"));
1006 assertThat(holder.uri(), is("test-yang:cont18.cont18.list12"));
1007 MultiInstanceNode node1 = ((MultiInstanceNode) holder.child("0"));
1008 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[0]"));
1009 Map<String, DataNodeChild> list12Child = node1.children();
1011 assertThat(list12Child.containsKey("leaf36"), is(true));
1012 LeafNode leaf = ((LeafNode) list12Child.get("leaf36"));
1013 assertThat(leaf.value(), is("hi"));
1014 assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[0].leaf36"));
1016 assertThat(list12Child.containsKey("list12"), is(true));
1017 HolderNode holder1 = ((ListHolderNode) list12Child.get("list12"));
1018 assertThat(holder1.uri(), is("test-yang:cont18.cont18.list12[0].list12"));
1019 node1 = ((MultiInstanceNode) holder1.child("0"));
1020 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[0].list12[0]"));
1021 list12Child = node1.children();
1022 assertThat(list12Child.containsKey("leaf36"), is(true));
1023 leaf = ((LeafNode) list12Child.get("leaf36"));
1024 assertThat(leaf.value(), is("abc"));
1025 assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[0].list12[0].leaf36"));
1027 node1 = ((MultiInstanceNode) holder.child("1"));
1028 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[1]"));
1029 list12Child = node1.children();
1030 assertThat(list12Child.containsKey("list12"), is(true));
1031 holder = ((ListHolderNode) list12Child.get("list12"));
1032 assertThat(holder.uri(), is("test-yang:cont18.cont18.list12[1].list12"));
1033 node1 = ((MultiInstanceNode) holder.child("0"));
1034 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[1].list12[0]"));
1035 assertThat(node1.children().containsKey("leaf36"), is(true));
1036 leaf = ((LeafNode) node1.children().get("leaf36"));
1037 assertThat(leaf.value(), is("xyz"));
1038 assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[1].list12[0].leaf36"));
1040 node1 = ((MultiInstanceNode) holder.child("1"));
1041 assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[1].list12[1]"));
1042 assertThat(node1.children().containsKey("leaf36"), is(true));
1043 leaf = ((LeafNode) node1.children().get("leaf36"));
1044 assertThat(leaf.value(), is("hey!"));
1045 assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[1].list12[1].leaf36"));
1047 Map<String, String> output1 = ser.decode(node);
1048 assertThat(output1.size(), is(params.size()));
1049 for (Map.Entry<String, String> entry : output1.entrySet()) {
1050 assertTrue(params.containsKey(entry.getKey()));
1055 public void testPropertiesWithoutSchema() throws SvcLogicException {
1056 String uri = "test-yang:cont18";
1057 Map<String, String> params = new HashMap<>();
1058 params.put("test-yang:cont18.leaf40", "abc");
1059 params.put("leaf41", "hi");
1060 params.put("test-yang:cont18.leaf41", "abc");
1062 InstanceIdentifierContext<?> iCtx = ParserIdentifier
1063 .toInstanceIdentifier(uri, context, null);
1064 PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
1065 iCtx.getSchemaNode(), context, uri);
1066 PropertiesNode node = ser.encode(params);
1068 Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
1069 assertThat(childNodes.containsKey("leaf40"), is(true));
1070 node = childNodes.get("leaf40");
1071 assertThat(node.uri(), is("test-yang:cont18.leaf40"));
1074 public static SchemaContext compileYangFile() throws FileNotFoundException {
1075 String path = PropertiesSerializerTest.class.getResource("/yang").getPath();
1076 File dir = new File(path);
1077 String[] fileList = dir.list();
1078 List<File> yangFiles = new ArrayList<File>();
1079 if (fileList == null) {
1080 throw new FileNotFoundException("/yang");
1082 for (int i = 0; i < fileList.length; i++) {
1083 final String fileName = fileList[i];
1084 if (new File(dir, fileName).isDirectory() == false) {
1085 yangFiles.add(new File(dir, fileName));
1088 return YangParserTestUtils.parseYangFiles(yangFiles);