rest api call node unit tests 83/88283/3
authorSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Wed, 22 May 2019 16:34:44 +0000 (16:34 +0000)
committerKevin Smokowski <kevin.smokowski@att.com>
Wed, 22 May 2019 18:44:50 +0000 (18:44 +0000)
rest api call node unit test added for the case in which a template mixes simple and complex json objects.

Change-Id: I6921d6e328b3593464d82b7a45b1844cd88c3476
Issue-ID: CCSDK-1355
Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/MockCookieAuthServer.java [moved from restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MockCookieAuthServer.java with 96% similarity]
restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/MultipartServerMock.java [moved from restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MultipartServerMock.java with 96% similarity]
restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java [moved from restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java with 97% similarity]
restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java [moved from restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java with 97% similarity]
restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java [moved from restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java with 99% similarity]
restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java [moved from restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java with 98% similarity]
restapi-call-node/provider/src/test/resources/testEmbeddedTemplate.json [new file with mode: 0644]

@@ -17,7 +17,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
-package jtest.org.onap.ccsdk.sli.plugins.restapicall;
+package org.onap.ccsdk.sli.plugins.restapicall;
 
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
 import org.glassfish.jersey.media.multipart.FormDataParam;
  * ============LICENSE_END=========================================================
  */
 
-package jtest.org.onap.ccsdk.sli.plugins.restapicall;
+package org.onap.ccsdk.sli.plugins.restapicall;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
 import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
+import org.codehaus.jettison.json.JSONObject;
 import org.glassfish.grizzly.http.server.HttpServer;
 import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
 import org.glassfish.jersey.media.multipart.MultiPartFeature;
@@ -721,4 +722,20 @@ public class TestRestapiCallNode {
         assertThat(ctx.getAttribute("header.Set-Cookie"), is("cookieResponse=cookieValueInReturn;Version=1"));
         server.shutdownNow();
     }
+
+    @Test
+    public void testEmbeddedJsonTemplate() throws Exception {
+        SvcLogicContext ctx = new SvcLogicContext();
+       String complexObj = "{\"image_name\":\"Ubuntu 14.04\",\"service-instance-id\":\"1\",\"vnf-model-customization-uuid\":\"2f\",\"vnf-id\":\"3b\"}";
+       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/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);
+    }
+
 }
diff --git a/restapi-call-node/provider/src/test/resources/testEmbeddedTemplate.json b/restapi-call-node/provider/src/test/resources/testEmbeddedTemplate.json
new file mode 100644 (file)
index 0000000..7f23778
--- /dev/null
@@ -0,0 +1,20 @@
+{
+  "commonHeader": {
+    "origin": "earth",
+    "requestId": ${reqId},
+    "subRequestId": ${subReqId}
+  },
+  "actions": {
+    "actionName": ${actionName},
+    "mode": "sync"
+  },
+  "payload": {
+    "assignment-request": {
+      "prefix": [
+        ${myPrefix}
+      ],
+        "assignment-properties": ${'"complexObj}
+    }
+  }
+}
+