From bb46fff4376095fb52443973577767026807a7ea Mon Sep 17 00:00:00 2001 From: Artur Date: Mon, 24 Apr 2017 12:04:15 +0300 Subject: Add support for frontend:// using separate es5 and es6 folders --- .../com/vaadin/server/BootstrapHandlerTest.java | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 server/src/test/java/com/vaadin/server/BootstrapHandlerTest.java (limited to 'server/src/test') 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)); + } +} -- cgit v1.2.3