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