Restapicallnode with cookie based auth
[ccsdk/sli/plugins.git] / restapi-call-node / provider / src / test / java / jtest / org / onap / ccsdk / sli / plugins / restapicall / TestRestapiCallNode.java
index 5b047e4..52da461 100644 (file)
 
 package jtest.org.onap.ccsdk.sli.plugins.restapicall;
 
+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;
 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 +662,46 @@ 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);
+        HttpServer server = 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"));
+        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();
+    }
 }