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