From f98a2022690815ac159161f942950aac3b7ed9a6 Mon Sep 17 00:00:00 2001 From: Gaurav Agrawal Date: Tue, 16 Apr 2019 12:00:40 +0530 Subject: Restapicallnode with cookie based auth Validate the cookie based auth feature of RestApiCallNode Fix multipart form data test to stop server after completion to avoid impacting other testcases Change-Id: I221b668978abf630f35cbb213687a25cc0de8b79 Issue-ID: CCSDK-239 Signed-off-by: Gaurav Agrawal --- restapi-call-node/provider/pom.xml | 1 + .../plugins/restapicall/MockCookieAuthServer.java | 40 ++++++++++++++++++++++ .../plugins/restapicall/TestRestapiCallNode.java | 25 +++++++++++++- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MockCookieAuthServer.java diff --git a/restapi-call-node/provider/pom.xml b/restapi-call-node/provider/pom.xml index 1f698eade..32089455f 100755 --- a/restapi-call-node/provider/pom.xml +++ b/restapi-call-node/provider/pom.xml @@ -93,4 +93,5 @@ test + diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MockCookieAuthServer.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MockCookieAuthServer.java new file mode 100644 index 000000000..b4a30d3ab --- /dev/null +++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MockCookieAuthServer.java @@ -0,0 +1,40 @@ +/*- + * ============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 javax.ws.rs.Consumes; +import javax.ws.rs.Produces; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.NewCookie; +import javax.ws.rs.core.Response; + +@Path("get-cookie") +public class MockCookieAuthServer { + @GET + @Path("cookie") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response getCookie() { + return Response.status(200).entity("success").cookie(new NewCookie("cookieResponse", "cookieValueInReturn")).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 7a24ca1a9..52da46157 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 @@ -25,6 +25,7 @@ import java.net.URI; import java.util.HashMap; import java.util.Map; +import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; import org.glassfish.jersey.media.multipart.MultiPartFeature; import org.junit.Test; @@ -666,7 +667,7 @@ public class TestRestapiCallNode { public void testMultipartFormData() throws SvcLogicException { final ResourceConfig resourceConfig = new ResourceConfig( MultipartServerMock.class, MultiPartFeature.class); - GrizzlyHttpServerFactory.createHttpServer( + HttpServer server = GrizzlyHttpServerFactory.createHttpServer( URI.create("http://localhost:8080/"),resourceConfig); Map p = new HashMap<>(); @@ -680,5 +681,27 @@ public class TestRestapiCallNode { rcn.sendRequest(p, ctx); assertThat(ctx.getAttribute("response-code"), is("200")); assertThat(ctx.getAttribute("httpResponse"), is( "test-template.json")); + server.shutdownNow(); + } + + @Test + public void testCookieResponse() throws SvcLogicException { + final ResourceConfig resourceConfig = new ResourceConfig( + MockCookieAuthServer.class); + HttpServer server = GrizzlyHttpServerFactory.createHttpServer( + URI.create("http://localhost:8080/"),resourceConfig); + + Map p = new HashMap<>(); + p.put("format", "none"); + p.put("httpMethod", "get"); + p.put("restapiUrl", "http://localhost:8080/get-cookie/cookie"); + p.put("dumpHeaders", "true"); + + SvcLogicContext ctx = new SvcLogicContext(); + RestapiCallNode rcn = new RestapiCallNode(); + rcn.sendRequest(p, ctx); + assertThat(ctx.getAttribute("response-code"), is("200")); + assertThat(ctx.getAttribute("header.Set-Cookie"), is("cookieResponse=cookieValueInReturn;Version=1")); + server.shutdownNow(); } } -- cgit 1.2.3-korg