9abbb16b702e0be329ceb4ae493b1980c7d3a375
[ccsdk/sli.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - CCSDK
4  * ================================================================================
5  * Copyright (C) 2019 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 java.util.HashMap;
24 import java.util.Map;
25
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.invocation.InvocationOnMock;
29 import org.mockito.stubbing.Answer;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
32 import org.onap.ccsdk.sli.plugins.restapicall.HttpResponse;
33 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
34 import org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiCallNode;
35 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
36 import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
37 import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
38
39 import static org.hamcrest.MatcherAssert.assertThat;
40 import static org.hamcrest.core.Is.is;
41 import static org.mockito.Matchers.any;
42 import static org.mockito.Mockito.doAnswer;
43 import static org.mockito.Mockito.doCallRealMethod;
44 import static org.mockito.Mockito.doReturn;
45 import static org.mockito.Mockito.mock;
46 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.DECODE_FROM_JSON_RPC_ID;
47 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.DECODE_FROM_XML_RPC_ID;
48 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_JSON_RPC_ID;
49 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_JSON_WITH_AUG_PATH;
50 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_JSON_YANG_AUG_POST_ID;
51 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_JSON_YANG_ID;
52 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_JSON_YANG_PUT_ID;
53 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_XML_RPC_ID;
54 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_XML_YANG_AUG_POST_ID;
55 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_XML_YANG_ID;
56 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.IdentifierValidationUtilsTest.ENCODE_TO_XML_YANG_PUT_ID;
57
58 /**
59  * Unit test cases for identifier validation test.
60  */
61 public class IdentifierValidationTest {
62
63     private Map<String, String> p;
64
65     private RestconfApiCallNode restconf;
66
67     private RestapiCallNode restApi;
68
69     private YangParserFactory parserFactory;
70
71     private DfCaptor dfCaptor;
72
73     /**
74      * Sets up the pre-requisite for each test case.
75      *
76      * @throws SvcLogicException when test case fails
77      */
78     @Before
79     public void setUp() throws SvcLogicException {
80         p = new HashMap<>();
81         p.put("restapiUser", "user1");
82         p.put("restapiPassword", "abc123");
83         p.put("responsePrefix", "response");
84         p.put("skipSending", "true");
85         restApi = new RestapiCallNode();
86         parserFactory = new YangParserFactoryImpl();
87         restconf = mock(RestconfApiCallNode.class);
88         dfCaptor = new DfCaptor();
89         createMethodMocks();
90     }
91
92     /**
93      * Creates method mocks using mockito for RestconfApiCallNode class.
94      *
95      * @throws SvcLogicException when test case fails
96      */
97     private void createMethodMocks() throws SvcLogicException {
98         doReturn(restApi).when(restconf).getRestapiCallNode();
99         doReturn(parserFactory).when(restconf).getParserFactory();
100         doCallRealMethod().when(restconf).sendRequest(
101                 any(Map.class), any(SvcLogicContext.class));
102         doCallRealMethod().when(restconf).sendRequest(
103                 any(Map.class), any(SvcLogicContext.class), any(Integer.class));
104         doAnswer(dfCaptor).when(restconf).serializeRequest(
105                 any(Map.class), any(YangParameters.class), any(String.class),
106                 any(InstanceIdentifierContext.class));
107         doAnswer(dfCaptor).when(restconf).updateReq(
108                 any(String.class), any(YangParameters.class),
109                 any(InstanceIdentifierContext.class));
110     }
111
112     /**
113      * Creates mock using mockito with input data for decoding.
114      *
115      * @param decodeData input data
116      * @throws SvcLogicException when test case fails
117      */
118     private void createMockForDecode(String decodeData)
119             throws SvcLogicException {
120         doReturn(decodeData).when(restconf).getResponse(
121                 any(SvcLogicContext.class), any(YangParameters.class),
122                 any(String.class), any(HttpResponse.class));
123         doCallRealMethod().when(restconf).serializeResponse(
124                 any(YangParameters.class), any(String.class), any(String.class),
125                 any(InstanceIdentifierContext.class));
126     }
127
128     /**
129      * Verifies encoding of parameters to JSON data format with containers,
130      * grouping and augment.
131      *
132      * @throws SvcLogicException when test case fails
133      */
134     @Test
135     public void encodeToJsonYang() throws SvcLogicException {
136         String pre = "test_name_of_the_module_name_of_the_cont1.name_" +
137                 "of_the_cont2.";
138         SvcLogicContext ctx = createAttListYang(pre);
139         p.put("dirPath", "src/test/resources");
140         p.put("format", "json");
141         p.put("httpMethod", "post");
142         p.put("restapiUrl", "http://echo.getpostman.com/restconf/operati" +
143                 "ons/test_name_of_the_module:name_of_the_cont1");
144         restconf.sendRequest(p, ctx);
145         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_ID));
146     }
147
148     /**
149      * Verifies encoding of parameters with augment in the URL.
150      *
151      * @throws SvcLogicException when test case fails
152      */
153     @Test
154     public void encodeToJsonYangWithAugUrl() throws SvcLogicException {
155         String pre = "test_name_of_the_module_name_of_the_cont1.name_" +
156                 "of_the_cont2.";
157         SvcLogicContext ctx = createAttListYang(pre);
158         p.put("dirPath", "src/test/resources");
159         p.put("format", "json");
160         p.put("httpMethod", "post");
161         p.put("restapiUrl", "http://echo.getpostman.com/restconf/operati" +
162                 "ons/test_name_of_the_module:name_of_the_cont1/name_of_t" +
163                 "he_cont2/name_of_the_cont4/test_augment_1_for_module:na" +
164                 "me_of_the_cont5");
165         restconf.sendRequest(p, ctx);
166         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_WITH_AUG_PATH));
167     }
168
169     /**
170      * Verifies encoding of parameters to JSON data format with containers,
171      * grouping and augment for put operation-type.
172      *
173      * @throws SvcLogicException when test case fails
174      */
175     @Test
176     public void encodeToJsonYangWithPut() throws SvcLogicException {
177         String pre = "test_name_of_the_module_name_of_the_cont1.name_of_the_cont2.";
178         SvcLogicContext ctx = createAttListYang(pre);
179         p.put("dirPath", "src/test/resources");
180         p.put("format", "json");
181         p.put("httpMethod", "put");
182         p.put("restapiUrl", "http://echo.getpostman" +
183                 ".com/restconf/operations/test_name_of_the_module:name_of" +
184                 "_the_cont1/name_of_the_cont2/name_of_the_cont4");
185         restconf.sendRequest(p, ctx);
186         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_PUT_ID));
187     }
188
189     /**
190      * Verifies encoding of parameters to JSON data format with containers,
191      * grouping and augment for patch operation-type.
192      *
193      * @throws SvcLogicException when test case fails
194      */
195     @Test
196     public void encodeToJsonYangWithPatch() throws SvcLogicException {
197         String pre = "test_name_of_the_module_name_of_the_cont1.name_o" +
198                 "f_the_cont2.";
199         SvcLogicContext ctx = createAttListYang(pre);
200         p.put("dirPath", "src/test/resources");
201         p.put("format", "json");
202         p.put("httpMethod", "patch");
203         p.put("restapiUrl", "http://echo.getpostman" +
204                 ".com/restconf/operations/test_name_of_the_module:name_of_" +
205                 "the_cont1/name_of_the_cont2/name_of_the_cont4");
206         restconf.sendRequest(p, ctx);
207         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_PUT_ID));
208     }
209
210     /**
211      * Verifies encoding of parameters to JSON data format with augment as
212      * root child.
213      *
214      * @throws SvcLogicException when test case fails
215      */
216     @Test
217     public void encodeToJsonWithAugAsRootChild() throws SvcLogicException {
218         String pre = "test_name_of_the_module_name_of_the_cont1.name_of_" +
219                 "the_cont2.";
220         SvcLogicContext ctx = createAttListYang(pre);
221         p.put("dirPath", "src/test/resources");
222         p.put("format", "json");
223         p.put("httpMethod", "post");
224         p.put("restapiUrl", "http://echo.getpostman" +
225                 ".com/restconf/operations/test_name_of_the_module:name_of_" +
226                 "the_cont1/name_of_the_cont2/name_of_the_cont4");
227         restconf.sendRequest(p, ctx);
228         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_AUG_POST_ID));
229     }
230
231     /**
232      * Verifies decoding of parameters from JSON data format with containers,
233      * grouping and augment.
234      *
235      * @throws SvcLogicException when test case fails
236      */
237     @Test
238     public void decodeToJsonYang() throws SvcLogicException {
239         createMockForDecode(ENCODE_TO_JSON_YANG_ID);
240         SvcLogicContext ctx = new SvcLogicContext();
241         String pre = "test_name_of_the_module_name_of_the_cont1.name_" +
242                 "of_the_cont2.";
243         p.put("dirPath", "src/test/resources");
244         p.put("format", "json");
245         p.put("httpMethod", "get");
246         p.put("restapiUrl", "http://echo.getpostman" +
247                 ".com/restconf/operations/test_name_of_the_module:name" +
248                 "_of_the_cont1");
249         restconf.sendRequest(p, ctx);
250         verifyAttListYang(ctx, pre);
251     }
252
253     /**
254      * Verifies encoding of parameters to XML data format with containers,
255      * grouping and augment.
256      *
257      * @throws SvcLogicException when test case fails
258      */
259     @Test
260     public void encodeToXmlYang() throws SvcLogicException {
261         String pre = "test_name_of_the_module_name_of_the_cont1.name_of" +
262                 "_the_cont2.";
263         SvcLogicContext ctx = createAttListYang(pre);
264         p.put("dirPath", "src/test/resources");
265         p.put("format", "xml");
266         p.put("httpMethod", "post");
267         p.put("restapiUrl", "http://echo.getpostman.com/restconf/operations/" +
268                 "test_name_of_the_module:name_of_the_cont1");
269         restconf.sendRequest(p, ctx);
270         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_ID));
271     }
272
273     /**
274      * Verifies encoding of parameters to XML data format with containers,
275      * grouping and augment for put operation-type
276      *
277      * @throws SvcLogicException when test case fails
278      */
279     @Test
280     public void encodeToXmlYangWithPut() throws SvcLogicException {
281         String pre = "test_name_of_the_module_name_of_the_cont1.name_" +
282                 "of_the_cont2.";
283         SvcLogicContext ctx = createAttListYang(pre);
284         p.put("dirPath", "src/test/resources");
285         p.put("format", "xml");
286         p.put("httpMethod", "put");
287         p.put("restapiUrl", "http://echo.getpostman.com/restconf/operations/" +
288                 "test_name_of_the_module:name_of_the_cont1/name_of_the_cont2" +
289                 "/name_of_the_cont4");
290         restconf.sendRequest(p, ctx);
291         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_PUT_ID));
292     }
293
294     /**
295      * Verifies encoding of parameters to XML data format with containers,
296      * grouping and augment for patch operation-type
297      *
298      * @throws SvcLogicException when test case fails
299      */
300     @Test
301     public void encodeToXmlYangWithPatch() throws SvcLogicException {
302         String pre = "test_name_of_the_module_name_of_the_cont1.name_of" +
303                 "_the_cont2.";
304         SvcLogicContext ctx = createAttListYang(pre);
305         p.put("dirPath", "src/test/resources");
306         p.put("format", "xml");
307         p.put("httpMethod", "put");
308         p.put("restapiUrl", "http://echo.getpostman.com/restconf/operation" +
309                 "s/test_name_of_the_module:name_of_the_cont1/name_of_the_c" +
310                 "ont2/name_of_the_cont4");
311         restconf.sendRequest(p, ctx);
312         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_PUT_ID));
313     }
314
315     /**
316      * Verifies encoding of parameters to XML data format with augment as
317      * root child.
318      *
319      * @throws SvcLogicException when test case fails
320      */
321     @Test
322     public void encodeToXmlWithAugAsRootChild() throws SvcLogicException {
323         String pre = "test_name_of_the_module_name_of_the_cont1.name_of_the" +
324                 "_cont2.";
325         SvcLogicContext ctx = createAttListYang(pre);
326         p.put("dirPath", "src/test/resources");
327         p.put("format", "xml");
328         p.put("httpMethod", "post");
329         p.put("restapiUrl", "http://echo.getpostman.com/restconf/operations/" +
330                 "test_name_of_the_module:name_of_the_cont1/name_of_the_cont2" +
331                 "/name_of_the_cont4");
332         restconf.sendRequest(p, ctx);
333         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_AUG_POST_ID));
334     }
335
336     /**
337      * Verifies decoding of parameters from XML data format with containers,
338      * grouping and augment.
339      *
340      * @throws SvcLogicException when test case fails
341      */
342     @Test
343     public void decodeToXmlYang() throws SvcLogicException {
344         createMockForDecode(ENCODE_TO_XML_YANG_ID);
345         SvcLogicContext ctx = new SvcLogicContext();
346         String pre = "test_name_of_the_module_name_of_the_cont1.name_of_" +
347                 "the_cont2.";
348         p.put("dirPath", "src/test/resources");
349         p.put("format", "xml");
350         p.put("httpMethod", "get");
351         p.put("restapiUrl", "http://echo.getpostman.com/restconf/operation" +
352                 "s/test_name_of_the_module:name_of_the_cont1");
353         restconf.sendRequest(p, ctx);
354         verifyAttListYang(ctx, pre);
355     }
356
357     /**
358      * Verifies encoding of and decoding from, JSON respectively for data
359      * format with containers, grouping and augment.
360      *
361      * @throws SvcLogicException when test case fails
362      */
363     @Test
364     public void codecToJsonRpc() throws SvcLogicException {
365         createMockForDecode(DECODE_FROM_JSON_RPC_ID);
366         String inPre = "test_name_of_the_module_name_of_the_create-sfc.input.";
367         String outPre = "test_name_of_the_module_name_of_the_create-sfc" +
368                 ".output.";
369         SvcLogicContext ctx = createAttListRpc(inPre);
370         p.put("dirPath", "src/test/resources");
371         p.put("format", "json");
372         p.put("httpMethod", "post");
373         p.put("restapiUrl", "http://echo.getpostman.com/restconf/operations" +
374                 "/test_name_of_the_module:name_of_the_create-sfc");
375         restconf.sendRequest(p, ctx);
376         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_RPC_ID));
377         verifyAttListRpc(ctx, outPre);
378     }
379
380     /**
381      * Verifies encoding of and decoding from, XML respectively for data
382      * format with containers, grouping and augment.
383      *
384      * @throws SvcLogicException when test case fails
385      */
386     @Test
387     public void codecToXmlRpc() throws SvcLogicException {
388         createMockForDecode(DECODE_FROM_XML_RPC_ID);
389         String inPre = "test_name_of_the_module_name_of_the_create-sfc.input.";
390         String outPre = "test_name_of_the_module_name_of_the_create-sfc.output.";
391         SvcLogicContext ctx = createAttListRpc(inPre);
392         p.put("dirPath", "src/test/resources");
393         p.put("format", "xml");
394         p.put("httpMethod", "post");
395         p.put("restapiUrl", "http://echo.getpostman" +
396                 ".com/restconf/operations/test_name_of_the_module" +
397                 ":name_of_the_create-sfc");
398         restconf.sendRequest(p, ctx);
399         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_RPC_ID));
400         verifyAttListRpc(ctx, outPre);
401     }
402
403     /**
404      * Creates attribute list for encoding JSON or XML with container,
405      * grouping and augmented YANG file.
406      *
407      * @param pre prefix
408      * @return service logic context
409      */
410     private SvcLogicContext createAttListYang(String pre) {
411         SvcLogicContext ctx = new SvcLogicContext();
412         ctx.setAttribute(pre + "name_of_the_cont3.name_of_the_leaf" +
413                                  "10", "abc");
414         ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_leaf1" +
415                                  "", "true");
416         ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_leaf2" +
417                                  "", "abc");
418         ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_leaf3" +
419                                  "", "abc");
420         ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" +
421                                  "ll1[0]", "abc");
422         ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" +
423                                  "ll1[1]", "abc");
424         ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" +
425                                  "ll2[0]", "abc");
426         ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" +
427                                  "ll2[1]", "abc");
428         ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" +
429                                  "cont4.name_of_the_leaf11", "abc");
430         ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" +
431                                  "list4[0].name_of_the_leaf8", "abc");
432         ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" +
433                                  "list4[1].name_of_the_leaf8", "abc");
434         ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" +
435                                  "list5[0].name_of_the_leaf9", "abc");
436         ctx.setAttribute(pre + "name_of_the_list1[0].name_of_the_" +
437                                  "list5[1].name_of_the_leaf9", "abc");
438         ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" +
439                                  "leaf1", "true");
440         ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" +
441                                  "leaf2", "abc");
442         ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" +
443                                  "leaf3", "abc");
444         ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" +
445                                  "ll1[0]", "abc");
446         ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" +
447                                  "ll1[1]", "abc");
448         ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" +
449                                  "ll2[0]", "abc");
450         ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" +
451                                  "ll2[1]", "abc");
452         ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" +
453                                  "cont4.name_of_the_leaf11", "abc");
454         ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" +
455                                  "list4[0].name_of_the_leaf8", "abc");
456         ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" +
457                                  "list4[1].name_of_the_leaf8", "abc");
458         ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" +
459                                  "list5[0].name_of_the_leaf9", "abc");
460         ctx.setAttribute(pre + "name_of_the_list1[1].name_of_the_" +
461                                  "list5[1].name_of_the_leaf9", "abc");
462         ctx.setAttribute(pre + "name_of_the_list2[0].name_of_the_" +
463                                  "leaf4", "abc");
464         ctx.setAttribute(pre + "name_of_the_list2[1].name_of_the_" +
465                                  "leaf4", "abc");
466         ctx.setAttribute(pre + "name_of_the_leaf5", "abc");
467         ctx.setAttribute(pre + "name_of_the_leaf6", "abc");
468         ctx.setAttribute(pre + "name_of_the_ll3[0]", "abc");
469         ctx.setAttribute(pre + "name_of_the_ll3[1]", "abc");
470         ctx.setAttribute(pre + "name_of_the_ll4[0]", "abc");
471         ctx.setAttribute(pre + "name_of_the_ll4[1]", "abc");
472         ctx.setAttribute(pre + "name_of_the_cont4.name_of_the_leaf10",
473                          "abc");
474         ctx.setAttribute(pre + "name_of_the_list6[0].name_of_the_leaf11",
475                          "abc");
476         ctx.setAttribute(pre + "name_of_the_list6[1].name_of_the_leaf11",
477                          "abc");
478         ctx.setAttribute(pre + "name_of_the_leaf12", "abc");
479         ctx.setAttribute(pre + "name_of_the_ll5[0]", "abc");
480         ctx.setAttribute(pre + "name_of_the_ll5[1]", "abc");
481         ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for_" +
482                                  "module_name_of_the_cont5.name_of_the_leaf13",
483                          "true");
484         ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for_" +
485                                  "module_name_of_the_list7[0].name_of_the" +
486                                  "_leaf14", "test");
487         ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for_" +
488                                  "module_name_of_the_list7[1].name_of_the" +
489                                  "_leaf14", "create");
490         ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for_" +
491                                  "module_name_of_the_leaf15", "abc");
492         ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for_" +
493                                  "module_name_of_the_ll6[0]",
494                          "unbounded");
495         ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for" +
496                                  "_module_name_of_the_ll6[1]", "8");
497         ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for" +
498                                  "_module_name_of_the_cont13.name_of_the_" +
499                                  "cont12.name_of_the_leaf26",
500                          "abc");
501         ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for_" +
502                                  "module_name_of_the_cont13.name_of_the_" +
503                                  "list9[0].name_of_the_leaf27",
504                          "abc");
505         ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for" +
506                                  "_module_name_of_the_cont13.name_of_the_" +
507                                  "list9[1].name_of_the_leaf27",
508                          "abc");
509         ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for" +
510                                  "_module_name_of_the_cont13.name_of_the_" +
511                                  "leaf28", "abc");
512         ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for" +
513                                  "_module_name_of_the_cont13.name_of_the_" +
514                                  "ll9[0]", "abc");
515         ctx.setAttribute(pre + "name_of_the_cont4.test_augment_1_for" +
516                                  "_module_name_of_the_cont13.name_of_the_" +
517                                  "ll9[1]", "abc");
518         return ctx;
519     }
520
521     /**
522      * Creates attribute list for encoding JSON or XML with RPC YANG file.
523      *
524      * @param pre prefix
525      * @return service logic context
526      */
527     private SvcLogicContext createAttListRpc(String pre) {
528         SvcLogicContext ctx = new SvcLogicContext();
529         ctx.setAttribute(pre + "name_of_the_cont14.name_of_the_leaf28",
530                          "abc");
531         ctx.setAttribute(pre + "name_of_the_list10[0].name_of_the_leaf29",
532                          "abc");
533         ctx.setAttribute(pre + "name_of_the_list10[1].name_of_the_leaf29",
534                          "abc");
535         ctx.setAttribute(pre + "name_of_the_leaf30", "abc");
536         ctx.setAttribute(pre + "name_of_the_ll10[0]", "abc");
537         ctx.setAttribute(pre + "name_of_the_ll10[1]", "abc");
538         ctx.setAttribute(pre + "name_of_the_cont15.name_of_the_leaf31",
539                          "abc");
540         ctx.setAttribute(pre + "name_of_the_cont13.name_of_the_list9[0]" +
541                                  ".name_of_the_leaf27", "abc");
542         ctx.setAttribute(pre + "name_of_the_cont13.name_of_the_list9[1]" +
543                                  ".name_of_the_leaf27", "abc");
544         ctx.setAttribute(pre + "name_of_the_cont13.name_of_the_leaf28",
545                          "abc");
546         ctx.setAttribute(pre + "name_of_the_cont13.name_of_the_ll9[0]",
547                          "abc");
548         ctx.setAttribute(pre + "name_of_the_cont13.name_of_the_ll9[1]",
549                          "abc");
550         return ctx;
551     }
552
553     /**
554      * Verifies the attribute list for decoding from JSON or XML with
555      * container, grouping and augmented file.
556      *
557      * @param ctx service logic context
558      * @param pre prefix
559      */
560     private void verifyAttListYang(SvcLogicContext ctx, String pre) {
561         assertThat(ctx.getAttribute(pre + "name_of_the_cont3.name_of" +
562                                             "_the_leaf10"), is("abc"));
563         assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" +
564                                             "_of_the_leaf1"), is("true"));
565         assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" +
566                                             "_of_the_leaf2"), is("abc"));
567         assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" +
568                                             "_of_the_leaf3"), is("abc"));
569         assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" +
570                                             "_of_the_ll1[0]"), is("abc"));
571         assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" +
572                                             "_of_the_ll1[1]"), is("abc"));
573         assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" +
574                                             "_of_the_ll2[0]"), is("abc"));
575         assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" +
576                                             "_of_the_ll2[1]"), is("abc"));
577         assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name" +
578                                             "_of_the_cont4.name_of_the_leaf11"),
579                    is("abc"));
580         assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name_of" +
581                                             "_the_list4[0].name_of_the_leaf8"),
582                    is("abc"));
583         assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name_of" +
584                                             "_the_list4[1].name_of_the_leaf8"),
585                    is("abc"));
586         assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name_of" +
587                                             "_the_list5[0].name_of_the_leaf9"),
588                    is("abc"));
589         assertThat(ctx.getAttribute(pre + "name_of_the_list1[0].name_of" +
590                                             "_the_list5[1].name_of_the_leaf9"),
591                    is("abc"));
592         assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" +
593                                             "_the_leaf1"), is("true"));
594         assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" +
595                                             "_the_leaf2"), is("abc"));
596         assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" +
597                                             "_the_leaf3"), is("abc"));
598         assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" +
599                                             "_the_ll1[0]"), is("abc"));
600         assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" +
601                                             "_the_ll1[1]"), is("abc"));
602         assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" +
603                                             "_the_ll2[0]"), is("abc"));
604         assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" +
605                                             "_the_ll2[1]"), is("abc"));
606         assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" +
607                                             "_the_cont4.name_of_the_leaf11"),
608                    is("abc"));
609         assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" +
610                                             "_the_list4[0].name_of_the_leaf8"),
611                    is("abc"));
612         assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" +
613                                             "_the_list4[1].name_of_the_leaf8"),
614                    is("abc"));
615         assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" +
616                                             "_the_list5[0].name_of_the_leaf9"),
617                    is("abc"));
618         assertThat(ctx.getAttribute(pre + "name_of_the_list1[1].name_of" +
619                                             "_the_list5[1].name_of_the_leaf9"),
620                    is("abc"));
621         assertThat(ctx.getAttribute(pre + "name_of_the_list2[0].name_of" +
622                                             "_the_leaf4"), is("abc"));
623         assertThat(ctx.getAttribute(pre + "name_of_the_list2[1].name_of" +
624                                             "_the_leaf4"), is("abc"));
625         assertThat(ctx.getAttribute(pre + "name_of_the_leaf5"),
626                    is("abc"));
627         assertThat(ctx.getAttribute(pre + "name_of_the_leaf6"),
628                    is("abc"));
629         assertThat(ctx.getAttribute(pre + "name_of_the_ll3[0]"),
630                    is("abc"));
631         assertThat(ctx.getAttribute(pre + "name_of_the_ll3[1]"),
632                    is("abc"));
633         assertThat(ctx.getAttribute(pre + "name_of_the_ll4[0]"),
634                    is("abc"));
635         assertThat(ctx.getAttribute(pre + "name_of_the_ll4[1]"),
636                    is("abc"));
637         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.name_of" +
638                                             "_the_leaf10"), is( "abc"));
639         assertThat(ctx.getAttribute(pre + "name_of_the_list6[0].name_of" +
640                                             "_the_leaf11"), is("abc"));
641         assertThat(ctx.getAttribute(pre + "name_of_the_list6[1].name_of" +
642                                             "_the_leaf11"), is("abc"));
643         assertThat(ctx.getAttribute(pre + "name_of_the_leaf12"),
644                    is("abc"));
645         assertThat(ctx.getAttribute(pre + "name_of_the_ll5[0]"),
646                    is("abc"));
647         assertThat(ctx.getAttribute(pre + "name_of_the_ll5[1]"),
648                    is("abc"));
649         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" +
650                                             "augment_1_for_module_name_of_" +
651                                             "the_cont5.name_of_the_leaf13"),
652                    is("true"));
653         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" +
654                                             "augment_1_for_module_name_of_" +
655                                             "the_list7[0].name_of_the_leaf14"),
656                    is("test"));
657         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" +
658                                             "augment_1_for_module_name_of_" +
659                                             "the_list7[1].name_of_the_leaf14"),
660                    is("create"));
661         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" +
662                                             "augment_1_for_module_name_of_" +
663                                             "the_leaf15"),
664                    is("abc"));
665         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" +
666                                             "augment_1_for_module_name_of_" +
667                                             "the_ll6[0]"),
668                    is("unbounded"));
669         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" +
670                                             "augment_1_for_module_name_of_" +
671                                             "the_ll6[1]"),
672                    is("8"));
673         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" +
674                                             "augment_1_for_module_name_of_" +
675                                             "the_cont13" +
676                                             ".name_of_the_cont12.name_of_" +
677                                             "the_leaf26"), is("abc"));
678         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" +
679                                             "augment_1_for_module_name_of_" +
680                                             "the_cont13.name_of_the_list9[0]" +
681                                             ".name_of_the_leaf27"),
682                    is("abc"));
683         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" +
684                                             "augment_1_for_module_name_of_" +
685                                             "the_cont13.name_of_the_list9[1]" +
686                                             ".name_of_the_leaf27"),
687                    is("abc"));
688         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" +
689                                             "augment_1_for_module_name_of_" +
690                                             "the_cont13.name_of_the_leaf28"),
691                    is("abc"));
692         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" +
693                                             "augment_1_for_module_name_of_" +
694                                             "the_cont13.name_of_the_ll9[0]"),
695                    is("abc"));
696         assertThat(ctx.getAttribute(pre + "name_of_the_cont4.test_" +
697                                             "augment_1_for_module_name_of_" +
698                                             "the_cont13.name_of_the_ll9[1]"),
699                    is("abc"));
700     }
701
702     /**
703      * Verifies the attribute list for decoding from JSON or XML with
704      * RPC YANG file.
705      *
706      * @param ctx service logic context
707      * @param pre prefix
708      */
709     private void verifyAttListRpc(SvcLogicContext ctx, String pre) {
710         assertThat(ctx.getAttribute(pre + "name_of_the_cont16.name_of_" +
711                                             "the_leaf32"), is("abc"));
712         assertThat(ctx.getAttribute(pre + "name_of_the_list11[0].name" +
713                                             "_of_the_leaf33"), is("abc"));
714         assertThat(ctx.getAttribute(pre + "name_of_the_list11[1].name" +
715                                             "_of_the_leaf33"), is("abc"));
716         assertThat(ctx.getAttribute(pre + "name_of_the_leaf34"),
717                    is("abc"));
718         assertThat(ctx.getAttribute(pre + "name_of_the_ll11[0]"),
719                    is("abc"));
720         assertThat(ctx.getAttribute(pre + "name_of_the_ll11[1]"),
721                    is("abc"));
722         assertThat(ctx.getAttribute(pre + "name_of_the_cont17.name_of_" +
723                                             "the_leaf35"), is("abc"));
724         assertThat(ctx.getAttribute(pre + "name_of_the_cont13.name_of_" +
725                                             "the_cont12.name_of_the_leaf26"),
726                    is("abc"));
727         assertThat(ctx.getAttribute(pre + "name_of_the_cont13.name_of_" +
728                                             "the_list9[0].name_of_the_leaf27"),
729                    is("abc"));
730         assertThat(ctx.getAttribute(pre + "name_of_the_cont13.name_of_" +
731                                             "the_list9[1].name_of_the_leaf27"),
732                    is("abc"));
733         assertThat(ctx.getAttribute(pre + "name_of_the_cont13.name_of_" +
734                                             "the_ll9[0]"), is("abc"));
735         assertThat(ctx.getAttribute(pre + "name_of_the_cont13.name_of_" +
736                                             "the_ll9[1]"), is("abc"));
737         assertThat(ctx.getAttribute(pre + "name_of_the_cont13.name_of_" +
738                                             "the_leaf28"), is("abc"));
739     }
740
741     /**
742      * Captures the data format messages by mocking it, which can be used in
743      * testing the value.
744      *
745      * @param <String> capturing data format
746      */
747     public class DfCaptor<String> implements Answer {
748
749         private String result;
750
751         /**
752          * Returns the captured data format message.
753          *
754          * @return data format message.
755          */
756         public String getResult() {
757             return result;
758         }
759
760         @Override
761         public String answer(InvocationOnMock invocationOnMock)
762                 throws Throwable {
763             result = (String) invocationOnMock.callRealMethod();
764             return result;
765         }
766     }
767
768 }