summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/server/FileResource.java3
-rw-r--r--server/src/main/java/com/vaadin/server/StreamResource.java2
-rw-r--r--server/src/test/java/com/vaadin/tests/server/FileResourceTest.java24
-rw-r--r--server/src/test/java/com/vaadin/tests/server/StreamResourceTest.java23
4 files changed, 50 insertions, 2 deletions
diff --git a/server/src/main/java/com/vaadin/server/FileResource.java b/server/src/main/java/com/vaadin/server/FileResource.java
index e7a1808775..221b0f6573 100644
--- a/server/src/main/java/com/vaadin/server/FileResource.java
+++ b/server/src/main/java/com/vaadin/server/FileResource.java
@@ -72,7 +72,8 @@ public class FileResource implements ConnectorResource {
ds.setParameter("Content-Length",
String.valueOf(sourceFile.length()));
- ds.setCacheTime(cacheTime);
+ ds.setBufferSize(getBufferSize());
+ ds.setCacheTime(getCacheTime());
return ds;
} catch (final FileNotFoundException e) {
throw new RuntimeException(
diff --git a/server/src/main/java/com/vaadin/server/StreamResource.java b/server/src/main/java/com/vaadin/server/StreamResource.java
index 9b6e02d0f6..b2cc3fd582 100644
--- a/server/src/main/java/com/vaadin/server/StreamResource.java
+++ b/server/src/main/java/com/vaadin/server/StreamResource.java
@@ -143,7 +143,7 @@ public class StreamResource implements ConnectorResource {
final DownloadStream ds = new DownloadStream(ss.getStream(),
getMIMEType(), getFilename());
ds.setBufferSize(getBufferSize());
- ds.setCacheTime(cacheTime);
+ ds.setCacheTime(getCacheTime());
return ds;
}
diff --git a/server/src/test/java/com/vaadin/tests/server/FileResourceTest.java b/server/src/test/java/com/vaadin/tests/server/FileResourceTest.java
index 130e87431c..5a21c749c8 100644
--- a/server/src/test/java/com/vaadin/tests/server/FileResourceTest.java
+++ b/server/src/test/java/com/vaadin/tests/server/FileResourceTest.java
@@ -15,10 +15,14 @@
*/
package com.vaadin.tests.server;
+import static org.junit.Assert.assertEquals;
+
import java.io.File;
+import java.net.URISyntaxException;
import org.junit.Test;
+import com.vaadin.server.DownloadStream;
import com.vaadin.server.FileResource;
public class FileResourceTest {
@@ -33,4 +37,24 @@ public class FileResourceTest {
new FileResource(new File("nonexisting")).getStream();
}
+ @Test
+ public void bufferSize() throws URISyntaxException {
+ File file = new File(getClass().getResource("../styles.scss").toURI());
+ FileResource resource = new FileResource(file) {
+ @Override
+ public long getCacheTime() {
+ return 5;
+ }
+ };
+ resource.setBufferSize(100);
+ resource.setCacheTime(200);
+
+ DownloadStream downloadStream = resource.getStream();
+ assertEquals(
+ "DownloadStream buffer size must be same as resource buffer size",
+ resource.getBufferSize(), downloadStream.getBufferSize());
+ assertEquals(
+ "DownloadStream cache time must be same as resource cache time",
+ resource.getCacheTime(), downloadStream.getCacheTime());
+ }
}
diff --git a/server/src/test/java/com/vaadin/tests/server/StreamResourceTest.java b/server/src/test/java/com/vaadin/tests/server/StreamResourceTest.java
index 438bf31925..b2d14802b0 100644
--- a/server/src/test/java/com/vaadin/tests/server/StreamResourceTest.java
+++ b/server/src/test/java/com/vaadin/tests/server/StreamResourceTest.java
@@ -18,9 +18,12 @@ package com.vaadin.tests.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import java.net.URISyntaxException;
+
import org.easymock.EasyMock;
import org.junit.Test;
+import com.vaadin.server.DownloadStream;
import com.vaadin.server.StreamResource;
import com.vaadin.server.StreamResource.StreamSource;
@@ -54,4 +57,24 @@ public class StreamResourceTest {
resource.hashCode();
}
+ @Test
+ public void cacheTime() throws URISyntaxException {
+ StreamResource resource = new StreamResource(
+ EasyMock.createMock(StreamSource.class), "") {
+ @Override
+ public long getCacheTime() {
+ return 5;
+ }
+ };
+ resource.setBufferSize(100);
+ resource.setCacheTime(200);
+
+ DownloadStream downloadStream = resource.getStream();
+ assertEquals(
+ "DownloadStream buffer size must be same as resource buffer size",
+ resource.getBufferSize(), downloadStream.getBufferSize());
+ assertEquals(
+ "DownloadStream cache time must be same as resource cache time",
+ resource.getCacheTime(), downloadStream.getCacheTime());
+ }
}