]> source.dussan.org Git - vaadin-framework.git/commitdiff
FileResource to use bufferSize, and StreamResource to use getCacheTime() (#10247)
authorAhmed Ashour <asashour@yahoo.com>
Tue, 21 Nov 2017 11:36:26 +0000 (12:36 +0100)
committercaalador <mikael.grankvist@gmail.com>
Tue, 21 Nov 2017 11:36:26 +0000 (13:36 +0200)
server/src/main/java/com/vaadin/server/FileResource.java
server/src/main/java/com/vaadin/server/StreamResource.java
server/src/test/java/com/vaadin/tests/server/FileResourceTest.java
server/src/test/java/com/vaadin/tests/server/StreamResourceTest.java

index e7a1808775de080bbc5693bf8df10a9d6cc24947..221b0f6573be9d9dad38d7bf19617a71bd72d378 100644 (file)
@@ -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(
index 9b6e02d0f610f6c29f0d6eef75971f2d92853661..b2cc3fd582336de41c20b5180bb016d950d19141 100644 (file)
@@ -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;
     }
 
index 130e87431c8bb7207daa7686626be5c34d847ede..5a21c749c821217ac4dc6fcfa483d75ef626a7bc 100644 (file)
  */
 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());
+    }
 }
index 438bf319252c0a8b8737f718289e3e99808a2848..b2d14802b0b7117c99f2eb3861d47421bc7d2d8a 100644 (file)
@@ -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());
+    }
 }