diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-11-21 12:36:26 +0100 |
---|---|---|
committer | caalador <mikael.grankvist@gmail.com> | 2017-11-21 13:36:26 +0200 |
commit | afe8b8a3873a202230f2c176e6552b5d64d1b758 (patch) | |
tree | 98af669ad8e3c999bfc1ffdb45f5bfe5cdea727d /server | |
parent | 94409e2221f14d2b592cfd41b17b000aed091600 (diff) | |
download | vaadin-framework-afe8b8a3873a202230f2c176e6552b5d64d1b758.tar.gz vaadin-framework-afe8b8a3873a202230f2c176e6552b5d64d1b758.zip |
FileResource to use bufferSize, and StreamResource to use getCacheTime() (#10247)
Diffstat (limited to 'server')
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()); + } } |