summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-10-08 08:11:51 +0300
committerVaadin Code Review <review@vaadin.com>2012-10-08 10:35:02 +0000
commit13d5b3e98954c2ade382305f8d044b2b49fdbd0b (patch)
tree37559368471cbed3a9ea159261869bcf5c82e52a /uitest/src/com/vaadin
parent6337f8f8ccb88014f7a3d269332661ec8183b758 (diff)
downloadvaadin-framework-13d5b3e98954c2ade382305f8d044b2b49fdbd0b.tar.gz
vaadin-framework-13d5b3e98954c2ade382305f8d044b2b49fdbd0b.zip
Bootstrap UI using relative URLs with servlets (#6771)
* Configure widgetset using URLs relative to the requested page * Provide a Util method for getting an absolute URL from a relative URL * Test by using an embedded Jetty acting as a transparent proxy * Make /embed1 use the Buttons test to enable testing UIDL requests Change-Id: I4ef9b40e3954ae16b682d743a339f4360db40d4d
Diffstat (limited to 'uitest/src/com/vaadin')
-rw-r--r--uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java51
-rw-r--r--uitest/src/com/vaadin/tests/integration/ProxyTest.html111
-rw-r--r--uitest/src/com/vaadin/tests/integration/ProxyTest.java155
3 files changed, 268 insertions, 49 deletions
diff --git a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java
index 12d1cb2c38..0c2a1f965a 100644
--- a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java
+++ b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java
@@ -30,7 +30,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.vaadin.LegacyApplication;
-import com.vaadin.server.DeploymentConfiguration;
import com.vaadin.server.LegacyVaadinServlet;
import com.vaadin.server.ServiceException;
import com.vaadin.server.SessionInitEvent;
@@ -40,7 +39,6 @@ import com.vaadin.server.UIProvider;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServiceSession;
import com.vaadin.server.VaadinServletRequest;
-import com.vaadin.server.VaadinServletService;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.UI;
@@ -174,8 +172,9 @@ public class ApplicationRunnerServlet extends LegacyVaadinServlet {
return getApplicationRunnerURIs(request).applicationClassname;
}
+ // TODO Don't need to use a data object now that there's only one field
private static class URIS {
- String staticFilesPath;
+ // String staticFilesPath;
// String applicationURI;
// String context;
// String runner;
@@ -201,21 +200,18 @@ public class ApplicationRunnerServlet extends LegacyVaadinServlet {
private static URIS getApplicationRunnerURIs(HttpServletRequest request) {
final String[] urlParts = request.getRequestURI().toString()
.split("\\/");
- String context = null;
// String runner = null;
URIS uris = new URIS();
String applicationClassname = null;
String contextPath = request.getContextPath();
if (urlParts[1].equals(contextPath.replaceAll("\\/", ""))) {
// class name comes after web context and runner application
- context = urlParts[1];
// runner = urlParts[2];
if (urlParts.length == 3) {
throw new IllegalArgumentException("No application specified");
}
applicationClassname = urlParts[3];
- uris.staticFilesPath = "/" + context;
// uris.applicationURI = "/" + context + "/" + runner + "/"
// + applicationClassname;
// uris.context = context;
@@ -223,14 +219,12 @@ public class ApplicationRunnerServlet extends LegacyVaadinServlet {
uris.applicationClassname = applicationClassname;
} else {
// no context
- context = "";
// runner = urlParts[1];
if (urlParts.length == 2) {
throw new IllegalArgumentException("No application specified");
}
applicationClassname = urlParts[2];
- uris.staticFilesPath = "/";
// uris.applicationURI = "/" + runner + "/" + applicationClassname;
// uris.context = context;
// uris.runner = runner;
@@ -274,47 +268,6 @@ public class ApplicationRunnerServlet extends LegacyVaadinServlet {
throw new ClassNotFoundException();
}
- @Override
- protected String getRequestPathInfo(HttpServletRequest request) {
- String path = request.getPathInfo();
- if (path == null) {
- return null;
- }
-
- path = path.substring(1 + getApplicationRunnerApplicationClassName(
- request).length());
- return path;
- }
-
- @Override
- protected VaadinServletService createServletService(
- DeploymentConfiguration deploymentConfiguration) {
- return new VaadinServletService(this, deploymentConfiguration) {
- @Override
- public String getStaticFileLocation(VaadinRequest request) {
- URIS uris = getApplicationRunnerURIs(VaadinServletRequest
- .cast(request));
- String staticFilesPath = uris.staticFilesPath;
- if (staticFilesPath.equals("/")) {
- staticFilesPath = "";
- }
-
- return staticFilesPath;
- }
- };
- }
-
- @Override
- protected VaadinServletRequest createVaadinRequest(
- HttpServletRequest request) {
- return new VaadinServletRequest(request, getService()) {
- @Override
- public String getRequestPathInfo() {
- return ApplicationRunnerServlet.this.getRequestPathInfo(this);
- }
- };
- }
-
private Logger getLogger() {
return Logger.getLogger(ApplicationRunnerServlet.class.getName());
}
diff --git a/uitest/src/com/vaadin/tests/integration/ProxyTest.html b/uitest/src/com/vaadin/tests/integration/ProxyTest.html
new file mode 100644
index 0000000000..f52f35ed55
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/integration/ProxyTest.html
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>AddAndRemoveTabs</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">AddAndRemoveTabs</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.integration.ProxyTest?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestsintegrationProxyTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestsintegrationProxyTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VLink[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>pause</td>
+ <td></td>
+ <td>2000</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=embed1::/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VLabel[0]</td>
+ <td>A generic test for Buttons in different configurations</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=embed1::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VCheckBox[0]/domChild[0]</td>
+ <td>5,5</td>
+</tr>
+<tr>
+ <td>assertCSSClass</td>
+ <td>vaadin=embed1::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]</td>
+ <td>v-disabled</td>
+</tr>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.integration.ProxyTest</td>
+ <td></td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestsintegrationProxyTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VLink[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>pause</td>
+ <td></td>
+ <td>2000</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=embed1::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VCheckBox[0]/domChild[0]</td>
+ <td>7,5</td>
+</tr>
+<tr>
+ <td>assertNotCSSClass</td>
+ <td>vaadin=embed1::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]</td>
+ <td>v-disabled</td>
+</tr>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.integration.ProxyTest</td>
+ <td></td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestsintegrationProxyTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VLink[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>pause</td>
+ <td></td>
+ <td>2000</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VCheckBox[0]/domChild[0]</td>
+ <td>35,7</td>
+</tr>
+<tr>
+ <td>assertCSSClass</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]</td>
+ <td>v-disabled</td>
+</tr>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.integration.ProxyTest</td>
+ <td></td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestsintegrationProxyTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/integration/ProxyTest.java b/uitest/src/com/vaadin/tests/integration/ProxyTest.java
new file mode 100644
index 0000000000..97a4efe90e
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/integration/ProxyTest.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2011 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.tests.integration;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.servlets.ProxyServlet;
+
+import com.vaadin.annotations.PreserveOnRefresh;
+import com.vaadin.server.ExternalResource;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.VaadinServletService;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Link;
+import com.vaadin.ui.VerticalLayout;
+
+@PreserveOnRefresh
+public class ProxyTest extends AbstractTestUI {
+
+ private Server server;
+
+ private final Button startButton = new Button("Start proxy",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ startProxy();
+ stopButton.setEnabled(true);
+ }
+ });
+ private final Button stopButton = new Button("Stop proxy",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ stopProxy();
+ startButton.setEnabled(true);
+ }
+ });
+ private VerticalLayout linkHolder = new VerticalLayout();
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ stopButton.setDisableOnClick(true);
+ stopButton.setEnabled(false);
+ startButton.setDisableOnClick(true);
+
+ addCleanupListener(new CleanupListener() {
+ @Override
+ public void cleanup(CleanupEvent event) {
+ if (server != null && server.isRunning()) {
+ try {
+ server.stop();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ });
+
+ addComponent(startButton);
+ addComponent(stopButton);
+ addComponent(linkHolder);
+ }
+
+ private void startProxy() {
+ HttpServletRequest request = VaadinServletService
+ .getCurrentServletRequest();
+
+ // Set up a server
+ server = new Server();
+ SelectChannelConnector connector = new SelectChannelConnector();
+ // Uses random available port by default, uncomment this to make local
+ // testing easier (you can just reload old tab after restarting proxy)
+ // connector.setPort(8889);
+ server.setConnectors(new Connector[] { connector });
+
+ // Create root context and add the ProxyServlet.Transparent to it
+ ServletContextHandler contextHandler = new ServletContextHandler();
+ server.setHandler(contextHandler);
+ contextHandler.setContextPath("/");
+ ServletHolder servletHolder = contextHandler.addServlet(
+ ProxyServlet.Transparent.class, "/*");
+
+ // Configure servlet to forward to the root of the original server
+ servletHolder.setInitParameter(
+ "ProxyTo",
+ "http://" + request.getLocalAddr() + ":"
+ + request.getLocalPort() + "/");
+ // Configure servlet to strip beginning of paths
+ servletHolder.setInitParameter("Prefix", "/proxypath/");
+
+ // Start the server
+ try {
+ server.start();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ // Add links to some proxied urls to tests
+ String linkBase = "http://" + request.getLocalName() + ":"
+ + connector.getLocalPort() + "/proxypath/";
+
+ linkHolder.removeAllComponents();
+ linkHolder.addComponent(new Link("Open embed1 in proxy",
+ new ExternalResource(linkBase + "embed1")));
+ linkHolder.addComponent(new Link("Open embed1/ in proxy",
+ new ExternalResource(linkBase + "embed1/")));
+ linkHolder.addComponent(new Link("Open Buttons in proxy",
+ new ExternalResource(linkBase
+ + "run/com.vaadin.tests.components.button.Buttons")));
+
+ }
+
+ private void stopProxy() {
+ linkHolder.removeAllComponents();
+ try {
+ server.stop();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ server.destroy();
+ server = null;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Test UI for starting an embedded Jetty on a different port that proxies requests back to the original server using a different path.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return Integer.valueOf(6771);
+ }
+
+}