diff options
author | Artur <artur@vaadin.com> | 2017-04-24 12:04:15 +0300 |
---|---|---|
committer | Ilia Motornyi <elmot@vaadin.com> | 2017-04-24 11:04:15 +0200 |
commit | bb46fff4376095fb52443973577767026807a7ea (patch) | |
tree | 815dcd357f856174e52c21d554e1b1f9b98fad22 /server/src/test | |
parent | 70a3a105b22a01ee1114b40e50c18cdd5b194e50 (diff) | |
download | vaadin-framework-bb46fff4376095fb52443973577767026807a7ea.tar.gz vaadin-framework-bb46fff4376095fb52443973577767026807a7ea.zip |
Add support for frontend:// using separate es5 and es6 folders
Diffstat (limited to 'server/src/test')
-rw-r--r-- | server/src/test/java/com/vaadin/server/BootstrapHandlerTest.java | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/server/src/test/java/com/vaadin/server/BootstrapHandlerTest.java b/server/src/test/java/com/vaadin/server/BootstrapHandlerTest.java new file mode 100644 index 0000000000..3530d105a3 --- /dev/null +++ b/server/src/test/java/com/vaadin/server/BootstrapHandlerTest.java @@ -0,0 +1,111 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.server; + +import java.util.Properties; + +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import com.vaadin.server.BootstrapHandler.BootstrapContext; +import com.vaadin.server.BootstrapHandler.BootstrapUriResolver; + +public class BootstrapHandlerTest { + + private static final String VAADIN_URL = "http://host/VAADIN/"; + + public static class ES5Browser extends WebBrowser { + @Override + public boolean isEs6Supported() { + return false; + } + } + + public static class ES6Browser extends WebBrowser { + @Override + public boolean isEs6Supported() { + return true; + } + } + + @Test + public void resolveFrontendES5() { + testResolveFrontEnd("frontend://foobar.html", + "http://host/VAADIN/frontend/es5/foobar.html", + new ES5Browser()); + + } + + @Test + public void resolveFrontendES6() { + testResolveFrontEnd("frontend://foobar.html", + "http://host/VAADIN/frontend/es6/foobar.html", + new ES6Browser()); + + } + + @Test + public void resolveFrontendES5CustomUrl() { + Properties properties = new Properties(); + properties.setProperty("frontend.url.es5", + "https://cdn.somewhere.com/5"); + testResolveFrontEnd("frontend://foobar.html", + "https://cdn.somewhere.com/5/foobar.html", new ES5Browser(), + properties); + + } + + @Test + public void resolveFrontendES6CustomUrl() { + Properties properties = new Properties(); + properties.setProperty("frontend.url.es6", + "https://cdn.somewhere.com/6"); + testResolveFrontEnd("frontend://foobar.html", + "https://cdn.somewhere.com/6/foobar.html", new ES6Browser(), + properties); + + } + + private static void testResolveFrontEnd(String frontendUrl, + String expectedUrl, WebBrowser browser) { + testResolveFrontEnd(frontendUrl, expectedUrl, browser, + new Properties()); + } + + @SuppressWarnings("deprecation") + private static void testResolveFrontEnd(String frontendUrl, + String expectedUrl, WebBrowser browser, + Properties customProperties) { + + BootstrapContext context = Mockito.mock(BootstrapContext.class); + BootstrapUriResolver resolver = new BootstrapUriResolver(context) { + @Override + protected String getVaadinDirUrl() { + return VAADIN_URL; + } + }; + VaadinSession session = Mockito.mock(VaadinSession.class); + Mockito.when(context.getSession()).thenReturn(session); + DeploymentConfiguration configuration = new DefaultDeploymentConfiguration( + BootstrapHandlerTest.class, customProperties); + Mockito.when(session.getBrowser()).thenReturn(browser); + Mockito.when(session.getConfiguration()).thenReturn(configuration); + + Assert.assertEquals(expectedUrl, + resolver.resolveVaadinUri(frontendUrl)); + } +} |