From a5fa2ea36c115aba01eb3328fd95a12dd654ed00 Mon Sep 17 00:00:00 2001 From: Vidyashree Rama Date: Fri, 12 Apr 2019 14:21:37 +0530 Subject: 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 --- restapi-call-node/provider/pom.xml | 12 ++++++ .../plugins/restapicall/MultipartServerMock.java | 44 ++++++++++++++++++++++ .../plugins/restapicall/TestRestapiCallNode.java | 27 +++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MultipartServerMock.java (limited to 'restapi-call-node') 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 @@ junit test + + org.glassfish.jersey.containers + jersey-container-servlet + ${jersey.version} + test + + + org.glassfish.jersey.containers + jersey-container-grizzly2-http + ${jersey.version} + test + 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 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")); + } } -- cgit 1.2.3-korg