You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FaviconTest.java 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package com.vaadin.tests.themes;
  2. import com.vaadin.tests.tb3.SingleBrowserTest;
  3. import org.junit.Test;
  4. import java.net.HttpURLConnection;
  5. import java.net.URL;
  6. import static org.hamcrest.CoreMatchers.is;
  7. import static org.hamcrest.MatcherAssert.assertThat;
  8. import static org.junit.Assert.fail;
  9. //Extending SingleBrowserTest just to include the test into our test suites.
  10. public class FaviconTest extends SingleBrowserTest {
  11. @Test
  12. public void chameleonHasFavicon() {
  13. assertThatThemeHasFavicon("chameleon");
  14. }
  15. @Test
  16. public void runoHasFavicon() {
  17. assertThatThemeHasFavicon("runo");
  18. }
  19. @Test
  20. public void reindeerHasFavicon() {
  21. assertThatThemeHasFavicon("reindeer");
  22. }
  23. @Test
  24. public void valoHasFavicon() {
  25. assertThatThemeHasFavicon("valo");
  26. }
  27. private void assertThatThemeHasFavicon(String theme) {
  28. assertThat(getResponseCode(theme), is(200));
  29. }
  30. private int getResponseCode(String theme) {
  31. try {
  32. URL url = new URL(String.format("%s/VAADIN/themes/%s/favicon.ico",
  33. getBaseURL(), theme));
  34. HttpURLConnection connection = (HttpURLConnection) url
  35. .openConnection();
  36. connection.setRequestMethod("GET");
  37. connection.connect();
  38. return connection.getResponseCode();
  39. } catch (Exception e) {
  40. fail(e.getMessage());
  41. }
  42. return 0;
  43. }
  44. }