aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/themes/FaviconTest.java
blob: ccb3d519012cd79a614a8a10c506e3d92fb66c8e (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
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.vaadin.tests.themes;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;

import java.net.HttpURLConnection;
import java.net.URL;

import org.junit.Test;

import com.vaadin.tests.tb3.SingleBrowserTest;

//Extending SingleBrowserTest just to include the test into our test suites.
public class FaviconTest extends SingleBrowserTest {

    @Test
    public void chameleonHasFavicon() {
        assertThatThemeHasFavicon("chameleon");
    }

    @Test
    public void runoHasFavicon() {
        assertThatThemeHasFavicon("runo");
    }

    @Test
    public void reindeerHasFavicon() {
        assertThatThemeHasFavicon("reindeer");
    }

    @Test
    public void valoHasFavicon() {
        assertThatThemeHasFavicon("valo");
    }

    private void assertThatThemeHasFavicon(String theme) {
        assertThat(getResponseCode(theme), is(200));
    }

    private int getResponseCode(String theme) {
        try {
            URL url = new URL(String.format("%s/VAADIN/themes/%s/favicon.ico",
                    getBaseURL(), theme));
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setRequestMethod("GET");
            connection.connect();

            return connection.getResponseCode();

        } catch (Exception e) {
            fail(e.getMessage());
        }

        return 0;
    }
}