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.

BootstrapHandlerTest.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.vaadin.server;
  2. import static org.junit.Assert.assertEquals;
  3. import java.util.Properties;
  4. import org.junit.Test;
  5. import org.mockito.Mockito;
  6. import com.vaadin.server.BootstrapHandler.BootstrapContext;
  7. import com.vaadin.server.BootstrapHandler.BootstrapUriResolver;
  8. public class BootstrapHandlerTest {
  9. private static final String VAADIN_URL = "http://host/VAADIN/";
  10. public static class ES5Browser extends WebBrowser {
  11. @Override
  12. public boolean isEs6Supported() {
  13. return false;
  14. }
  15. }
  16. public static class ES6Browser extends WebBrowser {
  17. @Override
  18. public boolean isEs6Supported() {
  19. return true;
  20. }
  21. }
  22. @Test
  23. public void resolveFrontendES5() {
  24. testResolveFrontEnd("frontend://foobar.html",
  25. "http://host/VAADIN/frontend/es5/foobar.html",
  26. new ES5Browser());
  27. }
  28. @Test
  29. public void resolveFrontendES6() {
  30. testResolveFrontEnd("frontend://foobar.html",
  31. "http://host/VAADIN/frontend/es6/foobar.html",
  32. new ES6Browser());
  33. }
  34. @Test
  35. public void resolveFrontendES5CustomUrl() {
  36. Properties properties = new Properties();
  37. properties.setProperty("frontend.url.es5",
  38. "https://cdn.somewhere.com/5");
  39. testResolveFrontEnd("frontend://foobar.html",
  40. "https://cdn.somewhere.com/5/foobar.html", new ES5Browser(),
  41. properties);
  42. }
  43. @Test
  44. public void resolveFrontendES6CustomUrl() {
  45. Properties properties = new Properties();
  46. properties.setProperty("frontend.url.es6",
  47. "https://cdn.somewhere.com/6");
  48. testResolveFrontEnd("frontend://foobar.html",
  49. "https://cdn.somewhere.com/6/foobar.html", new ES6Browser(),
  50. properties);
  51. }
  52. private static void testResolveFrontEnd(String frontendUrl,
  53. String expectedUrl, WebBrowser browser) {
  54. testResolveFrontEnd(frontendUrl, expectedUrl, browser,
  55. new Properties());
  56. }
  57. @SuppressWarnings("deprecation")
  58. private static void testResolveFrontEnd(String frontendUrl,
  59. String expectedUrl, WebBrowser browser,
  60. Properties customProperties) {
  61. BootstrapContext context = Mockito.mock(BootstrapContext.class);
  62. BootstrapUriResolver resolver = new BootstrapUriResolver(context) {
  63. @Override
  64. protected String getVaadinDirUrl() {
  65. return VAADIN_URL;
  66. }
  67. };
  68. VaadinSession session = Mockito.mock(VaadinSession.class);
  69. Mockito.when(context.getSession()).thenReturn(session);
  70. DeploymentConfiguration configuration = new DefaultDeploymentConfiguration(
  71. BootstrapHandlerTest.class, customProperties);
  72. Mockito.when(session.getBrowser()).thenReturn(browser);
  73. Mockito.when(session.getConfiguration()).thenReturn(configuration);
  74. assertEquals(expectedUrl, resolver.resolveVaadinUri(frontendUrl));
  75. }
  76. }