summaryrefslogtreecommitdiffstats
path: root/restapi-call-node/provider
diff options
context:
space:
mode:
authorGaurav Agrawal <gaurav.agrawal@huawei.com>2019-04-16 12:00:40 +0530
committerGaurav Agrawal <gaurav.agrawal@huawei.com>2019-04-17 13:52:11 +0530
commitf98a2022690815ac159161f942950aac3b7ed9a6 (patch)
treed0775b90ff5e1939c9020d16457937c3d79a9b00 /restapi-call-node/provider
parenta5fa2ea36c115aba01eb3328fd95a12dd654ed00 (diff)
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 <gaurav.agrawal@huawei.com>
Diffstat (limited to 'restapi-call-node/provider')
-rwxr-xr-xrestapi-call-node/provider/pom.xml1
-rw-r--r--restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MockCookieAuthServer.java40
-rw-r--r--restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java25
3 files changed, 65 insertions, 1 deletions
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 @@
<scope>test</scope>
</dependency>
</dependencies>
+
</project>
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<String, String> 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<String, String> 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();
}
}