You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by jo...@apache.org on 2022/02/04 16:22:58 UTC
[sling-org-apache-sling-servlets-get] branch master updated: SLING-10303 update to parent pom 41, other version updates, add testcases (#6)
This is an automated email from the ASF dual-hosted git repository.
joerghoh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-get.git
The following commit(s) were added to refs/heads/master by this push:
new 1cea3ae SLING-10303 update to parent pom 41, other version updates, add testcases (#6)
1cea3ae is described below
commit 1cea3ae36df79c75d489caa34bb933e7b7fb2b9e
Author: Jörg Hoh <jo...@users.noreply.github.com>
AuthorDate: Fri Feb 4 17:22:51 2022 +0100
SLING-10303 update to parent pom 41, other version updates, add testcases (#6)
* SLING-10303 update to parent pom 41, add testcases
---
pom.xml | 40 +++++++++++--
.../get/impl/helpers/StreamRendererTest.java | 65 +++++++++++++++++++++-
src/test/resources/samplefile.json | 1 +
3 files changed, 100 insertions(+), 6 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4ab1b8e..a00f043 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling-bundle-parent</artifactId>
- <version>39</version>
+ <version>41</version>
<relativePath />
</parent>
@@ -158,12 +158,42 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.testing.sling-mock</artifactId>
- <version>2.2.10</version>
- <scope>test</scope>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
+ <version>3.0.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-api</artifactId>
+ <version>2.18.6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-jcr-commons</artifactId>
+ <version>2.21.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.jcr.api</artifactId>
+ <version>2.4.0</version>
+ <scope>test</scope>
</dependency>
<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.8.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.sling-mock-oak</artifactId>
+ <scope>test</scope>
+ <version>2.1.10-1.16.0</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.servlet-helpers</artifactId>
<version>1.4.2</version>
diff --git a/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererTest.java b/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererTest.java
index 5a98d63..1584727 100644
--- a/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererTest.java
+++ b/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererTest.java
@@ -19,6 +19,7 @@
package org.apache.sling.servlets.get.impl.helpers;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
@@ -26,16 +27,52 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
+
+import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
-import junitx.util.PrivateAccessor;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.request.RequestDispatcherOptions;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.servlethelpers.MockRequestDispatcherFactory;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
+import junitx.util.PrivateAccessor;
+
public class StreamRendererTest {
+ @Rule
+ public SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
+
+ RequestDispatcher requestDispatcher;
+
+
+ @Before
+ public void setup() {
+ Resource r = context.create().resource("/abc.txt","prop","value");
+ context.build().file("file.txt", this.getClass().getResourceAsStream("/samplefile.json"));
+ requestDispatcher = Mockito.mock(RequestDispatcher.class);
+ context.request().setRequestDispatcherFactory(new MockRequestDispatcherFactory() {
+ @Override
+ public RequestDispatcher getRequestDispatcher(String path, RequestDispatcherOptions options) {
+ return requestDispatcher;
+ }
+
+ @Override
+ public RequestDispatcher getRequestDispatcher(Resource resource, RequestDispatcherOptions options) {
+ return requestDispatcher;
+ }
+ });
+ }
+
@Test
public void testCopyRange() throws IOException {
runTests(1234);
@@ -141,4 +178,30 @@ public class StreamRendererTest {
new Class[] { Resource.class, SlingHttpServletResponse.class }, new Object[] { resource, response });
Mockito.verify(response, Mockito.times(1)).setContentType("application/octet-stream");
}
+
+
+ @Test
+ public void test_render_file() throws IOException {
+
+ StreamRenderer renderer = new StreamRenderer(true,null,null);
+ context.request().setResource(context.resourceResolver().getResource("/file.txt"));
+ renderer.render(context.request(), context.response());
+ assertTrue(context.response().getOutputAsString().equals("not json"));
+ assertEquals(HttpServletResponse.SC_OK, context.response().getStatus());
+
+ }
+
+ @Test
+ public void test_render_file_directoryListing() throws IOException, ServletException {
+ ServletContext sc = Mockito.mock(ServletContext.class);
+ StreamRenderer renderer = new StreamRenderer(true,new String[] {"/"},sc);
+ Resource root = context.resourceResolver().getResource("/");
+ context.request().setResource(root);
+ renderer.render(context.request(), context.response());
+ assertEquals(HttpServletResponse.SC_OK, context.response().getStatus());
+ Mockito.verify(requestDispatcher).include(Mockito.any(), Mockito.any());
+
+ }
+
+
}
diff --git a/src/test/resources/samplefile.json b/src/test/resources/samplefile.json
new file mode 100644
index 0000000..a696bd2
--- /dev/null
+++ b/src/test/resources/samplefile.json
@@ -0,0 +1 @@
+not json
\ No newline at end of file