aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVidyashree Rama <vidyashree.rama@huawei.com>2019-04-12 14:21:37 +0530
committerTimoney, Dan (dt5972) <dtimoney@att.com>2019-04-16 10:17:08 -0400
commita5fa2ea36c115aba01eb3328fd95a12dd654ed00 (patch)
treec9bf65fa2efbc9b532a17000dd909858a62afb9c
parente4c9cfddd142785d527f29ff5c2b5883cc255033 (diff)
Add test case for multi part form data
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>
-rwxr-xr-xrestapi-call-node/provider/pom.xml12
-rw-r--r--restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MultipartServerMock.java44
-rw-r--r--restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java27
3 files changed, 83 insertions, 0 deletions
diff --git a/restapi-call-node/provider/pom.xml b/restapi-call-node/provider/pom.xml
index 2455866a..1f698ead 100755
--- a/restapi-call-node/provider/pom.xml
+++ b/restapi-call-node/provider/pom.xml
@@ -80,5 +80,17 @@
<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
index 00000000..9646272b
--- /dev/null
+++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MultipartServerMock.java
@@ -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();
+ }
+}
diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java
index 5b047e4e..7a24ca1a 100644
--- a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java
+++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java
@@ -21,15 +21,22 @@
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"));
+ }
}