diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-10-05 10:09:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-05 10:09:22 +0300 |
commit | 3cbd834842319d151d9248706bc14e14a3abca42 (patch) | |
tree | a2e918d9632512acecf0fcadc31a2ac1a10de71c /test/servlet-containers/generic-ui | |
parent | eda970f667f5784977b63a158b24bd1c1f28ffc4 (diff) | |
download | vaadin-framework-3cbd834842319d151d9248706bc14e14a3abca42.tar.gz vaadin-framework-3cbd834842319d151d9248706bc14e14a3abca42.zip |
Add maven based server tests for Wildfly and Jetty (#10116)
This patch refactors the generic integration test war into
two jar dependencies and individual modules for different servers.
There is now a common approach for making configurations for the
remaining server tests still executed through an Ant build script.
Diffstat (limited to 'test/servlet-containers/generic-ui')
16 files changed, 746 insertions, 0 deletions
diff --git a/test/servlet-containers/generic-ui/pom.xml b/test/servlet-containers/generic-ui/pom.xml new file mode 100644 index 0000000000..d54579cec6 --- /dev/null +++ b/test/servlet-containers/generic-ui/pom.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.vaadin</groupId> + <artifactId>vaadin-servlet-containers-test</artifactId> + <version>8.2-SNAPSHOT</version> + </parent> + <artifactId>vaadin-test-server-ui</artifactId> + <name>vaadin-test-server-ui</name> + <packaging>jar</packaging> + <properties> + <jetty.skip>true</jetty.skip> + </properties> + + <dependencies> + <dependency> + <groupId>com.vaadin</groupId> + <artifactId>vaadin-client-compiled</artifactId> + </dependency> + <dependency> + <groupId>com.vaadin</groupId> + <artifactId>vaadin-push</artifactId> + </dependency> + </dependencies> +</project> diff --git a/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/IntegrationTestUIProvider.java b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/IntegrationTestUIProvider.java new file mode 100644 index 0000000000..6f265b10f7 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/IntegrationTestUIProvider.java @@ -0,0 +1,58 @@ +package com.vaadin.tests; + +import com.vaadin.server.UIClassSelectionEvent; +import com.vaadin.server.UIProvider; +import com.vaadin.tests.integration.push.BasicPush; +import com.vaadin.ui.UI; + +public class IntegrationTestUIProvider extends UIProvider { + + public static final String[] defaultPackages = { + "com.vaadin.tests.integration", + "com.vaadin.tests.integration.push" }; + + @Override + public Class<? extends UI> getUIClass(UIClassSelectionEvent event) { + Class<? extends UI> uiClass = findUIClassFromPath(event); + return uiClass != null ? uiClass : BasicPush.class; + } + + private Class<? extends UI> findUIClassFromPath( + UIClassSelectionEvent event) { + String pathInfo = event.getRequest().getPathInfo(); + if (pathInfo != null) { + String className = pathInfo.substring(1); + if (className.startsWith("run/")) { + className = className.substring(4); + } + + if (className.contains(".")) { + return getUIClass(className); + } else { + return getUIClassFromDefaultPackage(className); + } + } + return null; + } + + private Class<? extends UI> getUIClassFromDefaultPackage(String className) { + for (String pkgName : defaultPackages) { + Class<? extends UI> uiClass = getUIClass(pkgName + "." + className); + if (uiClass != null) { + return uiClass; + } + } + return null; + } + + private Class<? extends UI> getUIClass(String className) { + try { + Class<?> loadClass = getClass().getClassLoader() + .loadClass(className.replace("/", ".")); + return (Class<? extends UI>) loadClass; + } catch (ClassNotFoundException e) { + return null; + } + } + +} diff --git a/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/JSR356Servlet.java b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/JSR356Servlet.java new file mode 100644 index 0000000000..1a6c138f36 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/JSR356Servlet.java @@ -0,0 +1,18 @@ +package com.vaadin.tests; + +import com.vaadin.annotations.VaadinServletConfiguration; +import com.vaadin.server.VaadinServlet; +import com.vaadin.tests.integration.ServletIntegrationWebsocketUI; + +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; + +/** + * Created by elmot on 06-02-2017. + */ +@WebServlet(urlPatterns = "/run-jsr356/*", name = "IntegrationUIProvider-Jsr356", asyncSupported = false, initParams = { + @WebInitParam(name = "org.atmosphere.cpr.asyncSupport", value = "org.atmosphere.container.JSR356AsyncSupport")}) +@VaadinServletConfiguration(ui = ServletIntegrationWebsocketUI.class, productionMode = false) +public class JSR356Servlet extends VaadinServlet { + +} diff --git a/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/ServerIntegrationTestServlet.java b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/ServerIntegrationTestServlet.java new file mode 100644 index 0000000000..9ca79b31a8 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/ServerIntegrationTestServlet.java @@ -0,0 +1,14 @@ +package com.vaadin.tests; + +import com.vaadin.annotations.VaadinServletConfiguration; +import com.vaadin.server.VaadinServlet; +import com.vaadin.tests.integration.ServletIntegrationUI; + +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; + +@WebServlet(urlPatterns = "/*" ,name = "IntegrationTestUIProvider", asyncSupported = true, initParams = { + @WebInitParam(name = "UIProvider", value = "com.vaadin.tests.IntegrationTestUIProvider")}) +@VaadinServletConfiguration(ui = ServletIntegrationUI.class, productionMode = false) +public class ServerIntegrationTestServlet extends VaadinServlet { +} diff --git a/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/FlagSeResource.java b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/FlagSeResource.java new file mode 100644 index 0000000000..8f8fce77c2 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/FlagSeResource.java @@ -0,0 +1,13 @@ +package com.vaadin.tests.integration; + +import com.vaadin.server.ClassResource; + +public class FlagSeResource extends ClassResource { + + public FlagSeResource() { + super("/" + + FlagSeResource.class.getName().replace('.', '/').replaceAll( + FlagSeResource.class.getSimpleName() + "$", "") + + "se.gif"); + } +} diff --git a/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushUI.java b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushUI.java new file mode 100644 index 0000000000..530e093d8e --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushUI.java @@ -0,0 +1,29 @@ +/* + * 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.tests.integration; + +import com.vaadin.annotations.Push; + +/** + * Server test which uses the default push mechanisms + * + * @since 7.1.12 + * @author Vaadin Ltd + */ +@Push +public class ServletIntegrationDefaultPushUI extends ServletIntegrationUI { + +} diff --git a/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationLongPollingUI.java b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationLongPollingUI.java new file mode 100644 index 0000000000..be74683026 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationLongPollingUI.java @@ -0,0 +1,30 @@ +/* + * 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.tests.integration; + +import com.vaadin.annotations.Push; +import com.vaadin.shared.ui.ui.Transport; + +/** + * Server test which uses long polling + * + * @since 7.1 + * @author Vaadin Ltd + */ +@Push(transport = Transport.LONG_POLLING) +public class ServletIntegrationLongPollingUI extends ServletIntegrationUI { + +} diff --git a/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationStreamingUI.java b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationStreamingUI.java new file mode 100644 index 0000000000..540fd70df5 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationStreamingUI.java @@ -0,0 +1,30 @@ +/* + * 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.tests.integration; + +import com.vaadin.annotations.Push; +import com.vaadin.shared.ui.ui.Transport; + +/** + * Server test which uses streaming + * + * @since 7.1 + * @author Vaadin Ltd + */ +@Push(transport = Transport.STREAMING) +public class ServletIntegrationStreamingUI extends ServletIntegrationUI { + +} diff --git a/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationUI.java b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationUI.java new file mode 100644 index 0000000000..0d4010beaa --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationUI.java @@ -0,0 +1,72 @@ +package com.vaadin.tests.integration; + +import com.vaadin.annotations.DesignRoot; +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.ClassResource; +import com.vaadin.server.Resource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Image; +import com.vaadin.ui.Label; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.declarative.Design; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class ServletIntegrationUI extends UI { + + public static class Country { + private final String name; + private final String id; + private final Resource icon; + + public Country(String name, String id, Resource icon) { + this.name = name; + this.id = id; + this.icon = icon; + } + + public String getName() { + return name; + } + + public String getId() { + return id; + } + + public Resource getIcon() { + return icon; + } + } + + @Override + protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + + final Grid<Country> grid = new Grid<>(); + // TODO ImageRenderer does not support ClassResource + grid.addComponentColumn(country -> new Image(null, country.getIcon())) + .setWidth(50).setCaption(""); + grid.addColumn(country -> country.getName()).setWidth(100) + .setCaption("Country"); + grid.setItems(new Country("Finland", "FI", new ClassResource("fi.gif")), + new Country("Sweden", "SE", new FlagSeResource())); + grid.setHeight("200px"); + grid.setWidth("200px"); + layout.addComponent(grid); + + final Label selectedLabel = new LabelFromDesign(); + grid.addSelectionListener(event -> selectedLabel.setValue( + event.getFirstSelectedItem().map(c -> c.getId()).orElse(""))); + layout.addComponent(selectedLabel); + } + + @DesignRoot + public static class LabelFromDesign extends Label { + public LabelFromDesign() { + Design.read(this); + } + } +} diff --git a/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationWebsocketUI.java b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationWebsocketUI.java new file mode 100644 index 0000000000..cfffa04c11 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/ServletIntegrationWebsocketUI.java @@ -0,0 +1,48 @@ +/* + * 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.tests.integration; + +import com.vaadin.annotations.Push; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.ui.Transport; +import com.vaadin.shared.ui.ui.UIState.PushConfigurationState; + +/** + * Server test which uses websockets + * + * @since 7.1 + * @author Vaadin Ltd + */ +@Push(transport = Transport.WEBSOCKET) +public class ServletIntegrationWebsocketUI extends ServletIntegrationUI { + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.tests.integration.IntegrationTestUI#init(com.vaadin.server + * .VaadinRequest) + */ + @Override + protected void init(VaadinRequest request) { + super.init(request); + // Ensure no fallback is used + getPushConfiguration().setParameter( + PushConfigurationState.FALLBACK_TRANSPORT_PARAM, "none"); + + } + +} diff --git a/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/push/AbstractTestUI.java b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/push/AbstractTestUI.java new file mode 100644 index 0000000000..c9ef1b82b0 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/push/AbstractTestUI.java @@ -0,0 +1,226 @@ +package com.vaadin.tests.integration.push; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinServlet; +import com.vaadin.server.WebBrowser; +import com.vaadin.shared.communication.PushMode; +import com.vaadin.shared.ui.ContentMode; +import com.vaadin.shared.ui.ui.Transport; +import com.vaadin.shared.ui.ui.UIState.PushConfigurationState; +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; +import com.vaadin.ui.Notification.Type; +import com.vaadin.ui.PushConfiguration; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; + +import java.io.File; + +public abstract class AbstractTestUI extends UI { + + @Override + public void init(VaadinRequest request) { + getPage().setTitle(getClass().getName()); + + Label label = new Label(getTestDescription(), ContentMode.HTML); + label.setWidth("100%"); + + VerticalLayout rootLayout = new VerticalLayout(); + rootLayout.setSpacing(false); + setContent(rootLayout); + + layout = new VerticalLayout(); + layout.setSpacing(false); + layout.setMargin(false); + + rootLayout.addComponent(label); + rootLayout.addComponent(layout); + ((VerticalLayout) getContent()).setExpandRatio(layout, 1); + + warnIfWidgetsetMaybeNotCompiled(); + + setTransport(request); + + setup(request); + } + + protected void warnIfWidgetsetMaybeNotCompiled() { + // Can't check location if sendUrlAsParameters is disabled + if (!getSession().getConfiguration().isSendUrlsAsParameters()) { + return; + } + + // Ignore if using debug mode + String query = getPage().getLocation().getQuery(); + if (query != null && query.matches(".*[&?]gwt\\.codesvr.*")) { + return; + } + + // Find out the widgetset of this UI based on @Widgetset annotation + Class<?> currentType = getClass(); + String usedWidgetset = VaadinServlet.DEFAULT_WIDGETSET; + while (currentType != Object.class) { + Widgetset annotation = currentType.getAnnotation(Widgetset.class); + if (annotation != null) { + usedWidgetset = annotation.value(); + break; + } else { + currentType = currentType.getSuperclass(); + } + } + + // Assuming the same folder structure as in git repo + // Assuming project root is the working dir of this process + File widgetsetsFolder = new File("WebContent/VAADIN/widgetsets"); + if (!widgetsetsFolder.isDirectory()) { + return; + } + + // Find the most newly compiled widgetset + long newestWidgetsetTimestamp = -1; + String newestWidgetsetName = null; + File[] children = widgetsetsFolder.listFiles(); + for (File child : children) { + if (!child.isDirectory() || child.getName().equals("WEB-INF")) { + continue; + } + long lastModified = child.lastModified(); + if (lastModified > newestWidgetsetTimestamp) { + newestWidgetsetTimestamp = lastModified; + newestWidgetsetName = child.getName(); + } + } + + // Compare to currently used widgetset, with a 30 minute grace period + File currentWidgetsetFolder = new File(widgetsetsFolder, usedWidgetset); + long currentWidgetsetTimestamp = currentWidgetsetFolder.lastModified(); + int halfHour = 30 * 60 * 1000; + if (currentWidgetsetTimestamp + halfHour < newestWidgetsetTimestamp) { + Notification.show( + "The currently used widgetset (" + usedWidgetset + + ") was compiled long before the most recently compiled one (" + + newestWidgetsetName + + "). Are you sure you have compiled the right widgetset?", + Type.WARNING_MESSAGE); + } + } + + /** + * Sets the push transport according to the transport= URL parameter if such + * is given. Supports transport=xhr (disables push), transport=websocket + * (forces websocket into use), transport=streaming (forces streaming into + * use). Using ?transport=xyz disables the fallback transport. + * + * @param request + * The UI init request + */ + protected void setTransport(VaadinRequest request) { + String transport = request.getParameter("transport"); + PushConfiguration config = getPushConfiguration(); + + if ("xhr".equals(transport)) { + config.setPushMode(PushMode.DISABLED); + } else if ("websocket".equals(transport)) { + enablePush(Transport.WEBSOCKET); + } else if ("websocket-xhr".equals(transport)) { + enablePush(Transport.WEBSOCKET_XHR); + } else if ("streaming".equals(transport)) { + enablePush(Transport.STREAMING); + } else if ("long-polling".equals(transport)) { + enablePush(Transport.LONG_POLLING); + } else if (transport != null) { + throw new IllegalArgumentException("Unknown transport value '" + + transport + + "'. Supported are xhr,websocket,streaming,long-polling"); + } + } + + protected void enablePush(Transport transport) { + PushConfiguration config = getPushConfiguration(); + if (!config.getPushMode().isEnabled()) { + config.setPushMode(PushMode.AUTOMATIC); + } + config.setTransport(transport); + // Ensure no fallback is used + getPushConfiguration().setParameter( + PushConfigurationState.FALLBACK_TRANSPORT_PARAM, "none"); + } + + /** + * This method is inherited from the super class, but it should generally + * not be used. If you want to just add components to your test, use e.g. + * {@link #addComponent(Component)} instead to add the component to the + * layout used by this UI. If you don't want to use the top-level layout + * used by this class, you instead inherit directly from UI. + * + * @deprecated Use {@link #addComponent(Component)} or inherit from UI + * instead. + */ + @Override + @Deprecated + public void setContent(Component content) { + // Overridden just to deprecate + super.setContent(content); + } + + private VerticalLayout layout; + + protected VerticalLayout getLayout() { + return layout; + } + + protected abstract void setup(VaadinRequest request); + + public void addComponent(Component c) { + getLayout().addComponent(c); + } + + public void addComponents(Component... c) { + getLayout().addComponents(c); + } + + public void removeComponent(Component c) { + getLayout().removeComponent(c); + } + + public void replaceComponent(Component oldComponent, + Component newComponent) { + getLayout().replaceComponent(oldComponent, newComponent); + } + + protected void addButton(String caption, Button.ClickListener listener) { + Button button = new Button(caption); + button.addClickListener(listener); + addComponent(button); + } + + protected String getTestDescription() { + return null; + }; + + protected Integer getTicketNumber() { + return null; + }; + + protected WebBrowser getBrowser() { + return getSession().getBrowser(); + } + + /** + * Execute the provided runnable on the UI thread as soon as the current + * request has been sent. + */ + protected void runAfterResponse(final Runnable runnable) { + // Immediately start a thread that will start waiting for the session to + // get unlocked. + new Thread() { + @Override + public void run() { + accessSynchronously(runnable); + } + }.start(); + } +} diff --git a/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/push/BasicPush.java b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/push/BasicPush.java new file mode 100644 index 0000000000..a3f2dd1c47 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/push/BasicPush.java @@ -0,0 +1,146 @@ +/* + * 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.tests.integration.push; + +import com.vaadin.annotations.Push; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.ContentMode; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Label; + +import java.util.Timer; +import java.util.TimerTask; + +@Push +public class BasicPush extends AbstractTestUI { + + public static final String CLIENT_COUNTER_ID = "clientCounter"; + + public static final String STOP_TIMER_ID = "stopTimer"; + + public static final String START_TIMER_ID = "startTimer"; + + public static final String SERVER_COUNTER_ID = "serverCounter"; + + public static final String INCREMENT_BUTTON_ID = "incrementCounter"; + + private int clientCounter = 0; + private int serverCounter = 0; + private final Timer timer = new Timer(true); + + private TimerTask task; + + @Override + protected void setup(VaadinRequest request) { + getReconnectDialogConfiguration().setDialogModal(false); + spacer(); + + /* + * Client initiated push. + */ + Label lbl = new Label("0"); + lbl.setCaption("Client counter (click 'increment' to update):"); + lbl.setId(CLIENT_COUNTER_ID); + addComponent(lbl); + + Button incrementButton = new Button("Increment", + new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + clientCounter++; + lbl.setValue(String.valueOf(clientCounter)); + } + }); + incrementButton.setId(INCREMENT_BUTTON_ID); + addComponent(incrementButton); + + spacer(); + + /* + * Server initiated push. + */ + Label serverCounterLabel = new Label("0"); + serverCounterLabel.setCaption( + "Server counter (updates each 3s by server thread) :"); + serverCounterLabel.setId(SERVER_COUNTER_ID); + addComponent(serverCounterLabel); + + Button startTimer = new Button("Start timer", (ClickListener) event -> { + serverCounter = 0; + serverCounterLabel.setValue(String.valueOf(serverCounter)); + if (task != null) { + task.cancel(); + } + task = new TimerTask() { + + @Override + public void run() { + access(() -> { + serverCounter++; + serverCounterLabel + .setValue(String.valueOf(serverCounter)); + }); + } + }; + timer.scheduleAtFixedRate(task, 3000, 3000); + }); + startTimer.setId(START_TIMER_ID); + addComponent(startTimer); + + Button stopTimer = new Button("Stop timer", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + if (task != null) { + task.cancel(); + task = null; + } + } + }); + stopTimer.setId(STOP_TIMER_ID); + addComponent(stopTimer); + } + + @Override + protected String getTestDescription() { + return "This test tests the very basic operations of push. " + + "It tests that client initiated changes are " + + "recieved back to the client as well as server " + + "initiated changes are correctly updated to the client."; + } + + @Override + protected Integer getTicketNumber() { + return 11494; + } + + private void spacer() { + addComponent(new Label("<hr/>", ContentMode.HTML)); + } + + @Override + public void attach() { + super.attach(); + } + + @Override + public void detach() { + super.detach(); + timer.cancel(); + } +} diff --git a/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/push/BasicPushLongPolling.java b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/push/BasicPushLongPolling.java new file mode 100644 index 0000000000..1ed7848a12 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/java/com/vaadin/tests/integration/push/BasicPushLongPolling.java @@ -0,0 +1,34 @@ +/* + * 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.tests.integration.push; + +import com.vaadin.annotations.Push; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.ui.Transport; +import com.vaadin.shared.ui.ui.UIState.PushConfigurationState; + +@Push(transport = Transport.LONG_POLLING) +public class BasicPushLongPolling extends BasicPush { + + @Override + public void init(VaadinRequest request) { + super.init(request); + // Don't use fallback so we can easier detect if long polling fails + getPushConfiguration().setParameter( + PushConfigurationState.FALLBACK_TRANSPORT_PARAM, "none"); + } + +} diff --git a/test/servlet-containers/generic-ui/src/main/resources/com/vaadin/tests/integration/LabelFromDesign.html b/test/servlet-containers/generic-ui/src/main/resources/com/vaadin/tests/integration/LabelFromDesign.html new file mode 100644 index 0000000000..56329d7d19 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/resources/com/vaadin/tests/integration/LabelFromDesign.html @@ -0,0 +1 @@ +<vaadin-label /> diff --git a/test/servlet-containers/generic-ui/src/main/resources/com/vaadin/tests/integration/fi.gif b/test/servlet-containers/generic-ui/src/main/resources/com/vaadin/tests/integration/fi.gif Binary files differnew file mode 100644 index 0000000000..8d3a191828 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/resources/com/vaadin/tests/integration/fi.gif diff --git a/test/servlet-containers/generic-ui/src/main/resources/com/vaadin/tests/integration/se.gif b/test/servlet-containers/generic-ui/src/main/resources/com/vaadin/tests/integration/se.gif Binary files differnew file mode 100644 index 0000000000..80f6285228 --- /dev/null +++ b/test/servlet-containers/generic-ui/src/main/resources/com/vaadin/tests/integration/se.gif |