2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
24 * Unit test case utilities for data format serializer and restconf api call
27 public final class DataFormatUtilsTest {
29 static final String ENCODE_TO_JSON_ID_COMMON = "\n \"interfaces\"" +
32 " \"int-list\": [\n" +
34 " \"iden\": \"optical\",\n" +
35 " \"available\": {\n" +
38 " \"identity-types:Loopback\",\n" +
39 " \"identity-types-second:Ethernet" +
42 " \"leaf1\": \"58\",\n" +
43 " \"leaf2\": \"identity-types-second:iden" +
48 " \"iden\": \"214748364\",\n" +
49 " \"available\": {\n" +
52 " \"identity-types:Loopback\",\n" +
53 " \"identity-types-second:Ethernet" +
56 " \"leaf1\": \"8888\",\n" +
57 " \"leaf2\": \"identity-types-second:ide" +
63 " \"interface\": \"identity-types:physical\"\n" +
66 static final String ENCODE_TO_JSON_ID = "{\n" +
67 " \"identity-test:con1\": {" + ENCODE_TO_JSON_ID_COMMON +
69 " \"identity-test:l\": \"abc\"\n" +
72 static final String ENCODE_TO_ANYXML = "{\n" +
73 " \"actionIdentifiers\": {\n" +
74 " \"mode\": \"sync\",\n" +
75 " \"blueprintName\": \"baseconfiguration\",\n" +
76 " \"blueprintVersion\": \"1.0.0\",\n" +
77 " \"actionName\": \"assign-activate\"\n" +
80 " \"template-prefix\": \"vDNS-test\",\n" +
81 " \"resource-assignment-request\": {\n" +
82 " \"resource-assignment-properties\": {\n" +
83 " \"service-instance-id\": \"1234\",\n" +
84 " \"vnf-id\": \"3526\",\n" +
85 " \"customer-name\": \"htipl\",\n" +
86 " \"subscriber-name\": \"huawei\"\n" +
90 " \"commonHeader\": {\n" +
91 " \"subRequestId\": \"sub-123456-1000\",\n" +
92 " \"requestId\": \"123456-1000\",\n" +
93 " \"originatorId\": \"SDNC_DG\"\n" +
97 static final String ENCODE_TO_JSON_ID_PUT = "{\n" +
98 " \"identity-test:test\": {\n" +
99 " \"con1\": {" + addSpace(ENCODE_TO_JSON_ID_COMMON, 4) +
101 " \"l\": \"abc\"\n" +
105 static final String ENCODE_TO_XML_ID_COMMON = "\n <interfaces>\n" +
107 " <iden>optical</iden>\n" +
110 " <ll xmlns:yangid=\"identity:list:ns:test:json:se" +
111 "r\">yangid:Loopback</ll>\n" +
112 " <ll xmlns:yangid=\"identity:list:second:ns:test" +
113 ":json:ser\">yangid:Ethernet</ll>\n" +
114 " <leaf1>58</leaf1>\n" +
115 " <leaf2 xmlns:yangid=\"identity:list:second:ns:t" +
116 "est:json:ser\">yangid:iden2</leaf2>\n" +
120 " <iden>214748364</iden>\n" +
123 " <ll xmlns:yangid=\"identity:list:ns:test:json:s" +
124 "er\">yangid:Loopback</ll>\n" +
125 " <ll xmlns:yangid=\"identity:list:second:ns:test" +
126 ":json:ser\">yangid:Ethernet</ll>\n" +
127 " <leaf1>8888</leaf1>\n" +
128 " <leaf2 xmlns:yangid=\"identity:list:second:ns:t" +
129 "est:json:ser\">yangid:iden2</leaf2>\n" +
133 " <interface xmlns:yangid=\"identity:list:ns:test:json:ser\">" +
134 "yangid:physical</interface>";
136 static final String ENCODE_TO_XML_ID = "<?xml version=\"1.0\" encoding=" +
137 "\"UTF-8\" standalone=\"no\"?>\n" +
138 "<con1 xmlns=\"identity:ns:test:json:ser\">" +
139 ENCODE_TO_XML_ID_COMMON + "\n</con1>\n";
141 static final String ENCODE_TO_XML_ID_PUT = "<?xml version=\"1.0\" enco" +
142 "ding=\"UTF-8\" standalone=\"no\"?>\n" +
143 "<test xmlns=\"identity:ns:test:json:ser\">\n" +
144 " <con1>" + addSpace(ENCODE_TO_XML_ID_COMMON, 4)
148 static final String ENCODE_TO_JSON_YANG_COMMON = "\n " +
149 "\"test-augment:ll6\": [\n" +
150 " \"unbounded\",\n" +
153 " \"test-augment:cont13\": {\n" +
160 " \"leaf27\": \"abc\"\n" +
163 " \"leaf27\": \"abc\"\n" +
166 " \"leaf28\": \"abc\",\n" +
168 " \"leaf26\": \"abc\"\n" +
171 " \"test-augment:list7\": [\n" +
173 " \"leaf14\": \"test\"\n" +
176 " \"leaf14\": \"create\"\n" +
179 " \"test-augment:leaf15\": \"abc\",\n" +
180 " \"test-augment:cont5\": {\n" +
181 " \"leaf13\": \"true\"\n" +
184 static final String ENCODE_TO_JSON_YANG_AUG_POST = "{\n" +
185 " \"test-yang:leaf10\": \"abc\"," +
186 ENCODE_TO_JSON_YANG_COMMON + "\n}";
188 static final String ENCODE_TO_JSON_YANG = "{\n" +
189 " \"test-yang:cont2\": {\n" +
196 " \"leaf1\": \"true\",\n" +
203 " \"leaf9\": \"abc\"\n" +
206 " \"leaf9\": \"abc\"\n" +
209 " \"leaf3\": \"abc\",\n" +
210 " \"leaf2\": \"abc\",\n" +
213 " \"leaf8\": \"abc\"\n" +
216 " \"leaf8\": \"abc\"\n" +
220 " \"leaf11\": \"abc\"\n" +
228 " \"leaf1\": \"true\",\n" +
233 " \"leaf3\": \"abc\",\n" +
236 " \"leaf9\": \"abc\"\n" +
239 " \"leaf9\": \"abc\"\n" +
244 " \"leaf8\": \"abc\"\n" +
247 " \"leaf8\": \"abc\"\n" +
250 " \"leaf2\": \"abc\",\n" +
252 " \"leaf11\": \"abc\"\n" +
265 " \"leaf10\": \"abc\"," +
266 addSpace(ENCODE_TO_JSON_YANG_COMMON, 8) + "\n" +
273 " \"leaf10\": \"abc\"\n" +
275 " \"leaf5\": \"abc\",\n" +
278 " \"leaf4\": \"abc\"\n" +
281 " \"leaf4\": \"abc\"\n" +
284 " \"leaf12\": \"abc\",\n" +
285 " \"leaf6\": \"abc\",\n" +
288 " \"leaf11\": \"abc\"\n" +
291 " \"leaf11\": \"abc\"\n" +
297 static final String ENCODE_TO_JSON_YANG_PUT = "{\n" +
298 " \"test-yang:cont4\": {" + addSpace(
299 ENCODE_TO_JSON_YANG_COMMON, 4) + ",\n" +
300 " \"leaf10\": \"abc\"\n" +
304 static final String ENCODE_TO_XML_YANG_COMMON = "\n" +
305 "<ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:aug" +
306 "ment\">unbounded</ll6>\n" +
307 "<ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:aug" +
309 "<cont13 xmlns=\"urn:opendaylight:params:xml:ns:yang:" +
311 " <ll9>abc</ll9>\n" +
312 " <ll9>abc</ll9>\n" +
314 " <leaf27>abc</leaf27>\n" +
317 " <leaf27>abc</leaf27>\n" +
319 " <leaf28>abc</leaf28>\n" +
321 " <leaf26>abc</leaf26>\n" +
324 "<list7 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" +
326 " <leaf14>test</leaf14>\n" +
328 "<list7 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" +
330 " <leaf14>create</leaf14>\n" +
332 "<leaf15 xmlns=\"urn:opendaylight:params:xml:ns:yang:" +
333 "augment\">abc</leaf15>\n" +
334 "<cont5 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" +
336 " <leaf13>true</leaf13>\n" +
339 static final String ENCODE_TO_XML_YANG_AUG_POST = "<?xml version=\"1.0\"" +
340 " encoding=\"UTF-8\" standalone=\"no\"?>\n" +
341 "<leaf10 xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">abc" +
343 ENCODE_TO_XML_YANG_COMMON + "\n";
345 static final String ENCODE_TO_XML_YANG_PUT = "<?xml version=\"1.0\" enc" +
346 "oding=\"UTF-8\" standalone=\"no\"?>\n" +
347 "<cont4 xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">\n" +
348 " <leaf10>abc</leaf10>" +
349 addSpace(ENCODE_TO_XML_YANG_COMMON, 4) + "\n</cont4>\n";
351 static final String ENCODE_TO_XML_YANG = "<?xml version=\"1.0\" encoding" +
352 "=\"UTF-8\" standalone=\"no\"?>\n" +
353 "<cont2 xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">\n" +
355 " <ll1>abc</ll1>\n" +
356 " <ll1>abc</ll1>\n" +
357 " <leaf1>true</leaf1>\n" +
358 " <ll2>abc</ll2>\n" +
359 " <ll2>abc</ll2>\n" +
361 " <leaf9>abc</leaf9>\n" +
364 " <leaf9>abc</leaf9>\n" +
366 " <leaf3>abc</leaf3>\n" +
367 " <leaf2>abc</leaf2>\n" +
369 " <leaf8>abc</leaf8>\n" +
372 " <leaf8>abc</leaf8>\n" +
375 " <leaf11>abc</leaf11>\n" +
379 " <ll1>abc</ll1>\n" +
380 " <ll1>abc</ll1>\n" +
381 " <leaf1>true</leaf1>\n" +
382 " <ll2>abc</ll2>\n" +
383 " <ll2>abc</ll2>\n" +
384 " <leaf3>abc</leaf3>\n" +
386 " <leaf9>abc</leaf9>\n" +
389 " <leaf9>abc</leaf9>\n" +
392 " <leaf8>abc</leaf8>\n" +
395 " <leaf8>abc</leaf8>\n" +
397 " <leaf2>abc</leaf2>\n" +
399 " <leaf11>abc</leaf11>\n" +
402 " <ll3>abc</ll3>\n" +
403 " <ll3>abc</ll3>\n" +
404 " <ll5>abc</ll5>\n" +
405 " <ll5>abc</ll5>\n" +
407 " <leaf10>abc</leaf10>"+
408 addSpace(ENCODE_TO_XML_YANG_COMMON, 8) + "\n" +
410 " <ll4>abc</ll4>\n" +
411 " <ll4>abc</ll4>\n" +
413 " <leaf10>abc</leaf10>\n" +
415 " <leaf5>abc</leaf5>\n" +
417 " <leaf4>abc</leaf4>\n" +
420 " <leaf4>abc</leaf4>\n" +
422 " <leaf12>abc</leaf12>\n" +
423 " <leaf6>abc</leaf6>\n" +
425 " <leaf11>abc</leaf11>\n" +
428 " <leaf11>abc</leaf11>\n" +
432 static final String ENCODE_TO_JSON_RPC = "{\n" +
433 " \"test-yang:input\": {\n" +
434 " \"leaf30\": \"abc\",\n" +
437 " \"leaf29\": \"abc\"\n" +
440 " \"leaf29\": \"abc\"\n" +
444 " \"leaf31\": \"abc\"\n" +
447 " \"leaf28\": \"abc\"\n" +
452 " \"leaf27\": \"abc\"\n" +
455 " \"leaf27\": \"abc\"\n" +
462 " \"leaf28\": \"abc\"\n" +
471 static final String DECODE_FROM_JSON_RPC = "{\n" +
472 " \"test-yang:output\": {\n" +
474 " \"leaf32\": \"abc\"\n" +
478 " \"leaf33\": \"abc\"\n" +
481 " \"leaf33\": \"abc\"\n" +
484 " \"leaf34\": \"abc\",\n" +
490 " \"leaf35\": \"abc\"\n" +
494 " \"leaf26\": \"abc\"\n" +
498 " \"leaf27\": \"abc\"\n" +
501 " \"leaf27\": \"abc\"\n" +
508 " \"leaf28\": \"abc\"\n" +
513 static final String DECODE_ANYXML_RESPONSE = "{\n" +
514 " \"commonHeader\": {\n" +
515 " \"timestamp\": \"2019-05-18T23:42:41.658Z\",\n" +
516 " \"originatorId\": \"System\",\n" +
517 " \"requestId\": \"1234\",\n" +
518 " \"subRequestId\": \"1234-12234\",\n" +
519 " \"flags\": null\n" +
521 " \"actionIdentifiers\": {\n" +
522 " \"blueprintName\": \"golden\",\n" +
523 " \"blueprintVersion\": \"1.0.0\",\n" +
524 " \"actionName\": \"resource-assignment\",\n" +
525 " \"mode\": \"sync\"\n" +
528 " \"code\": 200,\n" +
529 " \"eventType\": \"EVENT_COMPONENT_EXECUTED\",\n" +
530 " \"timestamp\": \"2019-05-18T23:42:41.950Z\",\n" +
531 " \"errorMessage\": null,\n" +
532 " \"message\": \"success\"\n" +
534 " \"payload\": {\n" +
535 " \"resource-assignment-response\": {\n" +
536 " \"meshed-template\": {\n" +
537 " \"vf-module-1\": \"<interface>\\n " +
538 " <description>This is the Virtual Firewall entity</" +
539 "description>\\n <vfw>10.0.101.20/24</vfw>\\n</interface>\"\n" +
543 " \"stepData\": {\n" +
544 " \"name\": \"resource-assignment\",\n" +
545 " \"properties\": {\n" +
546 " \"resource-assignment-params\": null,\n" +
547 " \"status\": null\n" +
552 static final String ENCODE_TO_XML_RPC = "<?xml version=\"1.0\" encoding" +
553 "=\"UTF-8\" standalone=\"no\"?>\n" +
554 "<input xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">\n" +
555 " <leaf30>abc</leaf30>\n" +
557 " <leaf29>abc</leaf29>\n" +
560 " <leaf29>abc</leaf29>\n" +
563 " <leaf31>abc</leaf31>\n" +
566 " <leaf28>abc</leaf28>\n" +
570 " <leaf27>abc</leaf27>\n" +
573 " <leaf27>abc</leaf27>\n" +
575 " <ll9>abc</ll9>\n" +
576 " <ll9>abc</ll9>\n" +
577 " <leaf28>abc</leaf28>\n" +
579 " <ll10>abc</ll10>\n" +
580 " <ll10>abc</ll10>\n" +
583 static final String DECODE_FROM_XML_RPC = "<?xml version=\"1.0\" encodi" +
584 "ng=\"UTF-8\" standalone=\"no\"?>\n" +
585 "<output xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">\n" +
587 " <leaf32>abc</leaf32>\n" +
590 " <leaf33>abc</leaf33>\n" +
593 " <leaf33>abc</leaf33>\n" +
595 " <leaf34>abc</leaf34>\n" +
596 " <ll11>abc</ll11>\n" +
597 " <ll11>abc</ll11>\n" +
599 " <leaf35>abc</leaf35>\n" +
603 " <leaf26>abc</leaf26>\n" +
606 " <leaf27>abc</leaf27>\n" +
609 " <leaf27>abc</leaf27>\n" +
611 " <ll9>abc</ll9>\n" +
612 " <ll9>abc</ll9>\n" +
613 " <leaf28>abc</leaf28>\n" +
618 * Adds the specified number of space required for a req in each line.
620 * @param req request message
621 * @param i number of space
622 * @return space appended string
624 public static String addSpace(String req, int i) {
625 StringBuilder space = new StringBuilder();
626 for (int sp = 0; sp < i; sp++) {
627 space = space.append(" ");
629 return req.replaceAll("\n", "\n" + space.toString());