*/
public final class DataFormatUtilsTest {
- static final String ENCODE_TO_JSON_ID = "{\n" +
- " \"identity-test:con1\": {\n" +
- " \"interfaces\": {\n" +
+ static final String ENCODE_TO_JSON_ID_COMMON = "\n \"interfaces\"" +
+ ": " +
+ "{\n" +
" \"int-list\": [\n" +
" {\n" +
" \"iden\": \"optical\",\n" +
" ]\n" +
" },\n" +
" \"interface\": \"identity-types:physical\"\n" +
- " },\n" +
+ " }";
+
+ static final String ENCODE_TO_JSON_ID = "{\n" +
+ " \"identity-test:con1\": {" + ENCODE_TO_JSON_ID_COMMON +
+ ",\n" +
" \"identity-test:l\": \"abc\"\n" +
"}";
- static final String ENCODE_TO_XML_ID = "<?xml version=\"1.0\" encoding=" +
- "\"UTF-8\" standalone=\"no\"?>\n" +
- "<con1 xmlns=\"identity:ns:test:json:ser\">\n" +
- " <interfaces>\n" +
+ static final String ENCODE_TO_ANYXML = "{\n" +
+ " \"actionIdentifiers\": {\n" +
+ " \"mode\": \"sync\",\n" +
+ " \"blueprintName\": \"baseconfiguration\",\n" +
+ " \"blueprintVersion\": \"1.0.0\",\n" +
+ " \"actionName\": \"assign-activate\"\n" +
+ " },\n" +
+ " \"payload\": {\n" +
+ " \"template-prefix\": \"vDNS-test\",\n" +
+ " \"resource-assignment-request\": {\n" +
+ " \"resource-assignment-properties\": {\n" +
+ " \"service-instance-id\": \"1234\",\n" +
+ " \"vnf-id\": \"3526\",\n" +
+ " \"customer-name\": \"htipl\",\n" +
+ " \"subscriber-name\": \"huawei\"\n" +
+ " }\n" +
+ " }\n" +
+ " },\n" +
+ " \"commonHeader\": {\n" +
+ " \"subRequestId\": \"sub-123456-1000\",\n" +
+ " \"requestId\": \"123456-1000\",\n" +
+ " \"originatorId\": \"SDNC_DG\"\n" +
+ " }\n" +
+ "}";
+
+ static final String ENCODE_TO_JSON_ID_PUT = "{\n" +
+ " \"identity-test:test\": {\n" +
+ " \"con1\": {" + addSpace(ENCODE_TO_JSON_ID_COMMON, 4) +
+ ",\n" +
+ " \"l\": \"abc\"\n" +
+ " }\n" +
+ "}";
+
+ static final String ENCODE_TO_XML_ID_COMMON = "\n <interfaces>\n" +
" <int-list>\n" +
" <iden>optical</iden>\n" +
" <available>\n" +
" </int-list>\n" +
" </interfaces>\n" +
" <interface xmlns:yangid=\"identity:list:ns:test:json:ser\">" +
- "yangid:physical</interface>\n" +
- "</con1>\n";
+ "yangid:physical</interface>";
+
+ static final String ENCODE_TO_XML_ID = "<?xml version=\"1.0\" encoding=" +
+ "\"UTF-8\" standalone=\"no\"?>\n" +
+ "<con1 xmlns=\"identity:ns:test:json:ser\">" +
+ ENCODE_TO_XML_ID_COMMON + "\n</con1>\n";
+
+ static final String ENCODE_TO_XML_ID_PUT = "<?xml version=\"1.0\" enco" +
+ "ding=\"UTF-8\" standalone=\"no\"?>\n" +
+ "<test xmlns=\"identity:ns:test:json:ser\">\n" +
+ " <con1>" + addSpace(ENCODE_TO_XML_ID_COMMON, 4)
+ + "\n </con1>\n" +
+ "</test>\n";
+
+ static final String ENCODE_TO_JSON_YANG_COMMON = "\n " +
+ "\"test-augment:ll6\": [\n" +
+ " \"unbounded\",\n" +
+ " \"8\"\n" +
+ " ],\n" +
+ " \"test-augment:cont13\": {\n" +
+ " \"ll9\": [\n" +
+ " \"abc\",\n" +
+ " \"abc\"\n" +
+ " ],\n" +
+ " \"list9\": [\n" +
+ " {\n" +
+ " \"leaf27\": \"abc\"\n" +
+ " },\n" +
+ " {\n" +
+ " \"leaf27\": \"abc\"\n" +
+ " }\n" +
+ " ],\n" +
+ " \"leaf28\": \"abc\",\n" +
+ " \"cont12\": {\n" +
+ " \"leaf26\": \"abc\"\n" +
+ " }\n" +
+ " },\n" +
+ " \"test-augment:list7\": [\n" +
+ " {\n" +
+ " \"leaf14\": \"test\"\n" +
+ " },\n" +
+ " {\n" +
+ " \"leaf14\": \"create\"\n" +
+ " }\n" +
+ " ],\n" +
+ " \"test-augment:leaf15\": \"abc\",\n" +
+ " \"test-augment:cont5\": {\n" +
+ " \"leaf13\": \"true\"\n" +
+ " }";
+
+ static final String ENCODE_TO_JSON_YANG_AUG_POST = "{\n" +
+ " \"test-yang:leaf10\": \"abc\"," +
+ ENCODE_TO_JSON_YANG_COMMON + "\n}";
static final String ENCODE_TO_JSON_YANG = "{\n" +
" \"test-yang:cont2\": {\n" +
" \"abc\"\n" +
" ],\n" +
" \"cont4\": {\n" +
- " \"leaf10\": \"abc\",\n" +
- " \"test-augment:cont13\": {\n" +
- " \"ll9\": [\n" +
- " \"abc\",\n" +
- " \"abc\"\n" +
- " ],\n" +
- " \"list9\": [\n" +
- " {\n" +
- " \"leaf27\": \"abc\"\n" +
- " },\n" +
- " {\n" +
- " \"leaf27\": \"abc\"\n" +
- " }\n" +
- " ],\n" +
- " \"leaf28\": \"abc\",\n" +
- " \"cont12\": {\n" +
- " \"leaf26\": \"abc\"\n" +
- " }\n" +
- " },\n" +
- " \"test-augment:list7\": [\n" +
- " {\n" +
- " \"leaf14\": \"test\"\n" +
- " },\n" +
- " {\n" +
- " \"leaf14\": \"create\"\n" +
- " }\n" +
- " ],\n" +
- " \"test-augment:leaf15\": \"abc\",\n" +
- " \"test-augment:ll6\": [\n" +
- " \"unbounded\",\n" +
- " \"8\"\n" +
- " ],\n" +
- " \"test-augment:cont5\": {\n" +
- " \"leaf13\": \"true\"\n" +
- " }\n" +
+ " \"leaf10\": \"abc\"," +
+ addSpace(ENCODE_TO_JSON_YANG_COMMON, 8) + "\n" +
" },\n" +
" \"ll4\": [\n" +
" \"abc\",\n" +
" }\n" +
"}";
+ static final String ENCODE_TO_JSON_YANG_PUT = "{\n" +
+ " \"test-yang:cont4\": {" + addSpace(
+ ENCODE_TO_JSON_YANG_COMMON, 4) + ",\n" +
+ " \"leaf10\": \"abc\"\n" +
+ " }\n" +
+ "}";
+
+ static final String ENCODE_TO_XML_YANG_COMMON = "\n" +
+ "<ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:aug" +
+ "ment\">unbounded</ll6>\n" +
+ "<ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:aug" +
+ "ment\">8</ll6>\n" +
+ "<cont13 xmlns=\"urn:opendaylight:params:xml:ns:yang:" +
+ "augment\">\n" +
+ " <ll9>abc</ll9>\n" +
+ " <ll9>abc</ll9>\n" +
+ " <list9>\n" +
+ " <leaf27>abc</leaf27>\n" +
+ " </list9>\n" +
+ " <list9>\n" +
+ " <leaf27>abc</leaf27>\n" +
+ " </list9>\n" +
+ " <leaf28>abc</leaf28>\n" +
+ " <cont12>\n" +
+ " <leaf26>abc</leaf26>\n" +
+ " </cont12>\n" +
+ "</cont13>\n" +
+ "<list7 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" +
+ "ugment\">\n" +
+ " <leaf14>test</leaf14>\n" +
+ "</list7>\n" +
+ "<list7 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" +
+ "ugment\">\n" +
+ " <leaf14>create</leaf14>\n" +
+ "</list7>\n" +
+ "<leaf15 xmlns=\"urn:opendaylight:params:xml:ns:yang:" +
+ "augment\">abc</leaf15>\n" +
+ "<cont5 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" +
+ "ugment\">\n" +
+ " <leaf13>true</leaf13>\n" +
+ "</cont5>";
+
+ static final String ENCODE_TO_XML_YANG_AUG_POST = "<?xml version=\"1.0\"" +
+ " encoding=\"UTF-8\" standalone=\"no\"?>\n" +
+ "<leaf10 xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">abc" +
+ "</leaf10>" +
+ ENCODE_TO_XML_YANG_COMMON + "\n";
+
+ static final String ENCODE_TO_XML_YANG_PUT = "<?xml version=\"1.0\" enc" +
+ "oding=\"UTF-8\" standalone=\"no\"?>\n" +
+ "<cont4 xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">\n" +
+ " <leaf10>abc</leaf10>" +
+ addSpace(ENCODE_TO_XML_YANG_COMMON, 4) + "\n</cont4>\n";
+
static final String ENCODE_TO_XML_YANG = "<?xml version=\"1.0\" encoding" +
"=\"UTF-8\" standalone=\"no\"?>\n" +
"<cont2 xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">\n" +
" <ll5>abc</ll5>\n" +
" <ll5>abc</ll5>\n" +
" <cont4>\n" +
- " <leaf10>abc</leaf10>\n" +
- " <cont13 xmlns=\"urn:opendaylight:params:xml:ns:yang:" +
- "augment\">\n" +
- " <ll9>abc</ll9>\n" +
- " <ll9>abc</ll9>\n" +
- " <list9>\n" +
- " <leaf27>abc</leaf27>\n" +
- " </list9>\n" +
- " <list9>\n" +
- " <leaf27>abc</leaf27>\n" +
- " </list9>\n" +
- " <leaf28>abc</leaf28>\n" +
- " <cont12>\n" +
- " <leaf26>abc</leaf26>\n" +
- " </cont12>\n" +
- " </cont13>\n" +
- " <list7 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" +
- "ugment\">\n" +
- " <leaf14>test</leaf14>\n" +
- " </list7>\n" +
- " <list7 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" +
- "ugment\">\n" +
- " <leaf14>create</leaf14>\n" +
- " </list7>\n" +
- " <leaf15 xmlns=\"urn:opendaylight:params:xml:ns:yang:" +
- "augment\">abc</leaf15>\n" +
- " <ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:aug" +
- "ment\">unbounded</ll6>\n" +
- " <ll6 xmlns=\"urn:opendaylight:params:xml:ns:yang:aug" +
- "ment\">8</ll6>\n" +
- " <cont5 xmlns=\"urn:opendaylight:params:xml:ns:yang:a" +
- "ugment\">\n" +
- " <leaf13>true</leaf13>\n" +
- " </cont5>\n" +
+ " <leaf10>abc</leaf10>"+
+ addSpace(ENCODE_TO_XML_YANG_COMMON, 8) + "\n" +
" </cont4>\n" +
" <ll4>abc</ll4>\n" +
" <ll4>abc</ll4>\n" +
" </list6>\n" +
"</cont2>\n";
-
static final String ENCODE_TO_JSON_RPC = "{\n" +
" \"test-yang:input\": {\n" +
" \"leaf30\": \"abc\",\n" +
" }\n" +
"}";
+ static final String DECODE_ANYXML_RESPONSE = "{\n" +
+ " \"commonHeader\": {\n" +
+ " \"timestamp\": \"2019-05-18T23:42:41.658Z\",\n" +
+ " \"originatorId\": \"System\",\n" +
+ " \"requestId\": \"1234\",\n" +
+ " \"subRequestId\": \"1234-12234\",\n" +
+ " \"flags\": null\n" +
+ " },\n" +
+ " \"actionIdentifiers\": {\n" +
+ " \"blueprintName\": \"golden\",\n" +
+ " \"blueprintVersion\": \"1.0.0\",\n" +
+ " \"actionName\": \"resource-assignment\",\n" +
+ " \"mode\": \"sync\"\n" +
+ " },\n" +
+ " \"status\": {\n" +
+ " \"code\": 200,\n" +
+ " \"eventType\": \"EVENT_COMPONENT_EXECUTED\",\n" +
+ " \"timestamp\": \"2019-05-18T23:42:41.950Z\",\n" +
+ " \"errorMessage\": null,\n" +
+ " \"message\": \"success\"\n" +
+ " },\n" +
+ " \"payload\": {\n" +
+ " \"resource-assignment-response\": {\n" +
+ " \"meshed-template\": {\n" +
+ " \"vf-module-1\": \"<interface>\\n " +
+ " <description>This is the Virtual Firewall entity</" +
+ "description>\\n <vfw>10.0.101.20/24</vfw>\\n</interface>\"\n" +
+ " }\n" +
+ " }\n" +
+ " },\n" +
+ " \"stepData\": {\n" +
+ " \"name\": \"resource-assignment\",\n" +
+ " \"properties\": {\n" +
+ " \"resource-assignment-params\": null,\n" +
+ " \"status\": null\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+
static final String ENCODE_TO_XML_RPC = "<?xml version=\"1.0\" encoding" +
"=\"UTF-8\" standalone=\"no\"?>\n" +
"<input xmlns=\"urn:opendaylight:params:xml:ns:yang:test\">\n" +
" <leaf28>abc</leaf28>\n" +
" </cont13>\n" +
"</output>";
+
+ /**
+ * Adds the specified number of space required for a req in each line.
+ *
+ * @param req request message
+ * @param i number of space
+ * @return space appended string
+ */
+ public static String addSpace(String req, int i) {
+ StringBuilder space = new StringBuilder();
+ for (int sp = 0; sp < i; sp++) {
+ space = space.append(" ");
+ }
+ return req.replaceAll("\n", "\n" + space.toString());
+ }
}