Add test case for multi part form data 69/85169/4
authorVidyashree Rama <vidyashree.rama@huawei.com>
Fri, 12 Apr 2019 08:51:37 +0000 (14:21 +0530)
committerTimoney, Dan (dt5972) <dtimoney@att.com>
Tue, 16 Apr 2019 14:17:08 +0000 (10:17 -0400)
Add test case for multipart form data in restapicallnode

Issue-ID: CCSDK-239

Change-Id: Icad15bce57455ed2c1cbf4779cf8b0820fa24dc9
Signed-off-by: Vidyashree Rama <vidyashree.rama@huawei.com>
restapi-call-node/provider/pom.xml
restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MultipartServerMock.java [new file with mode: 0644]
restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java

index 2455866..1f698ea 100755 (executable)
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.containers</groupId>
+            <artifactId>jersey-container-servlet</artifactId>
+            <version>${jersey.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.containers</groupId>
+            <artifactId>jersey-container-grizzly2-http</artifactId>
+            <version>${jersey.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MultipartServerMock.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MultipartServerMock.java
new file mode 100644 (file)
index 0000000..9646272
--- /dev/null
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package jtest.org.onap.ccsdk.sli.plugins.restapicall;
+
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.glassfish.jersey.media.multipart.FormDataParam;
+
+import javax.ws.rs.Consumes;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.InputStream;
+
+@Path("file-upload")
+public class MultipartServerMock {
+
+    @POST
+    @Path("upload")
+    @Consumes(MediaType.MULTIPART_FORM_DATA)
+    public Response uploadFile(
+            @FormDataParam("file") InputStream inputStream,
+            @FormDataParam("file") FormDataContentDisposition fileDetail) {
+        return Response.status(200).entity(fileDetail.getFileName()).build();
+    }
+}
index 5b047e4..7a24ca1 100644 (file)
 
 package jtest.org.onap.ccsdk.sli.plugins.restapicall;
 
+import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
 import org.junit.Test;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
 
 public class TestRestapiCallNode {
 
@@ -654,4 +661,24 @@ public class TestRestapiCallNode {
         RestapiCallNode rcn = new RestapiCallNode();
         rcn.sendRequest(p, ctx);
     }
+
+    @Test
+    public void testMultipartFormData() throws SvcLogicException {
+        final ResourceConfig resourceConfig = new ResourceConfig(
+                MultipartServerMock.class, MultiPartFeature.class);
+        GrizzlyHttpServerFactory.createHttpServer(
+                URI.create("http://localhost:8080/"),resourceConfig);
+
+        Map<String, String> p = new HashMap<>();
+        p.put("multipartFormData", "true");
+        p.put("format", "none");
+        p.put("multipartFile", "src/test/resources/test-template.json");
+        p.put("restapiUrl", "http://localhost:8080/file-upload/upload");
+
+        SvcLogicContext ctx = new SvcLogicContext();
+        RestapiCallNode rcn = new RestapiCallNode();
+        rcn.sendRequest(p, ctx);
+        assertThat(ctx.getAttribute("response-code"), is("200"));
+        assertThat(ctx.getAttribute("httpResponse"), is( "test-template.json"));
+    }
 }