From ab87c55476acf4e64015086e9cb200d0af181c17 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Mon, 17 Feb 2020 10:41:38 -0500 Subject: Escaping multi-line string Supporting multiline json string if embedding within Rest payload template Change-Id: I6a96f58732734fca0127d57fa5de3ba3cb7276c4 Issue-ID: CCSDK-2103 Signed-off-by: Singal, Kapil (ks220y) --- .../plugins/restapicall/TestRestapiCallNode.java | 22 +++++++++++++++++++++- .../resources/testMultiLineEmbeddedTemplate.json | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 restapi-call-node/provider/src/test/resources/testMultiLineEmbeddedTemplate.json (limited to 'restapi-call-node/provider/src/test') diff --git a/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java b/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java index 8cabaadc..da7b80ee 100755 --- a/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java +++ b/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java @@ -528,7 +528,27 @@ public class TestRestapiCallNode { RestapiCallNode rcn = new RestapiCallNode(); String request = rcn.buildXmlJsonRequest(ctx, rcn.readFile("src/test/resources/testEmbeddedTemplate.json"), Format.JSON); //This will throw a JSONException and fail the test case if rest api call node doesn't form valid JSON - JSONObject requestObj = new JSONObject(request); + assertNotNull(new JSONObject(request)); + } + + @Test + public void testMultiLineEmbeddedJsonTemplate() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + String complexObj = "{\n" + + " \"image_name\": \"Ubuntu 14.04\",\n" + + " \"service-instance-id\": \"1\",\n" + + " \"vnf-model-customization-uuid\": \"2f\",\n" + + " \"vnf-id\": \"3b\"\n" + + "}"; + ctx.setAttribute("reqId", "1235"); + ctx.setAttribute("subReqId", "054243"); + ctx.setAttribute("actionName", "CREATE"); + ctx.setAttribute("myPrefix", "2016-09-09 16:30:35.0"); + ctx.setAttribute("complexObj", complexObj); + RestapiCallNode rcn = new RestapiCallNode(); + String request = rcn.buildXmlJsonRequest(ctx, rcn.readFile("src/test/resources/testMultiLineEmbeddedTemplate.json"), Format.JSON); + //This will throw a JSONException and fail the test case if rest api call node doesn't form valid JSON + assertNotNull(new JSONObject(request)); } } diff --git a/restapi-call-node/provider/src/test/resources/testMultiLineEmbeddedTemplate.json b/restapi-call-node/provider/src/test/resources/testMultiLineEmbeddedTemplate.json new file mode 100644 index 00000000..84ae3a49 --- /dev/null +++ b/restapi-call-node/provider/src/test/resources/testMultiLineEmbeddedTemplate.json @@ -0,0 +1,20 @@ +{ + "commonHeader": { + "origin": "earth", + "requestId": ${reqId}, + "subRequestId": ${subReqId} + }, + "actions": { + "actionName": ${actionName}, + "mode": "sync" + }, + "payload": { + "assignment-request": { + "prefix": [ + ${myPrefix} + ], + "assignment-properties": ${complexObj} + } + } +} + -- cgit 1.2.3-korg