You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2019/07/02 19:10:49 UTC

[sling-org-apache-sling-app-cms] branch master updated: Adding a unit test for the latest servlet

This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git


The following commit(s) were added to refs/heads/master by this push:
     new 39f95ab  Adding a unit test for the latest servlet
39f95ab is described below

commit 39f95ab5482c07fe8c937a0ac3ea59dc7ce223cf
Author: Dan Klco <dk...@apache.org>
AuthorDate: Tue Jul 2 15:10:41 2019 -0400

    Adding a unit test for the latest servlet
---
 .../internal/servlets/DownloadFileServletTest.java | 53 ++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/core/src/test/java/org/apache/sling/cms/core/internal/servlets/DownloadFileServletTest.java b/core/src/test/java/org/apache/sling/cms/core/internal/servlets/DownloadFileServletTest.java
new file mode 100644
index 0000000..8e7ace1
--- /dev/null
+++ b/core/src/test/java/org/apache/sling/cms/core/internal/servlets/DownloadFileServletTest.java
@@ -0,0 +1,53 @@
+package org.apache.sling.cms.core.internal.servlets;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+
+import org.apache.sling.cms.core.helpers.SlingCMSContextHelper;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class DownloadFileServletTest {
+
+    @Rule
+    public final SlingContext context = new SlingContext();
+
+    @Before
+    public void init() {
+        SlingCMSContextHelper.initContext(context);
+
+    }
+
+    @Test
+    public void testValidRequest() throws ServletException, IOException {
+
+        context.requestPathInfo().setSuffix("/content/apache/sling-apache-org/index/apache.png");
+
+        DownloadFileServlet dfs = new DownloadFileServlet();
+
+        dfs.doGet(context.request(), context.response());
+        
+        assertTrue(context.response().getStatus() == 200);
+        assertTrue(context.response().getHeaderNames().contains("Content-Disposition"));
+    }
+    
+
+    @Test
+    public void testInValidRequest() throws ServletException, IOException {
+
+        context.requestPathInfo().setSuffix("/content/apache/sling-apache-org/index/notafile.png");
+
+        DownloadFileServlet dfs = new DownloadFileServlet();
+
+        dfs.doGet(context.request(), context.response());
+        
+        assertTrue(context.response().getStatus() == 404);
+        assertFalse(context.response().getHeaderNames().contains("Content-Disposition"));
+    }
+}