From 53674a7cafc22e8e21f5a7d46df0f5c126fb76c6 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Wed, 1 Feb 2017 17:17:15 +0200 Subject: Refactor testing of the framework (#8393) * Integration tests moved from uitest to separate test modules * Run TB4 tests with maven profile * Remove old ant/ivy build scripts from uitest * Add 'needs-ssh' test category for reconnection test * Add default values for testing and validation builds * Add placeholder build.xml with instructions to run Maven --- test/servlet-containers/generic/.gitignore | 1 + test/servlet-containers/generic/build.properties | 8 + test/servlet-containers/generic/build.xml | 49 +++ test/servlet-containers/generic/common.xml | 18 ++ .../generic/integration_base_files/base.xml | 144 +++++++++ .../generic/integration_base_files/cleanup.sh | 26 ++ .../generic/integration_base_files/lock_age.sh | 21 ++ .../generic/integration_tests.xml | 330 +++++++++++++++++++++ test/servlet-containers/generic/ivy-taskdefs.xml | 24 ++ test/servlet-containers/generic/ivy.xml | 134 +++++++++ test/servlet-containers/generic/ivysettings.xml | 77 +++++ test/servlet-containers/generic/pom.xml | 100 +++++++ .../vaadin/tests/IntegrationTestUIProvider.java | 77 +++++ .../vaadin/tests/integration/FlagSeResource.java | 13 + .../ServletIntegrationDefaultPushUI.java | 29 ++ .../ServletIntegrationLongPollingUI.java | 30 ++ .../integration/ServletIntegrationStreamingUI.java | 30 ++ .../tests/integration/ServletIntegrationUI.java | 59 ++++ .../integration/ServletIntegrationWebsocketUI.java | 48 +++ .../tests/integration/push/AbstractTestUI.java | 226 ++++++++++++++ .../vaadin/tests/integration/push/BasicPush.java | 146 +++++++++ .../integration/push/BasicPushLongPolling.java | 34 +++ .../vaadin/tests/integration/LabelFromDesign.html | 1 + .../resources/com/vaadin/tests/integration/fi.gif | Bin 0 -> 371 bytes .../resources/com/vaadin/tests/integration/se.gif | Bin 0 -> 367 bytes .../tests/integration/AbstractIntegrationTest.java | 56 ++++ .../AbstractServletIntegrationTest.java | 81 +++++ .../ServletIntegrationDefaultPushUITest.java | 21 ++ .../ServletIntegrationJSR356WebsocketUITest.java | 32 ++ .../ServletIntegrationLongPollingUITest.java | 21 ++ .../ServletIntegrationStreamingUITest.java | 21 ++ .../tests/integration/ServletIntegrationTests.java | 83 ++++++ .../integration/ServletIntegrationUITest.java | 20 ++ .../ServletIntegrationWebsocketUITest.java | 21 ++ .../tests/integration/push/BasicPushTest.java | 109 +++++++ .../push/LongPollingProxyServerTest.java | 105 +++++++ 36 files changed, 2195 insertions(+) create mode 100644 test/servlet-containers/generic/.gitignore create mode 100644 test/servlet-containers/generic/build.properties create mode 100644 test/servlet-containers/generic/build.xml create mode 100644 test/servlet-containers/generic/common.xml create mode 100644 test/servlet-containers/generic/integration_base_files/base.xml create mode 100644 test/servlet-containers/generic/integration_base_files/cleanup.sh create mode 100644 test/servlet-containers/generic/integration_base_files/lock_age.sh create mode 100644 test/servlet-containers/generic/integration_tests.xml create mode 100644 test/servlet-containers/generic/ivy-taskdefs.xml create mode 100644 test/servlet-containers/generic/ivy.xml create mode 100644 test/servlet-containers/generic/ivysettings.xml create mode 100644 test/servlet-containers/generic/pom.xml create mode 100644 test/servlet-containers/generic/src/main/java/com/vaadin/tests/IntegrationTestUIProvider.java create mode 100644 test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/FlagSeResource.java create mode 100644 test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushUI.java create mode 100644 test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/ServletIntegrationLongPollingUI.java create mode 100644 test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/ServletIntegrationStreamingUI.java create mode 100644 test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/ServletIntegrationUI.java create mode 100644 test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/ServletIntegrationWebsocketUI.java create mode 100644 test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/push/AbstractTestUI.java create mode 100644 test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/push/BasicPush.java create mode 100644 test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/push/BasicPushLongPolling.java create mode 100644 test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/LabelFromDesign.html create mode 100644 test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/fi.gif create mode 100644 test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/se.gif create mode 100644 test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/AbstractIntegrationTest.java create mode 100644 test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/AbstractServletIntegrationTest.java create mode 100644 test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushUITest.java create mode 100644 test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationJSR356WebsocketUITest.java create mode 100644 test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationLongPollingUITest.java create mode 100644 test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationStreamingUITest.java create mode 100644 test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationTests.java create mode 100644 test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationUITest.java create mode 100644 test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationWebsocketUITest.java create mode 100644 test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/push/BasicPushTest.java create mode 100644 test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/push/LongPollingProxyServerTest.java (limited to 'test/servlet-containers/generic') diff --git a/test/servlet-containers/generic/.gitignore b/test/servlet-containers/generic/.gitignore new file mode 100644 index 0000000000..e2f5dd2eb2 --- /dev/null +++ b/test/servlet-containers/generic/.gitignore @@ -0,0 +1 @@ +result \ No newline at end of file diff --git a/test/servlet-containers/generic/build.properties b/test/servlet-containers/generic/build.properties new file mode 100644 index 0000000000..1c2293f06a --- /dev/null +++ b/test/servlet-containers/generic/build.properties @@ -0,0 +1,8 @@ +ivy.organisation=com.vaadin +vaadin.vendor=Vaadin Ltd +vaadin.url=http://vaadin.com +vaadin.java.version=1.6 +vaadin.version=8.0-SNAPSHOT +vaadin.sass.version=0.9.13 +gwt.version=2.7.0.vaadin3 +commons-io.version=2.4 diff --git a/test/servlet-containers/generic/build.xml b/test/servlet-containers/generic/build.xml new file mode 100644 index 0000000000..ee16b2c0e1 --- /dev/null +++ b/test/servlet-containers/generic/build.xml @@ -0,0 +1,49 @@ + + + + + Provides a uitest WAR containing Vaadin UI tests + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/servlet-containers/generic/common.xml b/test/servlet-containers/generic/common.xml new file mode 100644 index 0000000000..7a105ca8bc --- /dev/null +++ b/test/servlet-containers/generic/common.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/test/servlet-containers/generic/integration_base_files/base.xml b/test/servlet-containers/generic/integration_base_files/base.xml new file mode 100644 index 0000000000..74ea41ac06 --- /dev/null +++ b/test/servlet-containers/generic/integration_base_files/base.xml @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${server}: Getting the lock + + + + + + + + ${server}: Got the lock + + + + + + + + + + + + ${server}: Released the lock + + + + + + + diff --git a/test/servlet-containers/generic/integration_base_files/cleanup.sh b/test/servlet-containers/generic/integration_base_files/cleanup.sh new file mode 100644 index 0000000000..42fb5a434d --- /dev/null +++ b/test/servlet-containers/generic/integration_base_files/cleanup.sh @@ -0,0 +1,26 @@ +#! /bin/bash +echo checking and killing open servers + +# Find all java processes, except +# * grep, as we're running it +# * get-lock, as that one is just waiting for this cleanup to happen +# * shutdown-and-cleanup, as that could be the one we're running from +ps x | grep -E bin/java | grep -v grep | grep -v get-lock | grep -v shutdown-and-cleanup | awk '{print $1}' > temp + +#Read and kill processes marked to temp +while read line +do + kill -9 $line +done < temp + +#Remove temp +rm temp + +if [ -a /home/integration/demo.war ] + then + echo removing old demo.war + rm /home/integration/demo.war +fi + +echo Cleaning deploy dir +rm -rf /home/integration/deploy/* diff --git a/test/servlet-containers/generic/integration_base_files/lock_age.sh b/test/servlet-containers/generic/integration_base_files/lock_age.sh new file mode 100644 index 0000000000..115a8fef79 --- /dev/null +++ b/test/servlet-containers/generic/integration_base_files/lock_age.sh @@ -0,0 +1,21 @@ +#! /bin/bash +if lockfile -r0 -! /home/integration/deploy/lock.file &> /dev/null + then + # If we could not get the lock, check how old the lock file is + DATE=$(date +%s) + # What if the file is not there any more? + LOCK_AGE=$(stat -c %Z /home/integration/deploy/lock.file) + + AGE=$[($DATE - $LOCK_AGE)/60] + + if [ "$AGE" -gt "20" ] + then + echo lock.file is $AGE min old. + ./cleanup.sh +# else +# echo lock.file is $AGE min old. + fi + else + # If we got the lock, do a cleanup (releasing the lock) just in case something has still been left running + ./cleanup.sh &> /dev/null +fi diff --git a/test/servlet-containers/generic/integration_tests.xml b/test/servlet-containers/generic/integration_tests.xml new file mode 100644 index 0000000000..a46670b6a3 --- /dev/null +++ b/test/servlet-containers/generic/integration_tests.xml @@ -0,0 +1,330 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Delaying startup of ${target-server} with ${startDelay} seconds + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Starting TB3 test for ${target-server} + + + + + + + + + + + + + + + + + + + + + + + + + ##teamcity[testStarted name='${target-server}' flowId='${target-server}'] + + + + + + + + + + ##teamcity[testFailed name='${target-server}' flowId='${target-server}' message='Integration test for ${target-server} failed.' details='${tried-escaped}'] + + + ##teamcity[testFinished name='${target-server}' flowId='${target-server}']" + + + + + + + + + + + + + + + + ##teamcity[testStarted name='${target-server}' flowId='${target-server}'] + + + + + + + + + + ##teamcity[testFailed name='${target-server}' flowId='${target-server}' message='Integration test for ${target-server} failed.' details='${tried-escaped}']" + + + ##teamcity[testFinished name='${target-server}' flowId='${target-server}']" + + + + + + + + + + + + + + + diff --git a/test/servlet-containers/generic/ivy-taskdefs.xml b/test/servlet-containers/generic/ivy-taskdefs.xml new file mode 100644 index 0000000000..95dca014dc --- /dev/null +++ b/test/servlet-containers/generic/ivy-taskdefs.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + diff --git a/test/servlet-containers/generic/ivy.xml b/test/servlet-containers/generic/ivy.xml new file mode 100644 index 0000000000..33ac7c7c04 --- /dev/null +++ b/test/servlet-containers/generic/ivy.xml @@ -0,0 +1,134 @@ + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/servlet-containers/generic/ivysettings.xml b/test/servlet-containers/generic/ivysettings.xml new file mode 100644 index 0000000000..f28250c3c1 --- /dev/null +++ b/test/servlet-containers/generic/ivysettings.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/servlet-containers/generic/pom.xml b/test/servlet-containers/generic/pom.xml new file mode 100644 index 0000000000..545ef8b52e --- /dev/null +++ b/test/servlet-containers/generic/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + + com.vaadin + vaadin-test + 8.0-SNAPSHOT + ../.. + + vaadin-test-generic-integration + vaadin-test-generic-integration + war + + + + + + + ${project.groupId} + vaadin-compatibility-server + ${project.version} + + + + ${project.groupId} + vaadin-compatibility-client-compiled + ${project.version} + + + ${project.groupId} + vaadin-client-compiled + ${project.version} + + + ${project.groupId} + vaadin-themes + ${project.version} + + + ${project.groupId} + vaadin-push + ${project.version} + + + + ${project.groupId} + vaadin-uitest-common + ${project.version} + test + + + + + + + + + + maven-install-plugin + + true + + + + maven-deploy-plugin + + true + + + + maven-surefire-plugin + + true + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + + true + + + + org.sonatype.plugins + nexus-staging-maven-plugin + + true + + + + maven-javadoc-plugin + + true + + + + + + diff --git a/test/servlet-containers/generic/src/main/java/com/vaadin/tests/IntegrationTestUIProvider.java b/test/servlet-containers/generic/src/main/java/com/vaadin/tests/IntegrationTestUIProvider.java new file mode 100644 index 0000000000..ce64c22577 --- /dev/null +++ b/test/servlet-containers/generic/src/main/java/com/vaadin/tests/IntegrationTestUIProvider.java @@ -0,0 +1,77 @@ +package com.vaadin.tests; + +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; + +import com.vaadin.annotations.VaadinServletConfiguration; +import com.vaadin.server.UIClassSelectionEvent; +import com.vaadin.server.UIProvider; +import com.vaadin.server.VaadinServlet; +import com.vaadin.tests.integration.ServletIntegrationUI; +import com.vaadin.tests.integration.ServletIntegrationWebsocketUI; +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 getUIClass(UIClassSelectionEvent event) { + Class uiClass = findUIClassFromPath(event); + return uiClass != null ? uiClass : BasicPush.class; + } + + private Class 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 getUIClassFromDefaultPackage(String className) { + for (String pkgName : defaultPackages) { + Class uiClass = getUIClass(pkgName + "." + className); + if (uiClass != null) { + return uiClass; + } + } + return null; + } + + private Class getUIClass(String className) { + try { + Class loadClass = getClass().getClassLoader() + .loadClass(className.replace("/", ".")); + return (Class) loadClass; + } catch (ClassNotFoundException e) { + return null; + } + } + + @WebServlet(urlPatterns = "/*", name = "IntegrationTestUIProvider", asyncSupported = true, initParams = { + @WebInitParam(name = "UIProvider", value = "com.vaadin.tests.IntegrationTestUIProvider") }) + @VaadinServletConfiguration(ui = ServletIntegrationUI.class, productionMode = false) + public static class MyServlet extends VaadinServlet { + } + + @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 static class JSR356Servlet extends VaadinServlet { + + } +} diff --git a/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/FlagSeResource.java b/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/FlagSeResource.java new file mode 100644 index 0000000000..8f8fce77c2 --- /dev/null +++ b/test/servlet-containers/generic/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/src/main/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushUI.java b/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushUI.java new file mode 100644 index 0000000000..530e093d8e --- /dev/null +++ b/test/servlet-containers/generic/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/src/main/java/com/vaadin/tests/integration/ServletIntegrationLongPollingUI.java b/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/ServletIntegrationLongPollingUI.java new file mode 100644 index 0000000000..be74683026 --- /dev/null +++ b/test/servlet-containers/generic/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/src/main/java/com/vaadin/tests/integration/ServletIntegrationStreamingUI.java b/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/ServletIntegrationStreamingUI.java new file mode 100644 index 0000000000..540fd70df5 --- /dev/null +++ b/test/servlet-containers/generic/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/src/main/java/com/vaadin/tests/integration/ServletIntegrationUI.java b/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/ServletIntegrationUI.java new file mode 100644 index 0000000000..03a24fbc4c --- /dev/null +++ b/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/ServletIntegrationUI.java @@ -0,0 +1,59 @@ +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.Label; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.declarative.Design; +import com.vaadin.v7.data.Item; +import com.vaadin.v7.data.Property.ValueChangeEvent; +import com.vaadin.v7.data.Property.ValueChangeListener; +import com.vaadin.v7.ui.Table; + +@Widgetset("com.vaadin.v7.Vaadin7WidgetSet") +public class ServletIntegrationUI extends UI { + + @Override + protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + + final Table table = new Table(); + table.addContainerProperty("icon", Resource.class, null); + table.setItemIconPropertyId("icon"); + table.addContainerProperty("country", String.class, null); + table.setRowHeaderMode(Table.RowHeaderMode.ICON_ONLY); + table.setImmediate(true); + table.setSelectable(true); + table.setVisibleColumns(new Object[] { "country" }); + layout.addComponent(table); + + Item item = table.addItem("FI"); + item.getItemProperty("icon").setValue(new ClassResource("fi.gif")); + item.getItemProperty("country").setValue("Finland"); + item = table.addItem("SE"); + item.getItemProperty("icon").setValue(new FlagSeResource()); + item.getItemProperty("country").setValue("Sweden"); + + final Label selectedLabel = new LabelFromDesign(); + table.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + selectedLabel.setValue(String.valueOf(table.getValue())); + } + }); + layout.addComponent(selectedLabel); + } + + @DesignRoot + public static class LabelFromDesign extends Label { + public LabelFromDesign() { + Design.read(this); + } + } +} diff --git a/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/ServletIntegrationWebsocketUI.java b/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/ServletIntegrationWebsocketUI.java new file mode 100644 index 0000000000..cfffa04c11 --- /dev/null +++ b/test/servlet-containers/generic/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/src/main/java/com/vaadin/tests/integration/push/AbstractTestUI.java b/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/push/AbstractTestUI.java new file mode 100644 index 0000000000..c9ef1b82b0 --- /dev/null +++ b/test/servlet-containers/generic/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/src/main/java/com/vaadin/tests/integration/push/BasicPush.java b/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/push/BasicPush.java new file mode 100644 index 0000000000..a3f2dd1c47 --- /dev/null +++ b/test/servlet-containers/generic/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("
", ContentMode.HTML)); + } + + @Override + public void attach() { + super.attach(); + } + + @Override + public void detach() { + super.detach(); + timer.cancel(); + } +} diff --git a/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/push/BasicPushLongPolling.java b/test/servlet-containers/generic/src/main/java/com/vaadin/tests/integration/push/BasicPushLongPolling.java new file mode 100644 index 0000000000..1ed7848a12 --- /dev/null +++ b/test/servlet-containers/generic/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/src/main/resources/com/vaadin/tests/integration/LabelFromDesign.html b/test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/LabelFromDesign.html new file mode 100644 index 0000000000..56329d7d19 --- /dev/null +++ b/test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/LabelFromDesign.html @@ -0,0 +1 @@ + diff --git a/test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/fi.gif b/test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/fi.gif new file mode 100644 index 0000000000..8d3a191828 Binary files /dev/null and b/test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/fi.gif differ diff --git a/test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/se.gif b/test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/se.gif new file mode 100644 index 0000000000..80f6285228 Binary files /dev/null and b/test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/se.gif differ diff --git a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/AbstractIntegrationTest.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/AbstractIntegrationTest.java new file mode 100644 index 0000000000..da0d6cb08e --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/AbstractIntegrationTest.java @@ -0,0 +1,56 @@ +/* + * 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.testbench.By; +import com.vaadin.testbench.elements.UIElement; +import com.vaadin.testbench.parallel.TestNameSuffix; +import com.vaadin.tests.tb3.SingleBrowserTestPhantomJS2; + +/** + * Base class for integration tests. Integration tests use the + * {@literal deployment.url} parameter to determine the base deployment url + * (http://hostname:123) + * + * @author Vaadin Ltd + */ +@TestNameSuffix(property = "server-name") +public abstract class AbstractIntegrationTest + extends SingleBrowserTestPhantomJS2 { + @Override + protected String getBaseURL() { + String deploymentUrl = System.getProperty("deployment.url"); + if (deploymentUrl == null || deploymentUrl.equals("")) { + throw new RuntimeException( + "Deployment url must be given as deployment.url"); + } + return deploymentUrl; + } + + @Override + protected void openTestURL() { + super.openTestURL(); + + waitForApplication(); + } + + protected void waitForApplication() { + if (!isElementPresent(UIElement.class)) { + // Wait for UI element. + waitForElementPresent(By.vaadin("//com.vaadin.ui.UI")); + } + } +} diff --git a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/AbstractServletIntegrationTest.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/AbstractServletIntegrationTest.java new file mode 100644 index 0000000000..a8f291d79d --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/AbstractServletIntegrationTest.java @@ -0,0 +1,81 @@ +/* + * 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 java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized.Parameters; + +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.tests.tb3.ParameterizedTB3Runner; + +/** + * Base class for servlet integration tests. Automatically prepends "/demo" to + * the deployment path + * + * @author Vaadin Ltd + */ +@RunWith(ParameterizedTB3Runner.class) +public abstract class AbstractServletIntegrationTest + extends AbstractIntegrationTest { + + private String contextPath = "/demo"; + + @Test + public void runTest() throws IOException, AssertionError { + openTestURL(); + // make sure no fading progress indicator from table update is lingering + sleep(2000); + compareScreen("initial"); + $(TableElement.class).first().getCell(0, 1).click(); + // without this, table fetch might have a fading progress indicator + sleep(2000); + compareScreen("finland"); + } + + @Override + protected String getDeploymentPath(Class uiClass) { + return contextPath + super.getDeploymentPath(uiClass); + } + + public void setContextPath(String contextPath) { + this.contextPath = contextPath; + } + + @Parameters + public static Collection getContextPaths() { + if (getServerName().equals("wildfly9-nginx")) { + ArrayList paths = new ArrayList<>(); + paths.add("/buffering/demo"); + paths.add("/nonbuffering/demo"); + paths.add("/buffering-timeout/demo"); + paths.add("/nonbuffering-timeout/demo"); + return paths; + } else { + return Collections.emptyList(); + } + } + + protected static String getServerName() { + return System.getProperty("server-name"); + } + +} diff --git a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushUITest.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushUITest.java new file mode 100644 index 0000000000..20c17a3424 --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushUITest.java @@ -0,0 +1,21 @@ +/* + * 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; + +public class ServletIntegrationDefaultPushUITest + extends AbstractServletIntegrationTest { + // Uses the test method declared in the super class +} diff --git a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationJSR356WebsocketUITest.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationJSR356WebsocketUITest.java new file mode 100644 index 0000000000..32338e2c37 --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationJSR356WebsocketUITest.java @@ -0,0 +1,32 @@ +/* + * 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; + +public class ServletIntegrationJSR356WebsocketUITest + extends AbstractServletIntegrationTest { + // Uses the test method declared in the super class + + @Override + protected String getDeploymentPath(Class uiClass) { + return super.getDeploymentPath(uiClass).replace("/run/", + "/run-jsr356/"); + } + + @Override + protected Class getUIClass() { + return ServletIntegrationWebsocketUI.class; + } +} diff --git a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationLongPollingUITest.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationLongPollingUITest.java new file mode 100644 index 0000000000..06f51de57d --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationLongPollingUITest.java @@ -0,0 +1,21 @@ +/* + * 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; + +public class ServletIntegrationLongPollingUITest + extends AbstractServletIntegrationTest { + // Uses the test method declared in the super class +} diff --git a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationStreamingUITest.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationStreamingUITest.java new file mode 100644 index 0000000000..29d5afc06f --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationStreamingUITest.java @@ -0,0 +1,21 @@ +/* + * 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; + +public class ServletIntegrationStreamingUITest + extends AbstractServletIntegrationTest { + // Uses the test method declared in the super class +} diff --git a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationTests.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationTests.java new file mode 100644 index 0000000000..ff30d645bf --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationTests.java @@ -0,0 +1,83 @@ +/* + * 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 java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.vaadin.tests.tb3.TB3TestLocator; +import com.vaadin.tests.tb3.TB3TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.model.InitializationError; + +import com.vaadin.tests.integration.ServletIntegrationTests.ServletIntegrationTestSuite; + +@RunWith(ServletIntegrationTestSuite.class) +public class ServletIntegrationTests { + + public static Set notJSR356Compatible = new HashSet<>(); + public static Set notWebsocketCompatible = new HashSet<>(); + static { + + notJSR356Compatible.add("jetty8"); + notJSR356Compatible.add("tomcat7"); + notJSR356Compatible.add("tomcat7apacheproxy"); + + notWebsocketCompatible.add("tomcat7apacheproxy"); + notWebsocketCompatible.add("weblogic10"); + notWebsocketCompatible.add("wildfly9-nginx"); + + // Jetty 9 but no ws support by default + notWebsocketCompatible.add("karaf4"); + + // If a server does not support any kind of websockets it does not + // support JSR-356 either.. + notJSR356Compatible.addAll(notWebsocketCompatible); + } + + public static class ServletIntegrationTestSuite extends TB3TestSuite { + public ServletIntegrationTestSuite(Class klass) + throws InitializationError, IOException { + super(klass, AbstractIntegrationTest.class, + "com.vaadin.tests.integration", new String[] {}, + new ServletTestLocator()); + } + } + + public static class ServletTestLocator extends TB3TestLocator { + @Override + protected List> findClasses(Class baseClass, + String basePackage, String[] ignoredPackages) + throws IOException { + List> allClasses = super.findClasses(baseClass, + basePackage, ignoredPackages); + String serverName = System.getProperty("server-name"); + + if (notJSR356Compatible.contains(serverName)) { + allClasses + .remove(ServletIntegrationJSR356WebsocketUITest.class); + } + + if (notWebsocketCompatible.contains(serverName)) { + allClasses.remove(ServletIntegrationWebsocketUITest.class); + } + return allClasses; + } + } +} diff --git a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationUITest.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationUITest.java new file mode 100644 index 0000000000..16c3c24685 --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationUITest.java @@ -0,0 +1,20 @@ +/* + * 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; + +public class ServletIntegrationUITest extends AbstractServletIntegrationTest { + // Uses the test method declared in the super class +} diff --git a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationWebsocketUITest.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationWebsocketUITest.java new file mode 100644 index 0000000000..204b1e29b3 --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationWebsocketUITest.java @@ -0,0 +1,21 @@ +/* + * 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; + +public class ServletIntegrationWebsocketUITest + extends AbstractServletIntegrationTest { + // Uses the test method declared in the super class +} diff --git a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/push/BasicPushTest.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/push/BasicPushTest.java new file mode 100644 index 0000000000..082710992b --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/push/BasicPushTest.java @@ -0,0 +1,109 @@ +/* + * 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.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.AbstractTB3Test; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; + +@TestCategory("push") +public abstract class BasicPushTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + } + + @Test + public void testPush() throws InterruptedException { + openTestURL(); + + getIncrementButton().click(); + testBench().disableWaitForVaadin(); + + waitUntilClientCounterChanges(1); + + getIncrementButton().click(); + getIncrementButton().click(); + getIncrementButton().click(); + waitUntilClientCounterChanges(4); + + // Test server initiated push + getServerCounterStartButton().click(); + waitUntilServerCounterChanges(); + } + + public static int getClientCounter(AbstractTB3Test t) { + WebElement clientCounterElem = t + .findElement(By.id(BasicPush.CLIENT_COUNTER_ID)); + return Integer.parseInt(clientCounterElem.getText()); + } + + protected WebElement getIncrementButton() { + return getIncrementButton(this); + } + + protected WebElement getServerCounterStartButton() { + return getServerCounterStartButton(this); + } + + public static int getServerCounter(AbstractTB3Test t) { + WebElement serverCounterElem = t + .findElement(By.id(BasicPush.SERVER_COUNTER_ID)); + return Integer.parseInt(serverCounterElem.getText()); + } + + public static WebElement getServerCounterStartButton(AbstractTB3Test t) { + return t.findElement(By.id(BasicPush.START_TIMER_ID)); + } + + public static WebElement getServerCounterStopButton(AbstractTB3Test t) { + return t.findElement(By.id(BasicPush.STOP_TIMER_ID)); + } + + public static WebElement getIncrementButton(AbstractTB3Test t) { + return t.findElement(By.id(BasicPush.INCREMENT_BUTTON_ID)); + } + + protected void waitUntilClientCounterChanges(final int expectedValue) { + waitUntil(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver input) { + return BasicPushTest + .getClientCounter(BasicPushTest.this) == expectedValue; + } + }, 10); + } + + protected void waitUntilServerCounterChanges() { + final int counter = BasicPushTest.getServerCounter(this); + waitUntil(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver input) { + return BasicPushTest + .getServerCounter(BasicPushTest.this) > counter; + } + }, 10); + } + +} diff --git a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/push/LongPollingProxyServerTest.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/push/LongPollingProxyServerTest.java new file mode 100644 index 0000000000..3357b143a5 --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/push/LongPollingProxyServerTest.java @@ -0,0 +1,105 @@ +/* + * 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.testbench.parallel.Browser; +import com.vaadin.tests.integration.AbstractIntegrationTest; +import com.vaadin.tests.tb3.IncludeIfProperty; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import java.util.Collections; +import java.util.List; + +@IncludeIfProperty(property = "server-name", value = "wildfly9-nginx") +public class LongPollingProxyServerTest extends AbstractIntegrationTest { + + @Override + protected Class getUIClass() { + return BasicPushLongPolling.class; + } + + @Test + public void bufferingTimeoutBasicPush() throws Exception { + basicPush("buffering-timeout"); + } + + @Test + public void nonbufferingTimeoutBasicPush() throws Exception { + basicPush("nonbuffering-timeout"); + } + + @Test + public void bufferingBasicPush() throws Exception { + basicPush("buffering"); + } + + @Test + public void nonbufferingBasicPush() throws Exception { + basicPush("nonbuffering"); + } + + @Test + public void bufferingTimeoutActionAfterFirstTimeout() throws Exception { + actionAfterFirstTimeout("buffering-timeout"); + } + + @Test + public void nonbufferingTimeoutActionAfterFirstTimeout() throws Exception { + actionAfterFirstTimeout("nonbuffering-timeout"); + } + + private String getUrl(String bufferingOrNot) { + return getBaseURL() + "/" + bufferingOrNot + "/demo" + + getDeploymentPath(); + } + + private void actionAfterFirstTimeout(String bufferingOrNot) + throws Exception { + String url = getUrl(bufferingOrNot); + getDriver().get(url); + // The wildfly9-nginx server has a configured timeout of 10s for + // *-timeout urls + Thread.sleep(15000); + Assert.assertEquals(0, BasicPushTest.getClientCounter(this)); + BasicPushTest.getIncrementButton(this).click(); + Assert.assertEquals(1, BasicPushTest.getClientCounter(this)); + } + + private void basicPush(String bufferingOrNot) throws Exception { + String url = getUrl(bufferingOrNot); + getDriver().get(url); + + Assert.assertEquals(0, BasicPushTest.getServerCounter(this)); + BasicPushTest.getServerCounterStartButton(this).click(); + waitUntil(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver input) { + return BasicPushTest + .getServerCounter(LongPollingProxyServerTest.this) > 1; + } + }); + } + + @Override + public List getBrowsersToTest() { + return Collections + .singletonList(Browser.PHANTOMJS.getDesiredCapabilities()); + } +} -- cgit v1.2.3