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