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(
final DownloadStream ds = new DownloadStream(ss.getStream(),
getMIMEType(), getFilename());
ds.setBufferSize(getBufferSize());
- ds.setCacheTime(cacheTime);
+ ds.setCacheTime(getCacheTime());
return ds;
}
*/
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 {
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());
+ }
}
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;
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());
+ }
}