diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-02-01 17:17:15 +0200 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-02-01 17:17:15 +0200 |
commit | 53674a7cafc22e8e21f5a7d46df0f5c126fb76c6 (patch) | |
tree | 7bb8916c2b891808e78ca95f0ae150e9b03060cc /test | |
parent | 8e20ab0f05603cb81a8bdbf456f63c9a49eb1d3b (diff) | |
download | vaadin-framework-53674a7cafc22e8e21f5a7d46df0f5c126fb76c6.tar.gz vaadin-framework-53674a7cafc22e8e21f5a7d46df0f5c126fb76c6.zip |
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
Diffstat (limited to 'test')
37 files changed, 2196 insertions, 0 deletions
diff --git a/test/pom.xml b/test/pom.xml index e44986ffb1..f8cefa468c 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -101,6 +101,7 @@ <module>space in directory</module> <module>vaadinservletconfiguration-widget-set</module> <module>spring-boot</module> + <module>servlet-containers/generic</module> <module>cdi</module> <module>servlet-containers/jsp-integration</module> <module>bean-api-validation</module> 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 @@ +<?xml version="1.0"?> + +<project name="vaadin-uitest" basedir="." default="test-server" + xmlns:ivy="antlib:org.apache.ivy.ant"> + <description> + Provides a uitest WAR containing Vaadin UI tests + </description> + <include file="./common.xml" as="common" /> + + <!-- global properties --> + <property name="module.name" value="vaadin-test-generic-integration" /> + <property name="uitest.dir" location="${common.basedir}" /><!-- todo rename--> + <property name="result.dir" value="result" /> + <property name="result.war" + location="${uitest.dir}/target/${module.name}-${vaadin.version}.war" /> + + <!-- Need to give a default value to keep Ivy happy --> + <property name="vaadin.build.repository" value="http://maven.vaadin.com/vaadin-prereleases"/> + + <target name="clean"> + <fail unless="result.dir" message="No result.dir parameter given" /> + <delete dir="${result.dir}" /> + </target> + + <target name="test-server" depends="clean-testbench-errors"> + <property name="war.file" location="${result.war}" /> + <mkdir dir="${vaadin.basedir}/result" /> + <ant antfile="integration_tests.xml" + target="integration-test-all" inheritall="false" + inheritrefs="false"> + <property name="demo.war" value="${war.file}" /> + </ant> + </target> + + + <target name="clean-testbench-errors"><!--todo remove when have got rid of screenshots--> + <fail unless="com.vaadin.testbench.screenshot.directory" + message="Define screenshot directory using -Dcom.vaadin.testbench.screenshot.directory" /> + <mkdir dir="${com.vaadin.testbench.screenshot.directory}/errors" /> + <delete> + <fileset + dir="${com.vaadin.testbench.screenshot.directory}/errors"> + <include name="*" /> + </fileset> + </delete> + </target> + + +</project> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project name="common" basedir="." default="" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:antcontrib="antlib:net.sf.antcontrib" xmlns:cs="antlib:com.puppycrawl.tools.checkstyle"> + + <tstamp> + <format property="build.date" pattern="yyyy-MM-dd" /> + </tstamp> + + <dirname property="vaadin.basedir" file="${ant.file.common}/../../../" /> + <dirname property="common.basedir" file="${ant.file.common}" /> + <property file="${common.basedir}/build.properties" /> + + <ivy:settings file="${common.basedir}/ivysettings.xml" /> + <ivy:settings file="${common.basedir}/ivysettings.xml" id="ivysettings" /> + <ivy:resolve log="download-only" file="${common.basedir}/ivy-taskdefs.xml" conf="taskdefs" /> + <ivy:cachepath pathid="taskdefs.classpath" conf="taskdefs" /> + <taskdef uri="antlib:net.sf.antcontrib" resource="net/sf/antcontrib/antlib.xml" classpathref="taskdefs.classpath" /> + +</project> 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 @@ +<?xml version="1.0"?> +<project name="test" basedir="."> + <property file="deploy.properties" /> + <property name="vaadin.major.7" value="1" /> + <property name="lock" value="deploy/lock.file" /> + <property name="deployDir" value="deploy/${server}" /> + <property name="serverPort" value="8080" /> + <property name="war" value="demo.war" /> + <property name="startupSpawn" value="false" /> + <property name="JAVA_HOME" value="/usr/lib/jvm/default-java" /> + <property name="waitMinutes" value="3" /> + <property name="waitUrl" + value="http://localhost:${serverPort}/demo/VAADIN/themes/valo/styles.css" /> + <property name="shutdownWait" value="10" /> + + + <target name="afterDeploy"> + <!-- Empty default --> + </target> + + <target name="beforeDeploy"> + <!-- Empty default --> + </target> + + <target name="deploy"> + <antcall target="beforeDeploy" /> + <echo + message="${server}: Deploying ${war} to ${deployDir}/${autodeployDir}" /> + <copy file="${war}" todir="${deployDir}/${autodeployDir}" /> + <antcall target="afterDeploy" /> + </target> + + <target name="deployStatic"> + <unzip src="${war}" dest="${staticDeployDir}/tmp-unpack-jar/"> + <patternset> + <include name="WEB-INF/lib/*.jar" /> + </patternset> + </unzip> + <unzip dest="${staticDeployDir}"> + <fileset dir="${staticDeployDir}/tmp-unpack-jar/WEB-INF/lib" + includes="*.jar" /> + + <patternset> + <include name="VAADIN/**" /> + </patternset> + </unzip> + <delete dir="${staticDeployDir}/tmp-unpack-jar/" /> + + <unzip src="${war}" dest="${staticDeployDir}"> + <patternset> + <include name="VAADIN/**" /> + </patternset> + </unzip> + </target> + + <target name="unpack-server"> + <echo message="${server}: Unpacking ${server}.tar.gz" /> + <delete dir="${server}" /> + <exec executable="tar"> + <arg value="-xf" /> + <arg value="${server}.tar.gz" /> + </exec> + <move file="${server}" tofile="${deployDir}" /> + <echo message="Done." /> + </target> + + <target name="doStartup"> + <exec executable="./run.sh" spawn="${startupSpawn}"> + <env key="JAVA_HOME" value="${JAVA_HOME}" /> + </exec> + </target> + + <target name="startup"> + <antcall target="doStartup" /> + <echo message="${server}: Waiting for ${waitUrl} to become available." /> + <waitfor maxwait="${waitMinutes}" maxwaitunit="minute" + checkevery="10000" timeoutproperty="timeout"> + <http url="${waitUrl}" /> + </waitfor> + <!-- Print load averages to get an indicator on whether the server + still attempts to start up --> + <exec executable="uptime" /> + <fail if="timeout" message="${server} failed to deploy" /> + + <echo message="${server}: Demo deployed successfully." /> + </target> + + <target name="shutdown"> + <exec executable="./stop.sh"> + <env key="JAVA_HOME" value="${JAVA_HOME}" /> + </exec> + <sleep seconds="${shutdownWait}" /> + </target> + + <target name="force-shutdown"> + <exec executable="./cleanup.sh" /> + </target> + + <target name="check-port"> + <fail + message="${server}: Something is still listening on port ${serverPort}"> + <condition> + <socket server="localhost" port="${serverPort}" /> + </condition> + </fail> + </target> + + <target name="check-lock"> + <available file="${lock}" property="lockAvailable" /> + <fail unless="lockAvailable" message="Instance is not locked!" /> + </target> + + <target name="get-lock"> + <mkdir dir="deploy" /> + <echo>${server}: Getting the lock</echo> + <exec executable="lockfile" failonerror="true"> + <!-- Check every 10 seconds --> + <arg value="-10" /> + <!-- Retry for 55 minutes (build server gives up after 60 minutes) --> + <arg value="-r330" /> + <arg value="${lock}" /> + </exec> + <echo>${server}: Got the lock</echo> + </target> + + <target name="clean"> + <delete dir="${deployDir}" failonerror="false" /> + </target> + + <target name="release-lock"> + <!-- <exec executable="rm"> <arg value="-f" /> <arg value="${lock}" + /> </exec> --> + <delete> + <fileset dir="." includes="${lock}" /> + </delete> + <echo>${server}: Released the lock</echo> + </target> + + <target name="startup-and-deploy" + depends="check-lock,check-port,unpack-server,deploy,startup" /> + + <target name="shutdown-and-cleanup" depends="shutdown,clean,release-lock,force-shutdown" /> + +</project> 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 @@ +<?xml version="1.0"?> + +<project xmlns:antcontrib="antlib:net.sf.antcontrib" xmlns:ivy="antlib:org.apache.ivy.ant" name="Vaadin Integration Tests" basedir="." default="integration-test-all"> + + <!-- Import common targets --> + <import file="common.xml" /> + <dirname file="${ant.file.Vaadin Integration Tests}" property="integration_test.dir" /> + + <!-- Target deploying demo.war --> + <fail unless="test.integration.server" message="test.integration.server must be set for integration tests to run" /> + + <fail unless="test.integration.user" message="test.integration.user must be set for integration tests to run" /> + <fail unless="test.integration.antfile" message="test.integration.antfile must be set for integration tests to run" /> + + <!-- Test with these browsers --> + <property name="test_browsers" value="winxp-firefox17-esr" /> + + <!-- Path to key file. Default value --> + <property name="sshkey.file" value="id_dsa" /> + + <!-- path and name for demo.war to be deployed --> + <property name="demo.war" value="demo.war" /> + + <!-- Host running Testbench RC or Testbench Hub. Default value --> + <property name="com.vaadin.testbench.tester.host" value="127.0.0.1" /> + + <!-- Base url where the testable application is deployed --> + <property name="deployment.url" value="http://${test.integration.server}:8080" /> + + <!-- TestBench license parameter --> + <property name="vaadin.testbench.developer.license" value="" /> + + <property name="report.dir" location="${vaadin.basedir}/result/reports-integration" /> + + <!-- ssh host values --> + <property name="ant.hub" value="${test.integration.antfile}" /> + <property name="user" value="${test.integration.user}" /> + <property name="passphrase" value="" /> + + <ivy:resolve file="ivy.xml" conf="build, build-provided" /> + <ivy:cachepath pathid="classpath.tb3.lib" conf="build, build-provided" /> + <path id="classpath.tb3"> + <path location="target/test-classes" /> + <path refid="classpath.tb3.lib" /> + <path location="target/classes" /> + </path> + + <!-- Upload war to deploy to ssh host --> + <target name="integration-test-upload-demo"> + <scp file="${demo.war}" todir="${user}@${test.integration.server}:integration-tests/servers/demo.war" keyfile="${sshkey.file}" passphrase="${passphrase}" /> + </target> + + <target name="run-tb3-servlet-test"> + <antcall target="run-tb3-test" inheritall="true"> + <param name="junit.test.suite" value="com.vaadin.tests.integration.ServletIntegrationTests" /> + </antcall> + </target> + <target name="run-tb3-test"> + <fail unless="server-name" message="Server name must be defined in server-name" /> + <fail unless="deployment.url" message="Deplyoment url must be defined in deployment.url" /> + <fail unless="com.vaadin.testbench.screenshot.directory" message="Screenshot directory must be defined in com.vaadin.testbench.screenshot.directory" /> + <property name="server.report.dir" location="${report.dir}/integration-test-tb3/${server-name}" /> + <!-- The junit task does not create the report dir... --> + <mkdir dir="${server.report.dir}" /> + + <junit showoutput="no" printsummary="no" fork="yes"> + <formatter type="xml" /> + <classpath refid="classpath.tb3" /> + + <jvmarg value="-Dcom.vaadin.testbench.screenshot.directory=${com.vaadin.testbench.screenshot.directory}" /> + <jvmarg value="-Ddeployment.url=${deployment.url}" /> + <jvmarg value="-Dserver-name=${server-name}" /> + <jvmarg value="-Djava.awt.headless=true" /> + <jvmarg value="-Ddemo.war=${demo.war}" /> + <jvmarg value="-Dvaadin.testbench.developer.license=${vaadin.testbench.developer.license}" /> + <test name="${junit.test.suite}" todir="${server.report.dir}" /> + </junit> + </target> + + <target name="integration-test-tomcat7"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="10" /> + <param name="target-server" value="tomcat7" /> + </antcall> + </target> + <target name="integration-test-tomcat7apacheproxy"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="10" /> + <param name="target-server" value="tomcat7apacheproxy" /> + </antcall> + </target> + <target name="integration-test-tomcat8"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="10" /> + <param name="target-server" value="tomcat8" /> + </antcall> + </target> + + <target name="integration-test-osgi"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="10" /> + <param name="target-server" value="karaf4" /> + </antcall> + </target> + + <target name="integration-test-jetty8"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="90" /> + <param name="target-server" value="jetty8" /> + </antcall> + </target> + + <target name="integration-test-jetty9"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="90" /> + <param name="target-server" value="jetty9" /> + </antcall> + </target> + + <target name="integration-test-jboss-eap6"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="10" /> + <param name="target-server" value="jbosseap6" /> + </antcall> + </target> + <target name="integration-test-wildfly8"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="10" /> + <param name="target-server" value="wildfly8" /> + </antcall> + </target> + <target name="integration-test-wildfly9"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="10" /> + <param name="target-server" value="wildfly9" /> + </antcall> + </target> + <target name="integration-test-wildfly10"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="10" /> + <param name="target-server" value="wildfly10" /> + </antcall> + </target> + <target name="integration-test-wildfly9-nginx"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="10" /> + <param name="target-server" value="wildfly9-nginx" /> + <param name="target-port" value="80" /> + </antcall> + </target> + <target name="integration-test-glassfish4"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="10" /> + <param name="target-server" value="glassfish4" /> + </antcall> + </target> + <target name="integration-test-payara"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="10" /> + <param name="target-server" value="payara" /> + </antcall> + </target> + + + <target name="integration-test-weblogic12"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="60" /> + <param name="target-port" value="7001" /> + <param name="target-server" value="weblogic12" /> + </antcall> + </target> + + + <!-- Upload demo, clean error screenshots and test deployment on all + servers --> + <target name="integration-test-all" unless="tests.integration.skip"> + <property name="passphrase" value="${passphrase}" /> + <fail unless="sshkey.file" message="You must define an ssh.keyfile parameter" /> + <fail unless="com.vaadin.testbench.screenshot.directory" message="You must define a com.vaadin.testbench.screenshot.directory parameter" /> + <delete dir="${report.dir}" /> + <mkdir dir="${report.dir}" /> + + <parallel> + <antcall target="integration-test-weblogic12" /> + <antcall target="integration-test-glassfish4" /> + <antcall target="integration-test-payara" /> + <antcall target="integration-test-jboss-eap6" /> + <antcall target="integration-test-wildfly8" /> + <antcall target="integration-test-wildfly9" /> + <antcall target="integration-test-wildfly10" /> + <antcall target="integration-test-jetty8" /> + <antcall target="integration-test-jetty9" /> + <antcall target="integration-test-tomcat7" /> + <antcall target="integration-test-tomcat8" /> + <antcall target="integration-test-osgi" /> + <antcall target="integration-test-tomcat7apacheproxy" /> + </parallel> + + </target> + + <target name="do-run-generic-test"> + <property name="target-host" value="${target-server}.devnet.vaadin.com" /> + <property name="target-port" value="8080" /> + <antcontrib:if> + <isset property="startDelay" /> + <then> + <echo>Delaying startup of ${target-server} with ${startDelay} seconds</echo> + <sleep seconds="${startDelay}" /> + </then> + </antcontrib:if> + + <scp todir="${user}@${target-host}:." keyfile="${sshkey.file}" trust="yes" passphrase="${passphrase}"> + <fileset dir="integration_base_files"> + <include name="*" /> + </fileset> + </scp> + + <!-- trycatch probably not needed any more as it just fails with + the original message and doesn't do anything in the finally block --> + <antcontrib:trycatch property="error_message"> + <try> + <!-- timeout in one hour (remote end should timeout in 55 + minutes) --> + <sshexec host="${target-host}" outputproperty="lock-output" timeout="3600000" username="${user}" keyfile="${sshkey.file}" trust="yes" command="chmod +x *.sh; ant -f deploy.xml get-lock" /> + <antcall target="echo-prefix"> + <param name="prefix" value="${target-server}: " /> + <param name="message" value="${lock-output}" /> + </antcall> + + <scp file="${demo.war}" todir="${user}@${target-host}:demo.war" keyfile="${sshkey.file}" trust="yes" passphrase="${passphrase}" /> + + <!-- timeout in 15 minutes --> + <sshexec host="${target-host}" outputproperty="start-output" timeout="900000" username="${user}" keyfile="${sshkey.file}" trust="yes" command="ant -f deploy.xml startup-and-deploy" failonerror="false" /> + <antcall target="echo-prefix"> + <param name="prefix" value="${target-server}: " /> + <param name="message" value="${start-output}" /> + </antcall> + + <fail message="${start-output}"> + <condition> + <not> + <contains string="${start-output}" substring="Demo deployed successfully" /> + </not> + </condition> + </fail> + + <echo>Starting TB3 test for ${target-server}</echo> + <antcall target="run-tb3-servlet-test"> + <param name="server-name" value="${target-server}" /> + <param name="deployment.url" value="http://${target-host}:${target-port}" /> + </antcall> + + <!-- timeout in five minutes --> + <sshexec host="${target-host}" outputproperty="stop-output" timeout="600000" username="${user}" keyfile="${sshkey.file}" trust="yes" command="ant -f deploy.xml shutdown-and-cleanup" failonerror="false" /> + <antcall target="echo-prefix"> + <param name="prefix" value="${target-server}: " /> + <param name="message" value="${stop-output}" /> + </antcall> + </try> + <catch> + <fail message="${error_message}" /> + </catch> + </antcontrib:trycatch> + </target> + + <target name="echo-prefix"> + <antcontrib:propertyregex property="message-prefixed" input="${prefix}${message}" regexp="\n" replace="\0${prefix}" global="true" defaultValue="${prefix}${message}" /> + <echo message="${message-prefixed}" /> + </target> + + <target name="run-generic-integration-test"> + <concat>##teamcity[testStarted name='${target-server}' flowId='${target-server}']</concat> + <antcontrib:trycatch property="tried"> + <try> + <antcall target="do-run-generic-test" /> + </try> + <catch> + <antcontrib:antcallback target="teamcity-escape" return="tried-escaped"> + <param name="returnTo" value="tried-escaped" /> + <param name="message" value="${tried}" /> + </antcontrib:antcallback> + <concat>##teamcity[testFailed name='${target-server}' flowId='${target-server}' message='Integration test for ${target-server} failed.' details='${tried-escaped}']</concat> + </catch> + </antcontrib:trycatch> + <concat>##teamcity[testFinished name='${target-server}' flowId='${target-server}']"</concat> + </target> + + <target name="teamcity-escape"> + <property name="returnTo" value="return" /> + + <!-- Should also perform other escaping (\u0085, \u2028 and \u2029) + - see http://confluence.jetbrains.net/display/TCD65/Build+Script+Interaction+with+TeamCity --> + <!-- Immutable properties -> needs to create a new one every time --> + <antcontrib:propertyregex property="details-escaped1" input="${message}" regexp="['|\[\]]" replace="|\0" global="true" defaultValue="${message}" /> + <antcontrib:propertyregex property="details-escaped2" input="${details-escaped1}" regexp="\n" replace="|n" global="true" defaultValue="${details-escaped1}" /> + <antcontrib:propertyregex property="details-escaped3" input="${details-escaped2}" regexp="\r" replace="|r" global="true" defaultValue="${details-escaped2}" /> + + <property name="${returnTo}" value="${details-escaped3}" /> + </target> + + <target name="run-integration-test"> + <concat>##teamcity[testStarted name='${target-server}' flowId='${target-server}']</concat> + <antcontrib:trycatch property="tried"> + <try> + <antcall target="integration-test-${target-server}" /> + </try> + <catch> + <antcallback target="teamcity-escape" return="tried-escaped"> + <param name="returnTo" value="tried-escaped" /> + <param name="message" value="${tried}" /> + </antcallback> + <concat>##teamcity[testFailed name='${target-server}' flowId='${target-server}' message='Integration test for ${target-server} failed.' details='${tried-escaped}']"</concat> + </catch> + </antcontrib:trycatch> + <concat>##teamcity[testFinished name='${target-server}' flowId='${target-server}']"</concat> + </target> + + <target name="integration-test-get-lock"> + <sshexec host="${test.integration.server}" username="${user}" keyfile="${sshkey.file}" command="ant -f ${ant.hub} get-lock" /> + </target> + + <target name="integration-test-release-lock"> + <sshexec host="${test.integration.server}" username="${user}" keyfile="${sshkey.file}" command="ant -f ${ant.hub} release-lock" /> + </target> + + <!-- Remove demo.war --> + <target name="integration-test-clean"> + <sshexec host="${test.integration.server}" username="${user}" keyfile="${sshkey.file}" command="ant -f ${ant.hub} clean" /> + </target> +</project> 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 @@ + +<ivy-module version="2.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"> + + <info organisation="com.vaadin" module="vaadin" /> + <configurations> + <conf name="taskdefs" description="Ant task definitions" + visibility="private" /> + </configurations> + <publications /> + <dependencies> + <!-- Ant tasks --> + <dependency org="ant-contrib" name="ant-contrib" rev="1.0b3" + conf="taskdefs ->master" /> + <dependency org="org.apache.maven" name="maven-ant-tasks" + rev="2.1.2" conf="taskdefs ->master" /> + <dependency org="com.googlecode.jarjar" name="jarjar" + rev="1.3" conf="taskdefs ->master" /> + <dependency org="com.puppycrawl.tools" name="checkstyle" + rev="5.6" /> + </dependencies> + +</ivy-module> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE ivy-module [ + <!ENTITY jetty.version "8.1.12.v20130726"> +]> +<ivy-module version="2.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd" + xmlns:m="http://ant.apache.org/ivy/maven"> + + <info organisation="com.vaadin" module="vaadin-uitest" + revision="${vaadin.version}" /> + + <configurations> + <conf name="build" /> + <conf name="build-provided" visibility="private" /> + <conf name="jetty-run" visibility="private" /> + </configurations> + <dependencies defaultconf="build" defaultconfmapping="build->default"> + <!-- API DEPENDENCIES --> + <dependency org="javax.portlet" name="portlet-api" + rev="2.0" conf="build-provided -> default" /> + + <dependency org="javax.validation" name="validation-api" + rev="1.0.0.GA" conf="build -> default,sources" /> + <dependency org="org.hibernate" name="hibernate-validator" + rev="4.2.0.Final" conf="build -> default" /> + + <!-- LIBRARY DEPENDENCIES (compile time) --> + <!-- Project modules --> + <dependency org="com.vaadin" name="vaadin-uitest-common" + rev="${vaadin.version}" conf="build->default"> + <exclude type="pom" /> + </dependency> + <dependency org="com.vaadin" name="vaadin-server" + rev="${vaadin.version}" conf="build->default"> + <exclude org="javax.servlet"></exclude> + <exclude type="pom" /> + </dependency> + <dependency org="com.vaadin" name="vaadin-compatibility-server" + rev="${vaadin.version}" conf="build->default"> + <exclude org="javax.servlet"></exclude> + <exclude type="pom" /> + </dependency> + <dependency org="com.vaadin" name="vaadin-client" + rev="${vaadin.version}" conf="build->default"> + <exclude org="javax.validation"></exclude> + <exclude type="pom" /> + </dependency> + <dependency org="com.vaadin" name="vaadin-compatibility-client" + rev="${vaadin.version}" conf="build->default"> + <exclude org="javax.validation"></exclude> + <exclude type="pom" /> + </dependency> + <dependency org="com.vaadin" name="vaadin-client-compiled" + rev="${vaadin.version}" conf="build->default"> + <exclude type="pom" /> + </dependency> + <dependency org="com.vaadin" name="vaadin-compatibility-client-compiled" + rev="${vaadin.version}" conf="build->default"> + <exclude type="pom" /> + </dependency> + <dependency org="com.vaadin" name="vaadin-themes" + rev="${vaadin.version}" conf="build->default"> + <exclude type="pom" /> + </dependency> + <dependency org="com.vaadin" name="vaadin-push" rev="${vaadin.version}" + conf="build->default"> + <exclude org="javax.servlet"></exclude> + <exclude type="pom" /> + </dependency> + + <!-- For compiling TestingWidgetSet --> + <dependency org="com.vaadin" name="vaadin-client-compiler" + rev="${vaadin.version}" conf="build-provided-> default"> + <exclude type="pom" /> + </dependency> + + <!-- Servlet 3.0 API --> + <dependency org="javax.servlet" name="javax.servlet-api" + rev="3.0.1" conf="build-provided -> default" /> + + <dependency org="org.eclipse.jetty" name="jetty-server" + rev="&jetty.version;" conf="build-provided, jetty-run->default"> + <exclude org="org.eclipse.jetty.orbit"></exclude> + </dependency> + <!-- jetty-servlets needed by ProxyTest, but not by jetty-runner --> + <dependency org="org.eclipse.jetty" name="jetty-servlets" + rev="&jetty.version;" conf="build-provided, jetty-run->default"> + <exclude org="org.eclipse.jetty.orbit"></exclude> + </dependency> + <dependency org="org.eclipse.jetty" name="jetty-websocket" + rev="&jetty.version;" conf="build-provided, jetty-run->default"> + <exclude org="org.eclipse.jetty.orbit"></exclude> + </dependency> + <dependency org="org.eclipse.jetty" name="jetty-webapp" + rev="&jetty.version;" conf="build-provided, jetty-run->default"> + <exclude org="org.eclipse.jetty.orbit"></exclude> + </dependency> + <dependency org="org.eclipse.jetty" name="jetty-util" + rev="&jetty.version;" conf="build-provided, jetty-run->default"> + <exclude org="org.eclipse.jetty.orbit"></exclude> + </dependency> + <dependency org="org.mortbay.jetty" name="jetty-runner" + rev="&jetty.version;" conf="build-provided, jetty-run->default"> + <exclude org="org.eclipse.jetty.orbit"></exclude> + </dependency> + + <dependency org="junit" name="junit" rev="4.12" + conf="build -> default" /> + <dependency org="org.hamcrest" name="hamcrest-all" + rev="1.3" conf="build->default" /> + <dependency org="com.jcraft" name="jsch" rev="0.1.52" + conf="build->default" /> + <dependency org="commons-codec" name="commons-codec" + rev="1.5" conf="build->default" /> + <dependency org="commons-io" name="commons-io" + rev="${commons-io.version}" conf="build->default" /> + <!-- Mainly for SQLContainer tests --> + <dependency org="org.hsqldb" name="hsqldb" rev="2.2.6" + conf="build -> default" /> + <dependency org="com.vaadin" name="vaadin-testbench-api" + rev="${vaadin.version}" conf="build-provided -> default" /> + <!-- This should be removed once tests have been updated to use lang3 --> + <dependency org="commons-lang" name="commons-lang" + rev="2.6" conf="build -> default" /> + + <dependency org="org.eclipse.jgit" name="org.eclipse.jgit" + rev="3.5.1.201410131835-r" conf="build->default"> + <exclude org="org.apache.httpcomponents"></exclude> + </dependency> + + </dependencies> + +</ivy-module> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ivysettings> + <!-- Default ivysettings.xml stuff --> + <include url="${ivy.default.settings.dir}/ivysettings-public.xml" /> + <include url="${ivy.default.settings.dir}/ivysettings-shared.xml" /> + <include url="${ivy.default.settings.dir}/ivysettings-local.xml" /> + <include url="${ivy.default.settings.dir}/ivysettings-main-chain.xml" /> + <include url="${ivy.default.settings.dir}/ivysettings-default-chain.xml" /> + + <!-- Customized stuff --> + <settings defaultResolver="public" /> + <resolvers> + <ibiblio name="public" m2compatible="true" /> + <ibiblio name="vaadin-addons" usepoms="true" + m2compatible="true" root="http://maven.vaadin.com/vaadin-addons" /> + <filesystem name="local-maven" m2compatible="true"> + <artifact + pattern="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]" /> + <ivy + pattern="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).pom" /> + </filesystem> + <ibiblio name="vaadin-build" usepoms="true" + m2compatible="true" root="${vaadin.build.repository}" /> + <chain name="vaadin-maven" returnFirst="true"> + <resolver ref="local-maven" /> + <resolver ref="vaadin-build" /> + </chain> + </resolvers> + <modules> + <module organisation="com.vaadin" name="vaadin-testbench" + resolver="vaadin-addons" /> + <module organisation="com.vaadin" name="vaadin-testbench-parent" + resolver="vaadin-addons" /> + <module organisation="com.vaadin" name="vaadin-testbench-core" + resolver="vaadin-addons" /> + <module organisation="com.vaadin" name="vaadin-testbench-api" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-buildhelpers" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-root" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-shared" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-compatibility-shared" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-server" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-compatibility-server" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-client" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-compatibility-client" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-client-compiler" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-client-compiled" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-compatibility-client-compiled" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-themes" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-compatibility-themes" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-push" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-widgets" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-bom" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-liferay" + resolver="vaadin-maven" /> + <module organisation="com.vaadin" name="vaadin-uitest-common" + resolver="vaadin-maven" /> + </modules> + + +</ivysettings> 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 @@ +<?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-test</artifactId> + <version>8.0-SNAPSHOT</version> + <relativePath>../..</relativePath> + </parent> + <artifactId>vaadin-test-generic-integration</artifactId> + <name>vaadin-test-generic-integration</name> + <packaging>war</packaging> + + <dependencies> + + <!-- LIBRARY DEPENDENCIES (compile time) --> + <!-- Project modules --> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>vaadin-compatibility-server</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>vaadin-compatibility-client-compiled</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>vaadin-client-compiled</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>vaadin-themes</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>vaadin-push</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>vaadin-uitest-common</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + + + <build> + + <plugins> + <!--TODO run this on different servers--> + <plugin> + <artifactId>maven-install-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <artifactId>maven-deploy-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>animal-sniffer-maven-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <groupId>org.sonatype.plugins</groupId> + <artifactId>nexus-staging-maven-plugin</artifactId> + <configuration> + <skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo> + </configuration> + </plugin> + <plugin> + <artifactId>maven-javadoc-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> + +</project> 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<? 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; + } + } + + @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("<hr/>", 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 @@ +<vaadin-label /> 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 Binary files differnew file mode 100644 index 0000000000..8d3a191828 --- /dev/null +++ b/test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/fi.gif 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 Binary files differnew file mode 100644 index 0000000000..80f6285228 --- /dev/null +++ b/test/servlet-containers/generic/src/main/resources/com/vaadin/tests/integration/se.gif 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<String> getContextPaths() { + if (getServerName().equals("wildfly9-nginx")) { + ArrayList<String> 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<String> notJSR356Compatible = new HashSet<>(); + public static Set<String> 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 <T> List<Class<? extends T>> findClasses(Class<T> baseClass, + String basePackage, String[] ignoredPackages) + throws IOException { + List<Class<? extends T>> 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<Boolean>() { + + @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<Boolean>() { + + @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<Boolean>() { + @Override + public Boolean apply(WebDriver input) { + return BasicPushTest + .getServerCounter(LongPollingProxyServerTest.this) > 1; + } + }); + } + + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + return Collections + .singletonList(Browser.PHANTOMJS.getDesiredCapabilities()); + } +} |