aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test/java/com/vaadin/tests/server/FileResourceTest.java
blob: e91274b90ab934e559879da6a6ae35e5ee13ebaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 {

    @Test(expected = IllegalArgumentException.class)
    public void nullFile() {
        new FileResource(null);
    }

    @Test(expected = RuntimeException.class)
    public void nonExistingFile() {
        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());
    }
}