Resolving root level augment nodes
[ccsdk/sli/plugins.git] / restconf-client / provider / src / test / java / org / onap / ccsdk / sli / plugins / yangserializers / dfserializer / DataFormatSerializerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - CCSDK
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.invocation.InvocationOnMock;
26 import org.mockito.stubbing.Answer;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
29 import org.onap.ccsdk.sli.plugins.restapicall.HttpResponse;
30 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
31 import org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiCallNode;
32 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
33
34 import java.util.HashMap;
35 import java.util.Map;
36
37 import static org.hamcrest.MatcherAssert.assertThat;
38 import static org.hamcrest.core.Is.is;
39 import static org.mockito.Matchers.any;
40 import static org.mockito.Mockito.doAnswer;
41 import static org.mockito.Mockito.doCallRealMethod;
42 import static org.mockito.Mockito.doReturn;
43 import static org.mockito.Mockito.mock;
44 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.GET;
45 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.POST;
46 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PUT;
47 import static org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiUtils.parseUrl;
48 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_FROM_JSON_RPC;
49 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_FROM_XML_RPC;
50 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_ID;
51 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_RPC;
52 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG;
53 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG_AUG_POST;
54 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_ID;
55 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_RPC;
56 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG;
57
58
59 /**
60  * Unit test cases for data format serialization and restconf api call node.
61  */
62 public class DataFormatSerializerTest {
63
64     private Map<String, String> p;
65
66     private RestconfApiCallNode restconf;
67
68     private RestapiCallNode restApi;
69
70     private DfCaptor dfCaptor;
71
72     /**
73      * Sets up the pre-requisite for each test case.
74      *
75      * @throws SvcLogicException when test case fails
76      */
77     @Before
78     public void setUp() throws SvcLogicException {
79         p = new HashMap<>();
80         p.put("restapiUser", "user1");
81         p.put("restapiPassword", "abc123");
82         p.put("responsePrefix", "response");
83         p.put("skipSending", "true");
84         restApi = new RestapiCallNode();
85         restconf = mock(RestconfApiCallNode.class);
86         dfCaptor = new DfCaptor();
87         createMethodMocks();
88     }
89
90     /**
91      * Creates method mocks using mockito for RestconfApiCallNode class.
92      *
93      * @throws SvcLogicException when test case fails
94      */
95     private void createMethodMocks() throws SvcLogicException {
96         doReturn(restApi).when(restconf).getRestapiCallNode();
97         doCallRealMethod().when(restconf).sendRequest(
98                 any(Map.class), any(SvcLogicContext.class));
99         doCallRealMethod().when(restconf).sendRequest(
100                 any(Map.class), any(SvcLogicContext.class), any(Integer.class));
101         doAnswer(dfCaptor).when(restconf).serializeRequest(
102                 any(Map.class), any(YangParameters.class), any(String.class),
103                 any(InstanceIdentifierContext.class));
104     }
105
106     /**
107      * Creates mock using mockito with input data for decoding.
108      *
109      * @param decodeData input data
110      * @throws SvcLogicException when test case fails
111      */
112     private void createMockForDecode(String decodeData)
113             throws SvcLogicException {
114         doReturn(decodeData).when(restconf).getResponse(
115                 any(SvcLogicContext.class), any(YangParameters.class),
116                 any(String.class), any(HttpResponse.class));
117         doCallRealMethod().when(restconf).serializeResponse(
118                 any(YangParameters.class), any(String.class), any(String.class),
119                 any(InstanceIdentifierContext.class));
120     }
121
122     /**
123      * Verifies encoding of parameters to JSON data format with identity-ref
124      * and inter-file linking.
125      *
126      * @throws SvcLogicException when test case fails
127      */
128     @Test
129     public void encodeToJsonId() throws SvcLogicException {
130         String pre = "identity-test:test.";
131         SvcLogicContext ctx = createAttList(pre);
132         ctx.setAttribute(pre + "l", "abc");
133         p.put("dirPath", "src/test/resources");
134         p.put("format", "json");
135         p.put("httpMethod", "post");
136         p.put("restapiUrl", "http://echo.getpostman" +
137                 ".com/restconf/operations/identity-test:test");
138         restconf.sendRequest(p, ctx);
139         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID));
140     }
141
142     /**
143      * Verifies encoding of parameters to XML data format with identity-ref
144      * and inter-file linking.
145      *
146      * @throws SvcLogicException when test case fails
147      */
148     @Test
149     public void encodeToXmlId() throws SvcLogicException {
150         String pre = "identity-test:test.";
151         SvcLogicContext ctx = createAttList(pre);
152         p.put("dirPath", "src/test/resources");
153         p.put("format", "xml");
154         p.put("httpMethod", "post");
155         p.put("restapiUrl", "http://echo.getpostman" +
156                 ".com/restconf/operations/identity-test:test");
157         restconf.sendRequest(p, ctx);
158         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID));
159     }
160
161     /**
162      * Verifies decoding of parameters from JSON data format with identity-ref
163      * and inter-file linking.
164      *
165      * @throws SvcLogicException when test case fails
166      */
167     @Test
168     public void decodeToJsonId() throws SvcLogicException {
169         createMockForDecode(ENCODE_TO_JSON_ID);
170         SvcLogicContext ctx = new SvcLogicContext();
171         String pre = "identity-test:test.";
172         p.put("dirPath", "src/test/resources");
173         p.put("format", "json");
174         p.put("httpMethod", "get");
175         p.put("restapiUrl", "http://echo.getpostman" +
176                 ".com/restconf/operations/identity-test:test");
177         restconf.sendRequest(p, ctx);
178         assertThat(ctx.getAttribute(pre + "l"), is("abc"));
179         verifyAttList(ctx, pre);
180     }
181
182     /**
183      * Verifies decoding of parameters from XML data format with identity-ref
184      * and inter-file linking.
185      *
186      * @throws SvcLogicException when test case fails
187      */
188     @Test
189     public void decodeToXmlId() throws SvcLogicException {
190         createMockForDecode(ENCODE_TO_XML_ID);
191         SvcLogicContext ctx = new SvcLogicContext();
192         String pre = "identity-test:test.";
193         p.put("dirPath", "src/test/resources");
194         p.put("format", "xml");
195         p.put("httpMethod", "get");
196         p.put("restapiUrl", "http://echo.getpostman" +
197                 ".com/restconf/operations/identity-test:test");
198         restconf.sendRequest(p, ctx);
199         verifyAttList(ctx, pre);
200     }
201
202     /**
203      * Verifies encoding of parameters to JSON data format with containers,
204      * grouping and augment.
205      *
206      * @throws SvcLogicException when test case fails
207      */
208     @Test
209     public void encodeToJsonYang() throws SvcLogicException {
210         String pre = "test-yang:cont1.cont2.";
211         SvcLogicContext ctx = createAttListYang(pre);
212         p.put("dirPath", "src/test/resources");
213         p.put("format", "json");
214         p.put("httpMethod", "post");
215         p.put("restapiUrl", "http://echo.getpostman" +
216                 ".com/restconf/operations/test-yang:cont1");
217         restconf.sendRequest(p, ctx);
218         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG));
219     }
220
221     /**
222      * Verifies encoding of parameters to JSON data format with augment as
223      * root child.
224      *
225      * @throws SvcLogicException when test case fails
226      */
227     @Test
228     public void encodeToJsonWithAugAsRootChild() throws SvcLogicException {
229         String pre = "test-yang:cont1.cont2.";
230         SvcLogicContext ctx = createAttListYang(pre);
231         p.put("dirPath", "src/test/resources");
232         p.put("format", "json");
233         p.put("httpMethod", "post");
234         p.put("restapiUrl", "http://echo.getpostman" +
235                 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
236         restconf.sendRequest(p, ctx);
237         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_AUG_POST));
238     }
239
240     /**
241      * Verifies decoding of parameters from JSON data format with containers,
242      * grouping and augment.
243      *
244      * @throws SvcLogicException when test case fails
245      */
246     @Test
247     public void decodeToJsonYang() throws SvcLogicException {
248         createMockForDecode(ENCODE_TO_JSON_YANG);
249         SvcLogicContext ctx = new SvcLogicContext();
250         String pre = "test-yang:cont1.cont2.";
251         p.put("dirPath", "src/test/resources");
252         p.put("format", "json");
253         p.put("httpMethod", "get");
254         p.put("restapiUrl", "http://echo.getpostman" +
255                 ".com/restconf/operations/test-yang:cont1");
256         restconf.sendRequest(p, ctx);
257         verifyAttListYang(ctx, pre);
258     }
259
260     /**
261      * Verifies encoding of parameters to XML data format with containers,
262      * grouping and augment.
263      *
264      * @throws SvcLogicException when test case fails
265      */
266     @Test
267     public void encodeToXmlYang() throws SvcLogicException {
268         String pre = "test-yang:cont1.cont2.";
269         SvcLogicContext ctx = createAttListYang(pre);
270         p.put("dirPath", "src/test/resources");
271         p.put("format", "xml");
272         p.put("httpMethod", "post");
273         p.put("restapiUrl", "http://echo.getpostman" +
274                 ".com/restconf/operations/test-yang:cont1");
275         restconf.sendRequest(p, ctx);
276         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG));
277     }
278
279     /**
280      * Verifies decoding of parameters from XML data format with containers,
281      * grouping and augment.
282      *
283      * @throws SvcLogicException when test case fails
284      */
285     @Test
286     public void decodeToXmlYang() throws SvcLogicException {
287         createMockForDecode(ENCODE_TO_XML_YANG);
288         SvcLogicContext ctx = new SvcLogicContext();
289         String pre = "test-yang:cont1.cont2.";
290         p.put("dirPath", "src/test/resources");
291         p.put("format", "xml");
292         p.put("httpMethod", "get");
293         p.put("restapiUrl", "http://echo.getpostman" +
294                 ".com/restconf/operations/test-yang:cont1");
295         restconf.sendRequest(p, ctx);
296         verifyAttListYang(ctx, pre);
297     }
298
299     /**
300      * Verifies encoding of and decoding from, JSON respectively for data
301      * format with containers, grouping and augment.
302      *
303      * @throws SvcLogicException when test case fails
304      */
305     @Test
306     public void codecToJsonRpc() throws SvcLogicException {
307         createMockForDecode(DECODE_FROM_JSON_RPC);
308         String inPre = "test-yang:create-sfc.input.";
309         String outPre = "test-yang:create-sfc.output.";
310         SvcLogicContext ctx = createAttListRpc(inPre);
311         p.put("dirPath", "src/test/resources");
312         p.put("format", "json");
313         p.put("httpMethod", "post");
314         p.put("restapiUrl", "http://echo.getpostman" +
315                 ".com/restconf/operations/test-yang:create-sfc");
316         restconf.sendRequest(p, ctx);
317         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_RPC));
318         verifyAttListRpc(ctx, outPre);
319     }
320
321     /**
322      * Verifies encoding of and decoding from, XML respectively for data
323      * format with containers, grouping and augment.
324      *
325      * @throws SvcLogicException when test case fails
326      */
327     @Test
328     public void codecToXmlRpc() throws SvcLogicException {
329         createMockForDecode(DECODE_FROM_XML_RPC);
330         String inPre = "test-yang:create-sfc.input.";
331         String outPre = "test-yang:create-sfc.output.";
332         SvcLogicContext ctx = createAttListRpc(inPre);
333         p.put("dirPath", "src/test/resources");
334         p.put("format", "xml");
335         p.put("httpMethod", "post");
336         p.put("restapiUrl", "http://echo.getpostman" +
337                 ".com/restconf/operations/test-yang:create-sfc");
338         restconf.sendRequest(p, ctx);
339         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_RPC));
340         verifyAttListRpc(ctx, outPre);
341     }
342
343     /**
344      * Verifies URL parser returning path with only schema information for all
345      * kind of URL.
346      *
347      * @throws SvcLogicException when test case fails
348      */
349     @Test
350     public void validateUrlParser() throws SvcLogicException {
351         String actVal = "identity-test:test";
352         String url1 = "http://echo.getpostman.com/restconf/operations/" +
353                 actVal;
354         String url2 = "http://echo.getpostman.com/restconf/data/" + actVal;
355         String url3 = "https://echo.getpostman.com/restconf/operations/" +
356                 actVal;
357         String url4 = "https://echo.getpostman.com/restconf/data/" + actVal +
358                 "/for-put";
359         String url5 = "http://localhost:8282/restconf/operations/" + actVal;
360         String url6 = "https://localhost:8282/restconf/operations/" + actVal;
361         String url7 = "http://localhost:8282/restconf/data/" + actVal +
362                 "/for-put";
363         String url8 = "https://localhost:8282/restconf/data/" + actVal;
364         String url9 = "http://182.2.61.24:2250/restconf/data/" + actVal;
365         String url10 = "https://182.2.61.24:2250/restconf/operations/" + actVal;
366         String val1 = parseUrl(url1, POST);
367         String val2 = parseUrl(url2, GET);
368         String val3 = parseUrl(url3, POST);
369         String val4 = parseUrl(url4, PUT);
370         String val5 = parseUrl(url5, GET);
371         String val6 = parseUrl(url6, POST);
372         String val7 = parseUrl(url7, PUT);
373         String val8 = parseUrl(url8, POST);
374         String val9 = parseUrl(url9, GET);
375         String val10 = parseUrl(url10, POST);
376         assertThat(val1, is(actVal));
377         assertThat(val2, is(actVal));
378         assertThat(val3, is(actVal));
379         assertThat(val4, is(actVal));
380         assertThat(val5, is(actVal));
381         assertThat(val6, is(actVal));
382         assertThat(val7, is(actVal));
383         assertThat(val8, is(actVal));
384         assertThat(val9, is(actVal));
385         assertThat(val10, is(actVal));
386     }
387
388     /**
389      * Creates attribute list for encoding JSON or XML with identity-ref YANG
390      * file.
391      *
392      * @param pre prefix
393      * @return service logic context
394      */
395     private SvcLogicContext createAttList(String pre) {
396         SvcLogicContext ctx = new SvcLogicContext();
397         String pre1 = pre + "con1.interfaces.";
398         ctx.setAttribute(pre + "con1.interface", "identity-types:physical");
399         ctx.setAttribute(pre1 + "int-list[0].iden", "optical");
400         ctx.setAttribute(pre1 + "int-list[0].available.ll[0]", "Giga");
401         ctx.setAttribute(pre1 + "int-list[0].available.ll[1]",
402                          "identity-types:Loopback");
403         ctx.setAttribute(pre1 + "int-list[0].available.ll[2]",
404                          "identity-types-second:Ethernet");
405         ctx.setAttribute(pre1 + "int-list[0].available.leaf1", "58");
406         ctx.setAttribute(pre1 + "int-list[0].available.leaf2",
407                          "identity-types-second:iden2");
408
409         ctx.setAttribute(pre1 + "int-list[1].iden", "214748364");
410         ctx.setAttribute(pre1 + "int-list[1].available.ll[0]", "Giga");
411         ctx.setAttribute(pre1 + "int-list[1].available.ll[1]",
412                          "identity-types:Loopback");
413         ctx.setAttribute(pre1 + "int-list[1].available.ll[2]",
414                          "identity-types-second:Ethernet");
415         ctx.setAttribute(pre1 + "int-list[1].available.leaf1",
416                          "8888");
417         ctx.setAttribute(pre1 + "int-list[1].available.leaf2",
418                          "identity-types-second:iden2");
419         return ctx;
420     }
421
422     /**
423      * Creates attribute list for encoding JSON or XML with container,
424      * grouping and augmented YANG file.
425      *
426      * @param pre prefix
427      * @return service logic context
428      */
429     private SvcLogicContext createAttListYang(String pre) {
430         SvcLogicContext ctx = new SvcLogicContext();
431         ctx.setAttribute(pre + "cont3.leaf10", "abc");
432         ctx.setAttribute(pre + "list1[0].leaf1", "true");
433         ctx.setAttribute(pre + "list1[0].leaf2", "abc");
434         ctx.setAttribute(pre + "list1[0].leaf3", "abc");
435         ctx.setAttribute(pre + "list1[0].ll1[0]", "abc");
436         ctx.setAttribute(pre + "list1[0].ll1[1]", "abc");
437         ctx.setAttribute(pre + "list1[0].ll2[0]", "abc");
438         ctx.setAttribute(pre + "list1[0].ll2[1]", "abc");
439         ctx.setAttribute(pre + "list1[0].cont4.leaf11", "abc");
440         ctx.setAttribute(pre + "list1[0].list4[0].leaf8", "abc");
441         ctx.setAttribute(pre + "list1[0].list4[1].leaf8", "abc");
442         ctx.setAttribute(pre + "list1[0].list5[0].leaf9", "abc");
443         ctx.setAttribute(pre + "list1[0].list5[1].leaf9", "abc");
444         ctx.setAttribute(pre + "list1[1].leaf1", "true");
445         ctx.setAttribute(pre + "list1[1].leaf2", "abc");
446         ctx.setAttribute(pre + "list1[1].leaf3", "abc");
447         ctx.setAttribute(pre + "list1[1].ll1[0]", "abc");
448         ctx.setAttribute(pre + "list1[1].ll1[1]", "abc");
449         ctx.setAttribute(pre + "list1[1].ll2[0]", "abc");
450         ctx.setAttribute(pre + "list1[1].ll2[1]", "abc");
451         ctx.setAttribute(pre + "list1[1].cont4.leaf11", "abc");
452         ctx.setAttribute(pre + "list1[1].list4[0].leaf8", "abc");
453         ctx.setAttribute(pre + "list1[1].list4[1].leaf8", "abc");
454         ctx.setAttribute(pre + "list1[1].list5[0].leaf9", "abc");
455         ctx.setAttribute(pre + "list1[1].list5[1].leaf9", "abc");
456         ctx.setAttribute(pre + "list2[0].leaf4", "abc");
457         ctx.setAttribute(pre + "list2[1].leaf4", "abc");
458         ctx.setAttribute(pre + "leaf5", "abc");
459         ctx.setAttribute(pre + "leaf6", "abc");
460         ctx.setAttribute(pre + "ll3[0]", "abc");
461         ctx.setAttribute(pre + "ll3[1]", "abc");
462         ctx.setAttribute(pre + "ll4[0]", "abc");
463         ctx.setAttribute(pre + "ll4[1]", "abc");
464         ctx.setAttribute(pre + "cont4.leaf10", "abc");
465         ctx.setAttribute(pre + "list6[0].leaf11", "abc");
466         ctx.setAttribute(pre + "list6[1].leaf11", "abc");
467         ctx.setAttribute(pre + "leaf12", "abc");
468         ctx.setAttribute(pre + "ll5[0]", "abc");
469         ctx.setAttribute(pre + "ll5[1]", "abc");
470         ctx.setAttribute(pre + "cont4.test-augment:cont5.leaf13", "true");
471         ctx.setAttribute(pre + "cont4.test-augment:list7[0].leaf14", "test");
472         ctx.setAttribute(pre + "cont4.test-augment:list7[1].leaf14", "create");
473         ctx.setAttribute(pre + "cont4.test-augment:leaf15", "abc");
474         ctx.setAttribute(pre + "cont4.test-augment:ll6[0]", "unbounded");
475         ctx.setAttribute(pre + "cont4.test-augment:ll6[1]", "8");
476         ctx.setAttribute(pre + "cont4.test-augment:cont13.cont12.leaf26",
477                          "abc");
478         ctx.setAttribute(pre + "cont4.test-augment:cont13.list9[0].leaf27",
479                          "abc");
480         ctx.setAttribute(pre + "cont4.test-augment:cont13.list9[1].leaf27",
481                          "abc");
482         ctx.setAttribute(pre + "cont4.test-augment:cont13.leaf28", "abc");
483         ctx.setAttribute(pre + "cont4.test-augment:cont13.ll9[0]", "abc");
484         ctx.setAttribute(pre + "cont4.test-augment:cont13.ll9[1]", "abc");
485         return ctx;
486     }
487
488     /**
489      * Creates attribute list for encoding JSON or XML with RPC YANG file.
490      *
491      * @param pre prefix
492      * @return service logic context
493      */
494     private SvcLogicContext createAttListRpc(String pre) {
495         SvcLogicContext ctx = new SvcLogicContext();
496         ctx.setAttribute(pre + "cont14.leaf28", "abc");
497         ctx.setAttribute(pre + "list10[0].leaf29", "abc");
498         ctx.setAttribute(pre + "list10[1].leaf29", "abc");
499         ctx.setAttribute(pre + "leaf30", "abc");
500         ctx.setAttribute(pre + "ll10[0]", "abc");
501         ctx.setAttribute(pre + "ll10[1]", "abc");
502         ctx.setAttribute(pre + "cont15.leaf31", "abc");
503         ctx.setAttribute(pre + "cont13.list9[0].leaf27", "abc");
504         ctx.setAttribute(pre + "cont13.list9[1].leaf27", "abc");
505         ctx.setAttribute(pre + "cont13.leaf28", "abc");
506         ctx.setAttribute(pre + "cont13.ll9[0]", "abc");
507         ctx.setAttribute(pre + "cont13.ll9[1]", "abc");
508         return ctx;
509     }
510
511     /**
512      * Verifies the attribute list for decoding from JSON or XML with
513      * identity-ref YANG file.
514      *
515      * @param ctx service logic context
516      * @param pre prefix
517      */
518     private void verifyAttList(SvcLogicContext ctx, String pre) {
519         String pre1 = pre + "con1.interfaces.";
520         assertThat(ctx.getAttribute(pre + "con1.interface"), is(
521                 "identity-types:physical"));
522         assertThat(ctx.getAttribute(pre + "con1.interface"), is(
523                 "identity-types:physical"));
524         assertThat(ctx.getAttribute(pre1 + "int-list[0].iden"), is("optical"));
525         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[0]"), is(
526                 "Giga"));
527         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[1]"), is(
528                 "identity-types:Loopback"));
529         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[2]"), is(
530                 "identity-types-second:Ethernet"));
531         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.leaf1"), is(
532                 "58"));
533         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.leaf2"), is(
534                 "identity-types-second:iden2"));
535
536         assertThat(ctx.getAttribute(pre1 + "int-list[1].iden"), is(
537                 "214748364"));
538         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[0]"), is(
539                 "Giga"));
540         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[1]"), is(
541                 "identity-types:Loopback"));
542         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[2]"), is(
543                 "identity-types-second:Ethernet"));
544         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.leaf1"), is(
545                 "8888"));
546         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.leaf2"), is(
547                 "identity-types-second:iden2"));
548     }
549
550     /**
551      * Verifies the attribute list for decoding from JSON or XML with
552      * container, grouping and augmented file.
553      *
554      * @param ctx service logic context
555      * @param pre prefix
556      */
557     private void verifyAttListYang(SvcLogicContext ctx, String pre) {
558         assertThat(ctx.getAttribute(pre + "cont3.leaf10"), is("abc"));
559         assertThat(ctx.getAttribute(pre + "list1[0].leaf1"), is("true"));
560         assertThat(ctx.getAttribute(pre + "list1[0].leaf2"), is("abc"));
561         assertThat(ctx.getAttribute(pre + "list1[0].leaf3"), is("abc"));
562         assertThat(ctx.getAttribute(pre + "list1[0].ll1[0]"), is("abc"));
563         assertThat(ctx.getAttribute(pre + "list1[0].ll1[1]"), is("abc"));
564         assertThat(ctx.getAttribute(pre + "list1[0].ll2[0]"), is("abc"));
565         assertThat(ctx.getAttribute(pre + "list1[0].ll2[1]"), is("abc"));
566         assertThat(ctx.getAttribute(pre + "list1[0].cont4.leaf11"), is("abc"));
567         assertThat(ctx.getAttribute(pre + "list1[0].list4[0].leaf8"),
568                    is("abc"));
569         assertThat(ctx.getAttribute(pre + "list1[0].list4[1].leaf8"),
570                    is("abc"));
571         assertThat(ctx.getAttribute(pre + "list1[0].list5[0].leaf9"),
572                    is("abc"));
573         assertThat(ctx.getAttribute(pre + "list1[0].list5[1].leaf9"),
574                    is("abc"));
575         assertThat(ctx.getAttribute(pre + "list1[1].leaf1"), is("true"));
576         assertThat(ctx.getAttribute(pre + "list1[1].leaf2"), is("abc"));
577         assertThat(ctx.getAttribute(pre + "list1[1].leaf3"), is("abc"));
578         assertThat(ctx.getAttribute(pre + "list1[1].ll1[0]"), is("abc"));
579         assertThat(ctx.getAttribute(pre + "list1[1].ll1[1]"), is("abc"));
580         assertThat(ctx.getAttribute(pre + "list1[1].ll2[0]"), is("abc"));
581         assertThat(ctx.getAttribute(pre + "list1[1].ll2[1]"), is("abc"));
582         assertThat(ctx.getAttribute(pre + "list1[1].cont4.leaf11"), is("abc"));
583         assertThat(ctx.getAttribute(pre + "list1[1].list4[0].leaf8"),
584                    is("abc"));
585         assertThat(ctx.getAttribute(pre + "list1[1].list4[1].leaf8"),
586                    is("abc"));
587         assertThat(ctx.getAttribute(pre + "list1[1].list5[0].leaf9"),
588                    is("abc"));
589         assertThat(ctx.getAttribute(pre + "list1[1].list5[1].leaf9"),
590                    is("abc"));
591         assertThat(ctx.getAttribute(pre + "list2[0].leaf4"), is("abc"));
592         assertThat(ctx.getAttribute(pre + "list2[1].leaf4"), is("abc"));
593         assertThat(ctx.getAttribute(pre + "leaf5"), is("abc"));
594         assertThat(ctx.getAttribute(pre + "leaf6"), is("abc"));
595         assertThat(ctx.getAttribute(pre + "ll3[0]"), is("abc"));
596         assertThat(ctx.getAttribute(pre + "ll3[1]"), is("abc"));
597         assertThat(ctx.getAttribute(pre + "ll4[0]"), is("abc"));
598         assertThat(ctx.getAttribute(pre + "ll4[1]"), is("abc"));
599         assertThat(ctx.getAttribute(pre + "cont4.leaf10"), is( "abc"));
600         assertThat(ctx.getAttribute(pre + "list6[0].leaf11"), is("abc"));
601         assertThat(ctx.getAttribute(pre + "list6[1].leaf11"), is("abc"));
602         assertThat(ctx.getAttribute(pre + "leaf12"), is("abc"));
603         assertThat(ctx.getAttribute(pre + "ll5[0]"), is("abc"));
604         assertThat(ctx.getAttribute(pre + "ll5[1]"), is("abc"));
605         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont5.leaf13"),
606                    is("true"));
607         assertThat(ctx.getAttribute(pre + "cont4.test-augment:list7[0].leaf14"),
608                    is("test"));
609         assertThat(ctx.getAttribute(pre + "cont4.test-augment:list7[1].leaf14"),
610                    is("create"));
611         assertThat(ctx.getAttribute(pre + "cont4.test-augment:leaf15"),
612                    is("abc"));
613         assertThat(ctx.getAttribute(pre + "cont4.test-augment:ll6[0]"),
614                    is("unbounded"));
615         assertThat(ctx.getAttribute(pre + "cont4.test-augment:ll6[1]"),
616                    is("8"));
617         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13" +
618                                             ".cont12.leaf26"), is("abc"));
619         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.list9[0]" +
620                                             ".leaf27"), is("abc"));
621         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.list9[1]" +
622                                             ".leaf27"), is("abc"));
623         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.leaf28"),
624                    is("abc"));
625         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.ll9[0]"),
626                    is("abc"));
627         assertThat(ctx.getAttribute(pre + "cont4.test-augment:cont13.ll9[1]"),
628                    is("abc"));
629     }
630
631     /**
632      * Verifies the attribute list for decoding from JSON or XML with
633      * RPC YANG file.
634      *
635      * @param ctx service logic context
636      * @param pre prefix
637      */
638     private void verifyAttListRpc(SvcLogicContext ctx, String pre) {
639         assertThat(ctx.getAttribute(pre + "cont16.leaf32"), is("abc"));
640         assertThat(ctx.getAttribute(pre + "list11[0].leaf33"), is("abc"));
641         assertThat(ctx.getAttribute(pre + "list11[1].leaf33"), is("abc"));
642         assertThat(ctx.getAttribute(pre + "leaf34"), is("abc"));
643         assertThat(ctx.getAttribute(pre + "ll11[0]"), is("abc"));
644         assertThat(ctx.getAttribute(pre + "ll11[1]"), is("abc"));
645         assertThat(ctx.getAttribute(pre + "cont17.leaf35"), is("abc"));
646         assertThat(ctx.getAttribute(pre + "cont13.cont12.leaf26"), is("abc"));
647         assertThat(ctx.getAttribute(pre + "cont13.list9[0].leaf27"), is("abc"));
648         assertThat(ctx.getAttribute(pre + "cont13.list9[1].leaf27"), is("abc"));
649         assertThat(ctx.getAttribute(pre + "cont13.ll9[0]"), is("abc"));
650         assertThat(ctx.getAttribute(pre + "cont13.ll9[1]"), is("abc"));
651         assertThat(ctx.getAttribute(pre + "cont13.leaf28"), is("abc"));
652     }
653
654     /**
655      * Captures the data format messages by mocking it, which can be used in
656      * testing the value.
657      *
658      * @param <String> capturing data format
659      */
660     public class DfCaptor<String> implements Answer {
661
662         private String result;
663
664         /**
665          * Returns the captured data format message.
666          *
667          * @return data format message.
668          */
669         public String getResult() {
670             return result;
671         }
672
673         @Override
674         public String answer(InvocationOnMock invocationOnMock)
675                 throws Throwable {
676             result = (String) invocationOnMock.callRealMethod();
677             return result;
678         }
679     }
680
681 }