Restapicallnode with cookie based auth 19/85419/3
authorGaurav Agrawal <gaurav.agrawal@huawei.com>
Tue, 16 Apr 2019 06:30:40 +0000 (12:00 +0530)
committerGaurav Agrawal <gaurav.agrawal@huawei.com>
Wed, 17 Apr 2019 08:22:11 +0000 (13:52 +0530)
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>
restapi-call-node/provider/pom.xml
restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MockCookieAuthServer.java [new file with mode: 0644]
restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java

index 1f698ea..3208945 100755 (executable)
@@ -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 (file)
index 0000000..b4a30d3
--- /dev/null
@@ -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();
+    }
+}
index 7a24ca1..52da461 100644 (file)
@@ -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();
     }
 }