diff options
author | Vidyashree Rama <vidyashree.rama@huawei.com> | 2019-04-12 14:21:37 +0530 |
---|---|---|
committer | Timoney, Dan (dt5972) <dtimoney@att.com> | 2019-04-16 10:17:08 -0400 |
commit | a5fa2ea36c115aba01eb3328fd95a12dd654ed00 (patch) | |
tree | c9bf65fa2efbc9b532a17000dd909858a62afb9c /restapi-call-node | |
parent | e4c9cfddd142785d527f29ff5c2b5883cc255033 (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>
Diffstat (limited to 'restapi-call-node')
3 files changed, 83 insertions, 0 deletions
diff --git a/restapi-call-node/provider/pom.xml b/restapi-call-node/provider/pom.xml index 2455866a4..1f698eade 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 000000000..9646272b4 --- /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 5b047e4e7..7a24ca1a9 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")); + } } |