Resolving root level augment nodes
[ccsdk/sli/plugins.git] / restconf-client / provider / src / test / java / org / onap / ccsdk / sli / plugins / yangserializers / dfserializer / DataFormatUtilsTest.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 /**
24  * Unit test case utilities for data format serializer and restconf api call
25  * node.
26  */
27 public final class DataFormatUtilsTest {
28
29     static final String ENCODE_TO_JSON_ID = "{\n" +
30             "    \"identity-test:con1\": {\n" +
31             "        \"interfaces\": {\n" +
32             "            \"int-list\": [\n" +
33             "                {\n" +
34             "                    \"iden\": \"optical\",\n" +
35             "                    \"available\": {\n" +
36             "                        \"ll\": [\n" +
37             "                            \"Giga\",\n" +
38             "                            \"identity-types:Loopback\",\n" +
39             "                            \"identity-types-second:Ethernet" +
40             "\"\n" +
41             "                        ],\n" +
42             "                        \"leaf1\": \"58\",\n" +
43             "                        \"leaf2\": \"identity-types-second:iden" +
44             "2\"\n" +
45             "                    }\n" +
46             "                },\n" +
47             "                {\n" +
48             "                    \"iden\": \"214748364\",\n" +
49             "                    \"available\": {\n" +
50             "                        \"ll\": [\n" +
51             "                            \"Giga\",\n" +
52             "                            \"identity-types:Loopback\",\n" +
53             "                            \"identity-types-second:Ethernet" +
54             "\"\n" +
55             "                        ],\n" +
56             "                        \"leaf1\": \"8888\",\n" +
57             "                        \"leaf2\": \"identity-types-second:ide" +
58             "n2\"\n" +
59             "                    }\n" +
60             "                }\n" +
61             "            ]\n" +
62             "        },\n" +
63             "        \"interface\": \"identity-types:physical\"\n" +
64             "    },\n" +
65             "    \"identity-test:l\": \"abc\"\n" +
66             "}";
67
68     static final String ENCODE_TO_XML_ID = "<?xml version=\"1.0\" encoding=" +
69             "\"UTF-8\" standalone=\"no\"?>\n" +
70             "<con1 xmlns=\"identity:ns:test:json:ser\">\n" +
71             "    <interfaces>\n" +
72             "        <int-list>\n" +
73             "            <iden>optical</iden>\n" +
74             "            <available>\n" +
75             "                <ll>Giga</ll>\n" +
76             "                <ll xmlns:yangid=\"identity:list:ns:test:json:se" +
77             "r\">yangid:Loopback</ll>\n" +
78             "                <ll xmlns:yangid=\"identity:list:second:ns:test" +
79             ":json:ser\">yangid:Ethernet</ll>\n" +
80             "                <leaf1>58</leaf1>\n" +
81             "                <leaf2 xmlns:yangid=\"identity:list:second:ns:t" +
82             "est:json:ser\">yangid:iden2</leaf2>\n" +
83             "            </available>\n" +
84             "        </int-list>\n" +
85             "        <int-list>\n" +
86             "            <iden>214748364</iden>\n" +
87             "            <available>\n" +
88             "                <ll>Giga</ll>\n" +
89             "                <ll xmlns:yangid=\"identity:list:ns:test:json:s" +
90             "er\">yangid:Loopback</ll>\n" +
91             "                <ll xmlns:yangid=\"identity:list:second:ns:test" +
92             ":json:ser\">yangid:Ethernet</ll>\n" +
93             "                <leaf1>8888</leaf1>\n" +
94             "                <leaf2 xmlns:yangid=\"identity:list:second:ns:t" +
95             "est:json:ser\">yangid:iden2</leaf2>\n" +
96             "            </available>\n" +
97             "        </int-list>\n" +
98             "    </interfaces>\n" +
99             "    <interface xmlns:yangid=\"identity:list:ns:test:json:ser\">" +
100             "yangid:physical</interface>\n" +
101             "</con1>\n";
102
103     static final String ENCODE_TO_JSON_YANG_COMMON = "\n    " +
104             "\"test-augment:cont13\": {\n" +
105             "        \"ll9\": [\n" +
106             "            \"abc\",\n" +
107             "            \"abc\"\n" +
108             "        ],\n" +
109             "        \"list9\": [\n" +
110             "            {\n" +
111             "                \"leaf27\": \"abc\"\n" +
112             "            },\n" +
113             "            {\n" +
114             "                \"leaf27\": \"abc\"\n" +
115             "            }\n" +
116             "        ],\n" +
117             "        \"leaf28\": \"abc\",\n" +
118             "        \"cont12\": {\n" +
119             "            \"leaf26\": \"abc\"\n" +
120             "        }\n" +
121             "    },\n" +
122             "    \"test-augment:list7\": [\n" +
123             "        {\n" +
124             "            \"leaf14\": \"test\"\n" +
125             "        },\n" +
126             "        {\n" +
127             "            \"leaf14\": \"create\"\n" +
128             "        }\n" +
129             "    ],\n" +
130             "    \"test-augment:leaf15\": \"abc\",\n" +
131             "    \"test-augment:ll6\": [\n" +
132             "        \"unbounded\",\n" +
133             "        \"8\"\n" +
134             "    ],\n" +
135             "    \"test-augment:cont5\": {\n" +
136             "        \"leaf13\": \"true\"\n" +
137             "    }";
138
139     static final String ENCODE_TO_JSON_YANG_AUG_POST = "{\n" +
140             "    \"test-yang:leaf10\": \"abc\"," +
141             ENCODE_TO_JSON_YANG_COMMON + "\n}";
142
143     static final String ENCODE_TO_JSON_YANG = "{\n" +
144             "    \"test-yang:cont2\": {\n" +
145             "        \"list1\": [\n" +
146             "            {\n" +
147             "                \"ll1\": [\n" +
148             "                    \"abc\",\n" +
149             "                    \"abc\"\n" +
150             "                ],\n" +
151             "                \"leaf1\": \"true\",\n" +
152             "                \"ll2\": [\n" +
153             "                    \"abc\",\n" +
154             "                    \"abc\"\n" +
155             "                ],\n" +
156             "                \"list5\": [\n" +
157             "                    {\n" +
158             "                        \"leaf9\": \"abc\"\n" +
159             "                    },\n" +
160             "                    {\n" +
161             "                        \"leaf9\": \"abc\"\n" +
162             "                    }\n" +
163             "                ],\n" +
164             "                \"leaf3\": \"abc\",\n" +
165             "                \"leaf2\": \"abc\",\n" +
166             "                \"list4\": [\n" +
167             "                    {\n" +
168             "                        \"leaf8\": \"abc\"\n" +
169             "                    },\n" +
170             "                    {\n" +
171             "                        \"leaf8\": \"abc\"\n" +
172             "                    }\n" +
173             "                ],\n" +
174             "                \"cont4\": {\n" +
175             "                    \"leaf11\": \"abc\"\n" +
176             "                }\n" +
177             "            },\n" +
178             "            {\n" +
179             "                \"ll1\": [\n" +
180             "                    \"abc\",\n" +
181             "                    \"abc\"\n" +
182             "                ],\n" +
183             "                \"leaf1\": \"true\",\n" +
184             "                \"ll2\": [\n" +
185             "                    \"abc\",\n" +
186             "                    \"abc\"\n" +
187             "                ],\n" +
188             "                \"leaf3\": \"abc\",\n" +
189             "                \"list5\": [\n" +
190             "                    {\n" +
191             "                        \"leaf9\": \"abc\"\n" +
192             "                    },\n" +
193             "                    {\n" +
194             "                        \"leaf9\": \"abc\"\n" +
195             "                    }\n" +
196             "                ],\n" +
197             "                \"list4\": [\n" +
198             "                    {\n" +
199             "                        \"leaf8\": \"abc\"\n" +
200             "                    },\n" +
201             "                    {\n" +
202             "                        \"leaf8\": \"abc\"\n" +
203             "                    }\n" +
204             "                ],\n" +
205             "                \"leaf2\": \"abc\",\n" +
206             "                \"cont4\": {\n" +
207             "                    \"leaf11\": \"abc\"\n" +
208             "                }\n" +
209             "            }\n" +
210             "        ],\n" +
211             "        \"ll3\": [\n" +
212             "            \"abc\",\n" +
213             "            \"abc\"\n" +
214             "        ],\n" +
215             "        \"ll5\": [\n" +
216             "            \"abc\",\n" +
217             "            \"abc\"\n" +
218             "        ],\n" +
219             "        \"cont4\": {\n" +
220             "            \"leaf10\": \"abc\"," +
221             addSpace(ENCODE_TO_JSON_YANG_COMMON, 8) + "\n" +
222             "        },\n" +
223             "        \"ll4\": [\n" +
224             "            \"abc\",\n" +
225             "            \"abc\"\n" +
226             "        ],\n" +
227             "        \"cont3\": {\n" +
228             "            \"leaf10\": \"abc\"\n" +
229             "        },\n" +
230             "        \"leaf5\": \"abc\",\n" +
231             "        \"list2\": [\n" +
232             "            {\n" +
233             "                \"leaf4\": \"abc\"\n" +
234             "            },\n" +
235             "            {\n" +
236             "                \"leaf4\": \"abc\"\n" +
237             "            }\n" +
238             "        ],\n" +
239             "        \"leaf12\": \"abc\",\n" +
240             "        \"leaf6\": \"abc\",\n" +
241             "        \"list6\": [\n" +
242             "            {\n" +
243             "                \"leaf11\": \"abc\"\n" +
244             "            },\n" +
245             "            {\n" +
246             "                \"leaf11\": \"abc\"\n" +
247             "            }\n" +
248             "        ]\n" +
249             "    }\n" +
250             "}";
251
252     static final String ENCODE_TO_XML_YANG = "<?xml version=\"1.0\" encoding" +
253             "=\"UTF-8\" standalone=\"no\"?>\n" +
254             "<cont2 xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">\n" +
255             "    <list1>\n" +
256             "        <ll1>abc</ll1>\n" +
257             "        <ll1>abc</ll1>\n" +
258             "        <leaf1>true</leaf1>\n" +
259             "        <ll2>abc</ll2>\n" +
260             "        <ll2>abc</ll2>\n" +
261             "        <list5>\n" +
262             "            <leaf9>abc</leaf9>\n" +
263             "        </list5>\n" +
264             "        <list5>\n" +
265             "            <leaf9>abc</leaf9>\n" +
266             "        </list5>\n" +
267             "        <leaf3>abc</leaf3>\n" +
268             "        <leaf2>abc</leaf2>\n" +
269             "        <list4>\n" +
270             "            <leaf8>abc</leaf8>\n" +
271             "        </list4>\n" +
272             "        <list4>\n" +
273             "            <leaf8>abc</leaf8>\n" +
274             "        </list4>\n" +
275             "        <cont4>\n" +
276             "            <leaf11>abc</leaf11>\n" +
277             "        </cont4>\n" +
278             "    </list1>\n" +
279             "    <list1>\n" +
280             "        <ll1>abc</ll1>\n" +
281             "        <ll1>abc</ll1>\n" +
282             "        <leaf1>true</leaf1>\n" +
283             "        <ll2>abc</ll2>\n" +
284             "        <ll2>abc</ll2>\n" +
285             "        <leaf3>abc</leaf3>\n" +
286             "        <list5>\n" +
287             "            <leaf9>abc</leaf9>\n" +
288             "        </list5>\n" +
289             "        <list5>\n" +
290             "            <leaf9>abc</leaf9>\n" +
291             "        </list5>\n" +
292             "        <list4>\n" +
293             "            <leaf8>abc</leaf8>\n" +
294             "        </list4>\n" +
295             "        <list4>\n" +
296             "            <leaf8>abc</leaf8>\n" +
297             "        </list4>\n" +
298             "        <leaf2>abc</leaf2>\n" +
299             "        <cont4>\n" +
300             "            <leaf11>abc</leaf11>\n" +
301             "        </cont4>\n" +
302             "    </list1>\n" +
303             "    <ll3>abc</ll3>\n" +
304             "    <ll3>abc</ll3>\n" +
305             "    <ll5>abc</ll5>\n" +
306             "    <ll5>abc</ll5>\n" +
307             "    <cont4>\n" +
308             "        <leaf10>abc</leaf10>\n" +
309             "        <cont13 xmlns=\"urn:opendaylight:params:xml:ns:yang:" +
310             "augment\">\n" +
311             "            <ll9>abc</ll9>\n" +
312             "            <ll9>abc</ll9>\n" +
313             "            <list9>\n" +
314             "                <leaf27>abc</leaf27>\n" +
315             "            </list9>\n" +
316             "            <list9>\n" +
317             "                <leaf27>abc</leaf27>\n" +
318             "            </list9>\n" +
319             "            <leaf28>abc</leaf28>\n" +
320             "            <cont12>\n" +
321             "                <leaf26>abc</leaf26>\n" +
322             "            </cont12>\n" +
323             "        </cont13>\n" +
324             "        <list7 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" +
325             "ugment\">\n" +
326             "            <leaf14>test</leaf14>\n" +
327             "        </list7>\n" +
328             "        <list7 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" +
329             "ugment\">\n" +
330             "            <leaf14>create</leaf14>\n" +
331             "        </list7>\n" +
332             "        <leaf15 xmlns=\"urn:opendaylight:params:xml:ns:yang:" +
333             "augment\">abc</leaf15>\n" +
334             "        <ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:aug" +
335             "ment\">unbounded</ll6>\n" +
336             "        <ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:aug" +
337             "ment\">8</ll6>\n" +
338             "        <cont5 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" +
339             "ugment\">\n" +
340             "            <leaf13>true</leaf13>\n" +
341             "        </cont5>\n" +
342             "    </cont4>\n" +
343             "    <ll4>abc</ll4>\n" +
344             "    <ll4>abc</ll4>\n" +
345             "    <cont3>\n" +
346             "        <leaf10>abc</leaf10>\n" +
347             "    </cont3>\n" +
348             "    <leaf5>abc</leaf5>\n" +
349             "    <list2>\n" +
350             "        <leaf4>abc</leaf4>\n" +
351             "    </list2>\n" +
352             "    <list2>\n" +
353             "        <leaf4>abc</leaf4>\n" +
354             "    </list2>\n" +
355             "    <leaf12>abc</leaf12>\n" +
356             "    <leaf6>abc</leaf6>\n" +
357             "    <list6>\n" +
358             "        <leaf11>abc</leaf11>\n" +
359             "    </list6>\n" +
360             "    <list6>\n" +
361             "        <leaf11>abc</leaf11>\n" +
362             "    </list6>\n" +
363             "</cont2>\n";
364
365
366     static final String ENCODE_TO_JSON_RPC = "{\n" +
367             "    \"test-yang:input\": {\n" +
368             "        \"leaf30\": \"abc\",\n" +
369             "        \"list10\": [\n" +
370             "            {\n" +
371             "                \"leaf29\": \"abc\"\n" +
372             "            },\n" +
373             "            {\n" +
374             "                \"leaf29\": \"abc\"\n" +
375             "            }\n" +
376             "        ],\n" +
377             "        \"cont15\": {\n" +
378             "            \"leaf31\": \"abc\"\n" +
379             "        },\n" +
380             "        \"cont14\": {\n" +
381             "            \"leaf28\": \"abc\"\n" +
382             "        },\n" +
383             "        \"cont13\": {\n" +
384             "            \"list9\": [\n" +
385             "                {\n" +
386             "                    \"leaf27\": \"abc\"\n" +
387             "                },\n" +
388             "                {\n" +
389             "                    \"leaf27\": \"abc\"\n" +
390             "                }\n" +
391             "            ],\n" +
392             "            \"ll9\": [\n" +
393             "                \"abc\",\n" +
394             "                \"abc\"\n" +
395             "            ],\n" +
396             "            \"leaf28\": \"abc\"\n" +
397             "        },\n" +
398             "        \"ll10\": [\n" +
399             "            \"abc\",\n" +
400             "            \"abc\"\n" +
401             "        ]\n" +
402             "    }\n" +
403             "}";
404
405     static final String DECODE_FROM_JSON_RPC = "{\n" +
406             "    \"test-yang:output\": {\n" +
407             "        \"cont16\": {\n" +
408             "            \"leaf32\": \"abc\"\n" +
409             "        },\n" +
410             "        \"list11\": [\n" +
411             "            {\n" +
412             "                \"leaf33\": \"abc\"\n" +
413             "            },\n" +
414             "            {\n" +
415             "                \"leaf33\": \"abc\"\n" +
416             "            }\n" +
417             "        ],\n" +
418             "        \"leaf34\": \"abc\",\n" +
419             "        \"ll11\": [\n" +
420             "            \"abc\",\n" +
421             "            \"abc\"\n" +
422             "        ],\n" +
423             "        \"cont17\": {\n" +
424             "            \"leaf35\": \"abc\"\n" +
425             "        },\n" +
426             "        \"cont13\": {\n" +
427             "            \"cont12\": {\n" +
428             "                \"leaf26\": \"abc\"\n" +
429             "            },\n" +
430             "            \"list9\": [\n" +
431             "                {\n" +
432             "                    \"leaf27\": \"abc\"\n" +
433             "                },\n" +
434             "                {\n" +
435             "                    \"leaf27\": \"abc\"\n" +
436             "                }\n" +
437             "            ],\n" +
438             "            \"ll9\": [\n" +
439             "                \"abc\",\n" +
440             "                \"abc\"\n" +
441             "            ],\n" +
442             "            \"leaf28\": \"abc\"\n" +
443             "        }\n" +
444             "    }\n" +
445             "}";
446
447     static final String ENCODE_TO_XML_RPC = "<?xml version=\"1.0\" encoding" +
448             "=\"UTF-8\" standalone=\"no\"?>\n" +
449             "<input xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">\n" +
450             "    <leaf30>abc</leaf30>\n" +
451             "    <list10>\n" +
452             "        <leaf29>abc</leaf29>\n" +
453             "    </list10>\n" +
454             "    <list10>\n" +
455             "        <leaf29>abc</leaf29>\n" +
456             "    </list10>\n" +
457             "    <cont15>\n" +
458             "        <leaf31>abc</leaf31>\n" +
459             "    </cont15>\n" +
460             "    <cont14>\n" +
461             "        <leaf28>abc</leaf28>\n" +
462             "    </cont14>\n" +
463             "    <cont13>\n" +
464             "        <list9>\n" +
465             "            <leaf27>abc</leaf27>\n" +
466             "        </list9>\n" +
467             "        <list9>\n" +
468             "            <leaf27>abc</leaf27>\n" +
469             "        </list9>\n" +
470             "        <ll9>abc</ll9>\n" +
471             "        <ll9>abc</ll9>\n" +
472             "        <leaf28>abc</leaf28>\n" +
473             "    </cont13>\n" +
474             "    <ll10>abc</ll10>\n" +
475             "    <ll10>abc</ll10>\n" +
476             "</input>\n";
477
478     static final String DECODE_FROM_XML_RPC = "<?xml version=\"1.0\" encodi" +
479             "ng=\"UTF-8\" standalone=\"no\"?>\n" +
480             "<output xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">\n" +
481             "    <cont16>\n" +
482             "        <leaf32>abc</leaf32>\n" +
483             "    </cont16>\n" +
484             "    <list11>\n" +
485             "        <leaf33>abc</leaf33>\n" +
486             "    </list11>\n" +
487             "    <list11>\n" +
488             "        <leaf33>abc</leaf33>\n" +
489             "    </list11>\n" +
490             "    <leaf34>abc</leaf34>\n" +
491             "    <ll11>abc</ll11>\n" +
492             "    <ll11>abc</ll11>\n" +
493             "    <cont17>\n" +
494             "        <leaf35>abc</leaf35>\n" +
495             "    </cont17>\n" +
496             "    <cont13>\n" +
497             "        <cont12>\n" +
498             "            <leaf26>abc</leaf26>\n" +
499             "        </cont12>\n" +
500             "        <list9>\n" +
501             "            <leaf27>abc</leaf27>\n" +
502             "        </list9>\n" +
503             "        <list9>\n" +
504             "            <leaf27>abc</leaf27>\n" +
505             "        </list9>\n" +
506             "        <ll9>abc</ll9>\n" +
507             "        <ll9>abc</ll9>\n" +
508             "        <leaf28>abc</leaf28>\n" +
509             "    </cont13>\n" +
510             "</output>";
511
512     /**
513      * Adds the specified number of space required for a req in each line.
514      *
515      * @param req request message
516      * @param i   number of space
517      * @return space appended string
518      */
519     private static String addSpace(String req, int i) {
520         StringBuilder space = new StringBuilder("");
521         for (int sp = 0; sp < i; sp++) {
522             space = space.append(" ");
523         }
524         return req.replaceAll("\n", "\n" + space.toString());
525     }
526 }