Replacing ":" by "_" for parameters
[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 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.restapicall.HttpMethod.GET;
45 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PATCH;
46 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.POST;
47 import static org.onap.ccsdk.sli.plugins.restapicall.HttpMethod.PUT;
48 import static org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiUtils.parseUrl;
49 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_FROM_JSON_RPC;
50 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.DECODE_FROM_XML_RPC;
51 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_ID;
52 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_ID_PUT;
53 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_RPC;
54 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG;
55 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG_AUG_POST;
56 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG_PUT;
57 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_ID;
58 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_ID_PUT;
59 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_RPC;
60 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG;
61 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG_AUG_POST;
62 import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG_PUT;
63
64
65 /**
66  * Unit test cases for data format serialization and restconf api call node.
67  */
68 public class DataFormatSerializerTest {
69
70     private Map<String, String> p;
71
72     private RestconfApiCallNode restconf;
73
74     private RestapiCallNode restApi;
75
76     private DfCaptor dfCaptor;
77
78     /**
79      * Sets up the pre-requisite for each test case.
80      *
81      * @throws SvcLogicException when test case fails
82      */
83     @Before
84     public void setUp() throws SvcLogicException {
85         p = new HashMap<>();
86         p.put("restapiUser", "user1");
87         p.put("restapiPassword", "abc123");
88         p.put("responsePrefix", "response");
89         p.put("skipSending", "true");
90         restApi = new RestapiCallNode();
91         restconf = mock(RestconfApiCallNode.class);
92         dfCaptor = new DfCaptor();
93         createMethodMocks();
94     }
95
96     /**
97      * Creates method mocks using mockito for RestconfApiCallNode class.
98      *
99      * @throws SvcLogicException when test case fails
100      */
101     private void createMethodMocks() throws SvcLogicException {
102         doReturn(restApi).when(restconf).getRestapiCallNode();
103         doCallRealMethod().when(restconf).sendRequest(
104                 any(Map.class), any(SvcLogicContext.class));
105         doCallRealMethod().when(restconf).sendRequest(
106                 any(Map.class), any(SvcLogicContext.class), any(Integer.class));
107         doAnswer(dfCaptor).when(restconf).serializeRequest(
108                 any(Map.class), any(YangParameters.class), any(String.class),
109                 any(InstanceIdentifierContext.class));
110         doAnswer(dfCaptor).when(restconf).updateReq(
111                 any(String.class), any(YangParameters.class),
112                 any(InstanceIdentifierContext.class));
113     }
114
115     /**
116      * Creates mock using mockito with input data for decoding.
117      *
118      * @param decodeData input data
119      * @throws SvcLogicException when test case fails
120      */
121     private void createMockForDecode(String decodeData)
122             throws SvcLogicException {
123         doReturn(decodeData).when(restconf).getResponse(
124                 any(SvcLogicContext.class), any(YangParameters.class),
125                 any(String.class), any(HttpResponse.class));
126         doCallRealMethod().when(restconf).serializeResponse(
127                 any(YangParameters.class), any(String.class), any(String.class),
128                 any(InstanceIdentifierContext.class));
129     }
130
131     /**
132      * Verifies encoding of parameters to JSON data format with identity-ref
133      * and inter-file linking.
134      *
135      * @throws SvcLogicException when test case fails
136      */
137     @Test
138     public void encodeToJsonId() throws SvcLogicException {
139         String pre = "identity-test_test.";
140         SvcLogicContext ctx = createAttList(pre);
141         ctx.setAttribute(pre + "l", "abc");
142         p.put("dirPath", "src/test/resources");
143         p.put("format", "json");
144         p.put("httpMethod", "post");
145         p.put("restapiUrl", "http://echo.getpostman" +
146                 ".com/restconf/operations/identity-test:test");
147         restconf.sendRequest(p, ctx);
148         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID));
149     }
150
151     /**
152      * Verifies encoding of parameters to JSON data format with identity-ref
153      * and inter-file linking for put operation-type.
154      *
155      * @throws SvcLogicException when test case fails
156      */
157     @Test
158     public void encodeToJsonIdWithPut() throws SvcLogicException {
159         String pre = "identity-test_test.";
160         SvcLogicContext ctx = createAttList(pre);
161         ctx.setAttribute(pre + "l", "abc");
162         p.put("dirPath", "src/test/resources");
163         p.put("format", "json");
164         p.put("httpMethod", "put");
165         p.put("restapiUrl", "http://echo.getpostman" +
166                 ".com/restconf/operations/identity-test:test");
167         restconf.sendRequest(p, ctx);
168         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID_PUT));
169     }
170
171     /**
172      * Verifies encoding of parameters to JSON data format with identity-ref
173      * and inter-file linking for patch operation-type.
174      *
175      * @throws SvcLogicException when test case fails
176      */
177     @Test
178     public void encodeToJsonIdWithPatch() throws SvcLogicException {
179         String pre = "identity-test_test.";
180         SvcLogicContext ctx = createAttList(pre);
181         ctx.setAttribute(pre + "l", "abc");
182         p.put("dirPath", "src/test/resources");
183         p.put("format", "json");
184         p.put("httpMethod", "patch");
185         p.put("restapiUrl", "http://echo.getpostman" +
186                 ".com/restconf/operations/identity-test:test");
187         restconf.sendRequest(p, ctx);
188         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_ID_PUT));
189     }
190
191     /**
192      * Verifies encoding of parameters to XML data format with identity-ref
193      * and inter-file linking.
194      *
195      * @throws SvcLogicException when test case fails
196      */
197     @Test
198     public void encodeToXmlId() throws SvcLogicException {
199         String pre = "identity-test_test.";
200         SvcLogicContext ctx = createAttList(pre);
201         p.put("dirPath", "src/test/resources");
202         p.put("format", "xml");
203         p.put("httpMethod", "post");
204         p.put("restapiUrl", "http://echo.getpostman" +
205                 ".com/restconf/operations/identity-test:test");
206         restconf.sendRequest(p, ctx);
207         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID));
208     }
209
210     /**
211      * Verifies encoding of parameters to XML data format with identity-ref
212      * and inter-file linking for put operation-type.
213      *
214      * @throws SvcLogicException when test case fails
215      */
216     @Test
217     public void encodeToXmlIdWithPut() throws SvcLogicException {
218         String pre = "identity-test_test.";
219         SvcLogicContext ctx = createAttList(pre);
220         p.put("dirPath", "src/test/resources");
221         p.put("format", "xml");
222         p.put("httpMethod", "put");
223         p.put("restapiUrl", "http://echo.getpostman" +
224                 ".com/restconf/operations/identity-test:test");
225         restconf.sendRequest(p, ctx);
226         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID_PUT));
227     }
228
229     /**
230      * Verifies encoding of parameters to XML data format with identity-ref
231      * and inter-file linking for patch operation-type.
232      *
233      * @throws SvcLogicException when test case fails
234      */
235     @Test
236     public void encodeToXmlIdWithPatch() throws SvcLogicException {
237         String pre = "identity-test_test.";
238         SvcLogicContext ctx = createAttList(pre);
239         p.put("dirPath", "src/test/resources");
240         p.put("format", "xml");
241         p.put("httpMethod", "patch");
242         p.put("restapiUrl", "http://echo.getpostman" +
243                 ".com/restconf/operations/identity-test:test");
244         restconf.sendRequest(p, ctx);
245         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_ID_PUT));
246     }
247
248     /**
249      * Verifies decoding of parameters from JSON data format with identity-ref
250      * and inter-file linking.
251      *
252      * @throws SvcLogicException when test case fails
253      */
254     @Test
255     public void decodeToJsonId() throws SvcLogicException {
256         createMockForDecode(ENCODE_TO_JSON_ID);
257         SvcLogicContext ctx = new SvcLogicContext();
258         String pre = "identity-test_test.";
259         p.put("dirPath", "src/test/resources");
260         p.put("format", "json");
261         p.put("httpMethod", "get");
262         p.put("restapiUrl", "http://echo.getpostman" +
263                 ".com/restconf/operations/identity-test:test");
264         restconf.sendRequest(p, ctx);
265         assertThat(ctx.getAttribute(pre + "l"), is("abc"));
266         verifyAttList(ctx, pre);
267     }
268
269     /**
270      * Verifies decoding of parameters from XML data format with identity-ref
271      * and inter-file linking.
272      *
273      * @throws SvcLogicException when test case fails
274      */
275     @Test
276     public void decodeToXmlId() throws SvcLogicException {
277         createMockForDecode(ENCODE_TO_XML_ID);
278         SvcLogicContext ctx = new SvcLogicContext();
279         String pre = "identity-test_test.";
280         p.put("dirPath", "src/test/resources");
281         p.put("format", "xml");
282         p.put("httpMethod", "get");
283         p.put("restapiUrl", "http://echo.getpostman" +
284                 ".com/restconf/operations/identity-test:test");
285         restconf.sendRequest(p, ctx);
286         verifyAttList(ctx, pre);
287     }
288
289     /**
290      * Verifies encoding of parameters to JSON data format with containers,
291      * grouping and augment.
292      *
293      * @throws SvcLogicException when test case fails
294      */
295     @Test
296     public void encodeToJsonYang() throws SvcLogicException {
297         String pre = "test-yang_cont1.cont2.";
298         SvcLogicContext ctx = createAttListYang(pre);
299         p.put("dirPath", "src/test/resources");
300         p.put("format", "json");
301         p.put("httpMethod", "post");
302         p.put("restapiUrl", "http://echo.getpostman" +
303                 ".com/restconf/operations/test-yang:cont1");
304         restconf.sendRequest(p, ctx);
305         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG));
306     }
307
308     /**
309      * Verifies encoding of parameters to JSON data format with containers,
310      * grouping and augment for put operation-type.
311      *
312      * @throws SvcLogicException when test case fails
313      */
314     @Test
315     public void encodeToJsonYangWithPut() throws SvcLogicException {
316         String pre = "test-yang_cont1.cont2.";
317         SvcLogicContext ctx = createAttListYang(pre);
318         p.put("dirPath", "src/test/resources");
319         p.put("format", "json");
320         p.put("httpMethod", "put");
321         p.put("restapiUrl", "http://echo.getpostman" +
322                 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
323         restconf.sendRequest(p, ctx);
324         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_PUT));
325     }
326
327     /**
328      * Verifies encoding of parameters to JSON data format with containers,
329      * grouping and augment for patch operation-type.
330      *
331      * @throws SvcLogicException when test case fails
332      */
333     @Test
334     public void encodeToJsonYangWithPatch() throws SvcLogicException {
335         String pre = "test-yang_cont1.cont2.";
336         SvcLogicContext ctx = createAttListYang(pre);
337         p.put("dirPath", "src/test/resources");
338         p.put("format", "json");
339         p.put("httpMethod", "patch");
340         p.put("restapiUrl", "http://echo.getpostman" +
341                 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
342         restconf.sendRequest(p, ctx);
343         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_PUT));
344     }
345
346     /**
347      * Verifies encoding of parameters to JSON data format with augment as
348      * root child.
349      *
350      * @throws SvcLogicException when test case fails
351      */
352     @Test
353     public void encodeToJsonWithAugAsRootChild() throws SvcLogicException {
354         String pre = "test-yang_cont1.cont2.";
355         SvcLogicContext ctx = createAttListYang(pre);
356         p.put("dirPath", "src/test/resources");
357         p.put("format", "json");
358         p.put("httpMethod", "post");
359         p.put("restapiUrl", "http://echo.getpostman" +
360                 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
361         restconf.sendRequest(p, ctx);
362         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_AUG_POST));
363     }
364
365     /**
366      * Verifies decoding of parameters from JSON data format with containers,
367      * grouping and augment.
368      *
369      * @throws SvcLogicException when test case fails
370      */
371     @Test
372     public void decodeToJsonYang() throws SvcLogicException {
373         createMockForDecode(ENCODE_TO_JSON_YANG);
374         SvcLogicContext ctx = new SvcLogicContext();
375         String pre = "test-yang_cont1.cont2.";
376         p.put("dirPath", "src/test/resources");
377         p.put("format", "json");
378         p.put("httpMethod", "get");
379         p.put("restapiUrl", "http://echo.getpostman" +
380                 ".com/restconf/operations/test-yang:cont1");
381         restconf.sendRequest(p, ctx);
382         verifyAttListYang(ctx, pre);
383     }
384
385     /**
386      * Verifies encoding of parameters to XML data format with containers,
387      * grouping and augment.
388      *
389      * @throws SvcLogicException when test case fails
390      */
391     @Test
392     public void encodeToXmlYang() throws SvcLogicException {
393         String pre = "test-yang_cont1.cont2.";
394         SvcLogicContext ctx = createAttListYang(pre);
395         p.put("dirPath", "src/test/resources");
396         p.put("format", "xml");
397         p.put("httpMethod", "post");
398         p.put("restapiUrl", "http://echo.getpostman" +
399                 ".com/restconf/operations/test-yang:cont1");
400         restconf.sendRequest(p, ctx);
401         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG));
402     }
403
404     /**
405      * Verifies encoding of parameters to XML data format with containers,
406      * grouping and augment for put operation-type
407      *
408      * @throws SvcLogicException when test case fails
409      */
410     @Test
411     public void encodeToXmlYangWithPut() throws SvcLogicException {
412         String pre = "test-yang_cont1.cont2.";
413         SvcLogicContext ctx = createAttListYang(pre);
414         p.put("dirPath", "src/test/resources");
415         p.put("format", "xml");
416         p.put("httpMethod", "put");
417         p.put("restapiUrl", "http://echo.getpostman" +
418                 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
419         restconf.sendRequest(p, ctx);
420         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_PUT));
421     }
422
423     /**
424      * Verifies encoding of parameters to XML data format with containers,
425      * grouping and augment for patch operation-type
426      *
427      * @throws SvcLogicException when test case fails
428      */
429     @Test
430     public void encodeToXmlYangWithPatch() throws SvcLogicException {
431         String pre = "test-yang_cont1.cont2.";
432         SvcLogicContext ctx = createAttListYang(pre);
433         p.put("dirPath", "src/test/resources");
434         p.put("format", "xml");
435         p.put("httpMethod", "put");
436         p.put("restapiUrl", "http://echo.getpostman" +
437                 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
438         restconf.sendRequest(p, ctx);
439         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_PUT));
440     }
441
442     /**
443      * Verifies encoding of parameters to XML data format with augment as
444      * root child.
445      *
446      * @throws SvcLogicException when test case fails
447      */
448     @Test
449     public void encodeToXmlWithAugAsRootChild() throws SvcLogicException {
450         String pre = "test-yang_cont1.cont2.";
451         SvcLogicContext ctx = createAttListYang(pre);
452         p.put("dirPath", "src/test/resources");
453         p.put("format", "xml");
454         p.put("httpMethod", "post");
455         p.put("restapiUrl", "http://echo.getpostman" +
456                 ".com/restconf/operations/test-yang:cont1/cont2/cont4");
457         restconf.sendRequest(p, ctx);
458         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_YANG_AUG_POST));
459     }
460
461     /**
462      * Verifies decoding of parameters from XML data format with containers,
463      * grouping and augment.
464      *
465      * @throws SvcLogicException when test case fails
466      */
467     @Test
468     public void decodeToXmlYang() throws SvcLogicException {
469         createMockForDecode(ENCODE_TO_XML_YANG);
470         SvcLogicContext ctx = new SvcLogicContext();
471         String pre = "test-yang_cont1.cont2.";
472         p.put("dirPath", "src/test/resources");
473         p.put("format", "xml");
474         p.put("httpMethod", "get");
475         p.put("restapiUrl", "http://echo.getpostman" +
476                 ".com/restconf/operations/test-yang:cont1");
477         restconf.sendRequest(p, ctx);
478         verifyAttListYang(ctx, pre);
479     }
480
481     /**
482      * Verifies encoding of and decoding from, JSON respectively for data
483      * format with containers, grouping and augment.
484      *
485      * @throws SvcLogicException when test case fails
486      */
487     @Test
488     public void codecToJsonRpc() throws SvcLogicException {
489         createMockForDecode(DECODE_FROM_JSON_RPC);
490         String inPre = "test-yang_create-sfc.input.";
491         String outPre = "test-yang_create-sfc.output.";
492         SvcLogicContext ctx = createAttListRpc(inPre);
493         p.put("dirPath", "src/test/resources");
494         p.put("format", "json");
495         p.put("httpMethod", "post");
496         p.put("restapiUrl", "http://echo.getpostman" +
497                 ".com/restconf/operations/test-yang:create-sfc");
498         restconf.sendRequest(p, ctx);
499         assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_RPC));
500         verifyAttListRpc(ctx, outPre);
501     }
502
503     /**
504      * Verifies encoding of and decoding from, XML respectively for data
505      * format with containers, grouping and augment.
506      *
507      * @throws SvcLogicException when test case fails
508      */
509     @Test
510     public void codecToXmlRpc() throws SvcLogicException {
511         createMockForDecode(DECODE_FROM_XML_RPC);
512         String inPre = "test-yang_create-sfc.input.";
513         String outPre = "test-yang_create-sfc.output.";
514         SvcLogicContext ctx = createAttListRpc(inPre);
515         p.put("dirPath", "src/test/resources");
516         p.put("format", "xml");
517         p.put("httpMethod", "post");
518         p.put("restapiUrl", "http://echo.getpostman" +
519                 ".com/restconf/operations/test-yang:create-sfc");
520         restconf.sendRequest(p, ctx);
521         assertThat(dfCaptor.getResult(), is(ENCODE_TO_XML_RPC));
522         verifyAttListRpc(ctx, outPre);
523     }
524
525     /**
526      * Verifies URL parser returning path with only schema information for all
527      * kind of URL.
528      *
529      * @throws SvcLogicException when test case fails
530      */
531     @Test
532     public void validateUrlParser() throws SvcLogicException {
533         String actVal = "identity-test:test";
534         String putId = "/for-put";
535         String url1 = "http://echo.getpostman.com/restconf/operations/" +
536                 actVal;
537         String url2 = "http://echo.getpostman.com/restconf/data/" + actVal;
538         String url3 = "https://echo.getpostman.com/restconf/operations/" +
539                 actVal;
540         String url4 = "https://echo.getpostman.com/restconf/data/" + actVal +
541                 putId;
542         String url5 = "http://localhost:8282/restconf/operations/" + actVal;
543         String url6 = "https://localhost:8282/restconf/operations/" + actVal;
544         String url7 = "http://localhost:8282/restconf/data/" + actVal +
545                 putId;
546         String url8 = "https://localhost:8282/restconf/data/" + actVal;
547         String url9 = "http://182.2.61.24:2250/restconf/data/" + actVal;
548         String url10 = "https://182.2.61.24:2250/restconf/operations/" + actVal;
549         String val1 = parseUrl(url1, POST);
550         String val2 = parseUrl(url2, GET);
551         String val3 = parseUrl(url3, PATCH);
552         String val4 = parseUrl(url4, PUT);
553         String val5 = parseUrl(url5, GET);
554         String val6 = parseUrl(url6, POST);
555         String val7 = parseUrl(url7, PUT);
556         String val8 = parseUrl(url8, POST);
557         String val9 = parseUrl(url9, GET);
558         String val10 = parseUrl(url10, POST);
559         assertThat(val1, is(actVal));
560         assertThat(val2, is(actVal));
561         assertThat(val3, is(actVal));
562         assertThat(val4, is(actVal + putId));
563         assertThat(val5, is(actVal));
564         assertThat(val6, is(actVal));
565         assertThat(val7, is(actVal + putId));
566         assertThat(val8, is(actVal));
567         assertThat(val9, is(actVal));
568         assertThat(val10, is(actVal));
569     }
570
571     /**
572      * Creates attribute list for encoding JSON or XML with identity-ref YANG
573      * file.
574      *
575      * @param pre prefix
576      * @return service logic context
577      */
578     private SvcLogicContext createAttList(String pre) {
579         SvcLogicContext ctx = new SvcLogicContext();
580         String pre1 = pre + "con1.interfaces.";
581         ctx.setAttribute(pre + "con1.interface", "identity-types:physical");
582         ctx.setAttribute(pre1 + "int-list[0].iden", "optical");
583         ctx.setAttribute(pre1 + "int-list[0].available.ll[0]", "Giga");
584         ctx.setAttribute(pre1 + "int-list[0].available.ll[1]",
585                          "identity-types:Loopback");
586         ctx.setAttribute(pre1 + "int-list[0].available.ll[2]",
587                          "identity-types-second:Ethernet");
588         ctx.setAttribute(pre1 + "int-list[0].available.leaf1", "58");
589         ctx.setAttribute(pre1 + "int-list[0].available.leaf2",
590                          "identity-types-second:iden2");
591
592         ctx.setAttribute(pre1 + "int-list[1].iden", "214748364");
593         ctx.setAttribute(pre1 + "int-list[1].available.ll[0]", "Giga");
594         ctx.setAttribute(pre1 + "int-list[1].available.ll[1]",
595                          "identity-types:Loopback");
596         ctx.setAttribute(pre1 + "int-list[1].available.ll[2]",
597                          "identity-types-second:Ethernet");
598         ctx.setAttribute(pre1 + "int-list[1].available.leaf1",
599                          "8888");
600         ctx.setAttribute(pre1 + "int-list[1].available.leaf2",
601                          "identity-types-second:iden2");
602         return ctx;
603     }
604
605     /**
606      * Creates attribute list for encoding JSON or XML with container,
607      * grouping and augmented YANG file.
608      *
609      * @param pre prefix
610      * @return service logic context
611      */
612     private SvcLogicContext createAttListYang(String pre) {
613         SvcLogicContext ctx = new SvcLogicContext();
614         ctx.setAttribute(pre + "cont3.leaf10", "abc");
615         ctx.setAttribute(pre + "list1[0].leaf1", "true");
616         ctx.setAttribute(pre + "list1[0].leaf2", "abc");
617         ctx.setAttribute(pre + "list1[0].leaf3", "abc");
618         ctx.setAttribute(pre + "list1[0].ll1[0]", "abc");
619         ctx.setAttribute(pre + "list1[0].ll1[1]", "abc");
620         ctx.setAttribute(pre + "list1[0].ll2[0]", "abc");
621         ctx.setAttribute(pre + "list1[0].ll2[1]", "abc");
622         ctx.setAttribute(pre + "list1[0].cont4.leaf11", "abc");
623         ctx.setAttribute(pre + "list1[0].list4[0].leaf8", "abc");
624         ctx.setAttribute(pre + "list1[0].list4[1].leaf8", "abc");
625         ctx.setAttribute(pre + "list1[0].list5[0].leaf9", "abc");
626         ctx.setAttribute(pre + "list1[0].list5[1].leaf9", "abc");
627         ctx.setAttribute(pre + "list1[1].leaf1", "true");
628         ctx.setAttribute(pre + "list1[1].leaf2", "abc");
629         ctx.setAttribute(pre + "list1[1].leaf3", "abc");
630         ctx.setAttribute(pre + "list1[1].ll1[0]", "abc");
631         ctx.setAttribute(pre + "list1[1].ll1[1]", "abc");
632         ctx.setAttribute(pre + "list1[1].ll2[0]", "abc");
633         ctx.setAttribute(pre + "list1[1].ll2[1]", "abc");
634         ctx.setAttribute(pre + "list1[1].cont4.leaf11", "abc");
635         ctx.setAttribute(pre + "list1[1].list4[0].leaf8", "abc");
636         ctx.setAttribute(pre + "list1[1].list4[1].leaf8", "abc");
637         ctx.setAttribute(pre + "list1[1].list5[0].leaf9", "abc");
638         ctx.setAttribute(pre + "list1[1].list5[1].leaf9", "abc");
639         ctx.setAttribute(pre + "list2[0].leaf4", "abc");
640         ctx.setAttribute(pre + "list2[1].leaf4", "abc");
641         ctx.setAttribute(pre + "leaf5", "abc");
642         ctx.setAttribute(pre + "leaf6", "abc");
643         ctx.setAttribute(pre + "ll3[0]", "abc");
644         ctx.setAttribute(pre + "ll3[1]", "abc");
645         ctx.setAttribute(pre + "ll4[0]", "abc");
646         ctx.setAttribute(pre + "ll4[1]", "abc");
647         ctx.setAttribute(pre + "cont4.leaf10", "abc");
648         ctx.setAttribute(pre + "list6[0].leaf11", "abc");
649         ctx.setAttribute(pre + "list6[1].leaf11", "abc");
650         ctx.setAttribute(pre + "leaf12", "abc");
651         ctx.setAttribute(pre + "ll5[0]", "abc");
652         ctx.setAttribute(pre + "ll5[1]", "abc");
653         ctx.setAttribute(pre + "cont4.test-augment_cont5.leaf13", "true");
654         ctx.setAttribute(pre + "cont4.test-augment_list7[0].leaf14", "test");
655         ctx.setAttribute(pre + "cont4.test-augment_list7[1].leaf14", "create");
656         ctx.setAttribute(pre + "cont4.test-augment_leaf15", "abc");
657         ctx.setAttribute(pre + "cont4.test-augment_ll6[0]", "unbounded");
658         ctx.setAttribute(pre + "cont4.test-augment_ll6[1]", "8");
659         ctx.setAttribute(pre + "cont4.test-augment_cont13.cont12.leaf26",
660                          "abc");
661         ctx.setAttribute(pre + "cont4.test-augment_cont13.list9[0].leaf27",
662                          "abc");
663         ctx.setAttribute(pre + "cont4.test-augment_cont13.list9[1].leaf27",
664                          "abc");
665         ctx.setAttribute(pre + "cont4.test-augment_cont13.leaf28", "abc");
666         ctx.setAttribute(pre + "cont4.test-augment_cont13.ll9[0]", "abc");
667         ctx.setAttribute(pre + "cont4.test-augment_cont13.ll9[1]", "abc");
668         return ctx;
669     }
670
671     /**
672      * Creates attribute list for encoding JSON or XML with RPC YANG file.
673      *
674      * @param pre prefix
675      * @return service logic context
676      */
677     private SvcLogicContext createAttListRpc(String pre) {
678         SvcLogicContext ctx = new SvcLogicContext();
679         ctx.setAttribute(pre + "cont14.leaf28", "abc");
680         ctx.setAttribute(pre + "list10[0].leaf29", "abc");
681         ctx.setAttribute(pre + "list10[1].leaf29", "abc");
682         ctx.setAttribute(pre + "leaf30", "abc");
683         ctx.setAttribute(pre + "ll10[0]", "abc");
684         ctx.setAttribute(pre + "ll10[1]", "abc");
685         ctx.setAttribute(pre + "cont15.leaf31", "abc");
686         ctx.setAttribute(pre + "cont13.list9[0].leaf27", "abc");
687         ctx.setAttribute(pre + "cont13.list9[1].leaf27", "abc");
688         ctx.setAttribute(pre + "cont13.leaf28", "abc");
689         ctx.setAttribute(pre + "cont13.ll9[0]", "abc");
690         ctx.setAttribute(pre + "cont13.ll9[1]", "abc");
691         return ctx;
692     }
693
694     /**
695      * Verifies the attribute list for decoding from JSON or XML with
696      * identity-ref YANG file.
697      *
698      * @param ctx service logic context
699      * @param pre prefix
700      */
701     private void verifyAttList(SvcLogicContext ctx, String pre) {
702         String pre1 = pre + "con1.interfaces.";
703         assertThat(ctx.getAttribute(pre + "con1.interface"), is(
704                 "identity-types:physical"));
705         assertThat(ctx.getAttribute(pre + "con1.interface"), is(
706                 "identity-types:physical"));
707         assertThat(ctx.getAttribute(pre1 + "int-list[0].iden"), is("optical"));
708         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[0]"), is(
709                 "Giga"));
710         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[1]"), is(
711                 "identity-types:Loopback"));
712         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.ll[2]"), is(
713                 "identity-types-second:Ethernet"));
714         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.leaf1"), is(
715                 "58"));
716         assertThat(ctx.getAttribute(pre1 + "int-list[0].available.leaf2"), is(
717                 "identity-types-second:iden2"));
718
719         assertThat(ctx.getAttribute(pre1 + "int-list[1].iden"), is(
720                 "214748364"));
721         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[0]"), is(
722                 "Giga"));
723         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[1]"), is(
724                 "identity-types:Loopback"));
725         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.ll[2]"), is(
726                 "identity-types-second:Ethernet"));
727         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.leaf1"), is(
728                 "8888"));
729         assertThat(ctx.getAttribute(pre1 + "int-list[1].available.leaf2"), is(
730                 "identity-types-second:iden2"));
731     }
732
733     /**
734      * Verifies the attribute list for decoding from JSON or XML with
735      * container, grouping and augmented file.
736      *
737      * @param ctx service logic context
738      * @param pre prefix
739      */
740     private void verifyAttListYang(SvcLogicContext ctx, String pre) {
741         assertThat(ctx.getAttribute(pre + "cont3.leaf10"), is("abc"));
742         assertThat(ctx.getAttribute(pre + "list1[0].leaf1"), is("true"));
743         assertThat(ctx.getAttribute(pre + "list1[0].leaf2"), is("abc"));
744         assertThat(ctx.getAttribute(pre + "list1[0].leaf3"), is("abc"));
745         assertThat(ctx.getAttribute(pre + "list1[0].ll1[0]"), is("abc"));
746         assertThat(ctx.getAttribute(pre + "list1[0].ll1[1]"), is("abc"));
747         assertThat(ctx.getAttribute(pre + "list1[0].ll2[0]"), is("abc"));
748         assertThat(ctx.getAttribute(pre + "list1[0].ll2[1]"), is("abc"));
749         assertThat(ctx.getAttribute(pre + "list1[0].cont4.leaf11"), is("abc"));
750         assertThat(ctx.getAttribute(pre + "list1[0].list4[0].leaf8"),
751                    is("abc"));
752         assertThat(ctx.getAttribute(pre + "list1[0].list4[1].leaf8"),
753                    is("abc"));
754         assertThat(ctx.getAttribute(pre + "list1[0].list5[0].leaf9"),
755                    is("abc"));
756         assertThat(ctx.getAttribute(pre + "list1[0].list5[1].leaf9"),
757                    is("abc"));
758         assertThat(ctx.getAttribute(pre + "list1[1].leaf1"), is("true"));
759         assertThat(ctx.getAttribute(pre + "list1[1].leaf2"), is("abc"));
760         assertThat(ctx.getAttribute(pre + "list1[1].leaf3"), is("abc"));
761         assertThat(ctx.getAttribute(pre + "list1[1].ll1[0]"), is("abc"));
762         assertThat(ctx.getAttribute(pre + "list1[1].ll1[1]"), is("abc"));
763         assertThat(ctx.getAttribute(pre + "list1[1].ll2[0]"), is("abc"));
764         assertThat(ctx.getAttribute(pre + "list1[1].ll2[1]"), is("abc"));
765         assertThat(ctx.getAttribute(pre + "list1[1].cont4.leaf11"), is("abc"));
766         assertThat(ctx.getAttribute(pre + "list1[1].list4[0].leaf8"),
767                    is("abc"));
768         assertThat(ctx.getAttribute(pre + "list1[1].list4[1].leaf8"),
769                    is("abc"));
770         assertThat(ctx.getAttribute(pre + "list1[1].list5[0].leaf9"),
771                    is("abc"));
772         assertThat(ctx.getAttribute(pre + "list1[1].list5[1].leaf9"),
773                    is("abc"));
774         assertThat(ctx.getAttribute(pre + "list2[0].leaf4"), is("abc"));
775         assertThat(ctx.getAttribute(pre + "list2[1].leaf4"), is("abc"));
776         assertThat(ctx.getAttribute(pre + "leaf5"), is("abc"));
777         assertThat(ctx.getAttribute(pre + "leaf6"), is("abc"));
778         assertThat(ctx.getAttribute(pre + "ll3[0]"), is("abc"));
779         assertThat(ctx.getAttribute(pre + "ll3[1]"), is("abc"));
780         assertThat(ctx.getAttribute(pre + "ll4[0]"), is("abc"));
781         assertThat(ctx.getAttribute(pre + "ll4[1]"), is("abc"));
782         assertThat(ctx.getAttribute(pre + "cont4.leaf10"), is( "abc"));
783         assertThat(ctx.getAttribute(pre + "list6[0].leaf11"), is("abc"));
784         assertThat(ctx.getAttribute(pre + "list6[1].leaf11"), is("abc"));
785         assertThat(ctx.getAttribute(pre + "leaf12"), is("abc"));
786         assertThat(ctx.getAttribute(pre + "ll5[0]"), is("abc"));
787         assertThat(ctx.getAttribute(pre + "ll5[1]"), is("abc"));
788         assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont5.leaf13"),
789                    is("true"));
790         assertThat(ctx.getAttribute(pre + "cont4.test-augment_list7[0].leaf14"),
791                    is("test"));
792         assertThat(ctx.getAttribute(pre + "cont4.test-augment_list7[1].leaf14"),
793                    is("create"));
794         assertThat(ctx.getAttribute(pre + "cont4.test-augment_leaf15"),
795                    is("abc"));
796         assertThat(ctx.getAttribute(pre + "cont4.test-augment_ll6[0]"),
797                    is("unbounded"));
798         assertThat(ctx.getAttribute(pre + "cont4.test-augment_ll6[1]"),
799                    is("8"));
800         assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13" +
801                                             ".cont12.leaf26"), is("abc"));
802         assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.list9[0]" +
803                                             ".leaf27"), is("abc"));
804         assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.list9[1]" +
805                                             ".leaf27"), is("abc"));
806         assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.leaf28"),
807                    is("abc"));
808         assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.ll9[0]"),
809                    is("abc"));
810         assertThat(ctx.getAttribute(pre + "cont4.test-augment_cont13.ll9[1]"),
811                    is("abc"));
812     }
813
814     /**
815      * Verifies the attribute list for decoding from JSON or XML with
816      * RPC YANG file.
817      *
818      * @param ctx service logic context
819      * @param pre prefix
820      */
821     private void verifyAttListRpc(SvcLogicContext ctx, String pre) {
822         assertThat(ctx.getAttribute(pre + "cont16.leaf32"), is("abc"));
823         assertThat(ctx.getAttribute(pre + "list11[0].leaf33"), is("abc"));
824         assertThat(ctx.getAttribute(pre + "list11[1].leaf33"), is("abc"));
825         assertThat(ctx.getAttribute(pre + "leaf34"), is("abc"));
826         assertThat(ctx.getAttribute(pre + "ll11[0]"), is("abc"));
827         assertThat(ctx.getAttribute(pre + "ll11[1]"), is("abc"));
828         assertThat(ctx.getAttribute(pre + "cont17.leaf35"), is("abc"));
829         assertThat(ctx.getAttribute(pre + "cont13.cont12.leaf26"), is("abc"));
830         assertThat(ctx.getAttribute(pre + "cont13.list9[0].leaf27"), is("abc"));
831         assertThat(ctx.getAttribute(pre + "cont13.list9[1].leaf27"), is("abc"));
832         assertThat(ctx.getAttribute(pre + "cont13.ll9[0]"), is("abc"));
833         assertThat(ctx.getAttribute(pre + "cont13.ll9[1]"), is("abc"));
834         assertThat(ctx.getAttribute(pre + "cont13.leaf28"), is("abc"));
835     }
836
837     /**
838      * Captures the data format messages by mocking it, which can be used in
839      * testing the value.
840      *
841      * @param <String> capturing data format
842      */
843     public class DfCaptor<String> implements Answer {
844
845         private String result;
846
847         /**
848          * Returns the captured data format message.
849          *
850          * @return data format message.
851          */
852         public String getResult() {
853             return result;
854         }
855
856         @Override
857         public String answer(InvocationOnMock invocationOnMock)
858                 throws Throwable {
859             result = (String) invocationOnMock.callRealMethod();
860             return result;
861         }
862     }
863
864 }