diff options
author | Build Agent <build@vaadin.com> | 2014-04-16 15:09:25 +0300 |
---|---|---|
committer | Build Agent <build@vaadin.com> | 2014-04-16 15:09:26 +0300 |
commit | 4015bd18e05cd26e73bfcd028bd261172ab82290 (patch) | |
tree | b79e99653cd8d4efd3224a88ffc593f53506bb9a /uitest | |
parent | 202514e6c03877b40bbb17fbb74cf4d68eb21503 (diff) | |
parent | 5057c59a02b6570f6a314dee3379688f0a48981b (diff) | |
download | vaadin-framework-4015bd18e05cd26e73bfcd028bd261172ab82290.tar.gz vaadin-framework-4015bd18e05cd26e73bfcd028bd261172ab82290.zip |
Merge changes from origin/7.1
08b0589 Refactored TimeoutRedirectResetsOnActivity tests.
5057c59 Added integration test for WebSphere Portal. (#13309)
Change-Id: I50c8a8f6513679dca611889b43782d6ee6089d6c
Diffstat (limited to 'uitest')
6 files changed, 324 insertions, 59 deletions
diff --git a/uitest/integration_tests.xml b/uitest/integration_tests.xml index 77c5a94e26..c0d73580bb 100644 --- a/uitest/integration_tests.xml +++ b/uitest/integration_tests.xml @@ -114,7 +114,7 @@ <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" /> @@ -123,6 +123,7 @@ <jvmarg value="-Ddeployment.url=${deployment.url}" /> <jvmarg value="-Dserver-name=${server-name}" /> <jvmarg value="-Djava.awt.headless=true" /> + <jvmarg value="-Ddemo.war=${demo.war}" /> <test name="${junit.test.suite}" todir="${server.report.dir}" /> </junit> </target> @@ -343,6 +344,20 @@ </antcall> </target> + <target name="integration-test-websphereportal8"> + <concat>##teamcity[testStarted name='websphereportal8' flowId='websphereportal8']</concat> + <antcall target="run-tb3-test" inheritall="true"> + <param name="junit.test.suite" value="com.vaadin.tests.integration.WebSpherePortalIntegrationTest" /> + <param name="server-name" value="websphereportal8" /> + + <!-- Fill out dummy values for params required by run-tb3-test target --> + <param name="test.integration.server" value="" /> + <param name="test.integration.user" value="" /> + <param name="test.integration.antfile" value="" /> + </antcall> + <concat>##teamcity[testFinished name='websphereportal8' flowId='websphereportal8']"</concat> + </target> + <target name="integration-test-weblogic10"> <antcall target="run-generic-integration-test"> <param name="startDelay" value="600" /> @@ -375,7 +390,7 @@ <antcall target="integration-test-test-GAE" /> </target> - <!-- Upload demo, clean error screenshots and test deployment on all + <!-- 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}" /> @@ -387,7 +402,7 @@ <parallel> <antcontrib:trycatch property="tried"> <try> - <!-- Still running GAE test from the old server which + <!-- Still running GAE test from the old server which requires its own lock --> <echo message="Getting lock" /> @@ -439,6 +454,7 @@ <antcall target="integration-test-tomcat8" /> <antcall target="integration-test-tomcat7apacheproxy" /> <antcall target="integration-test-websphere8" /> + <antcall target="integration-test-websphereportal8" /> </parallel> </target> @@ -468,11 +484,11 @@ </fileset> </scp> - <!-- trycatch probably not needed any more as it just fails with + <!-- 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 + <!-- 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"> @@ -515,7 +531,7 @@ </antcontrib:else> </antcontrib:if> - <!-- Run theme tests in all browsers if there's a property + <!-- Run theme tests in all browsers if there's a property with the test files --> <antcontrib:if> <isset property="testfiles-theme" /> @@ -565,7 +581,7 @@ <target name="teamcity-escape"> <property name="returnTo" value="return" /> - <!-- Should also perform other escaping (\u0085, \u2028 and \u2029) + <!-- 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}" /> diff --git a/uitest/ivy.xml b/uitest/ivy.xml index 170ffd21cf..ea22172937 100644 --- a/uitest/ivy.xml +++ b/uitest/ivy.xml @@ -57,7 +57,9 @@ <!-- For compiling TestingWidgetSet --> <dependency org="com.vaadin" name="vaadin-client-compiler" - rev="${vaadin.version}" conf="build-provided-> build"></dependency> + rev="${vaadin.version}" conf="build-provided-> build"> + <exclude type="pom" /> + </dependency> <!-- Servlet 3.0 API --> <dependency org="javax.servlet" name="javax.servlet-api" diff --git a/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java index 2c649c9ca8..bf58846060 100644 --- a/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java +++ b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java @@ -23,22 +23,50 @@ import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Label; public class TimeoutRedirectResetsOnActivity extends AbstractTestUI { + private int maxActiveInterval = 15; + private int timeoutOverhead = 15; + @Override protected void setup(VaadinRequest request) { - setupTimout(request); + setupTimeout(request); + + Label startedLabel = new Label(); + startedLabel.setValue(String.valueOf(System.currentTimeMillis())); + startedLabel.setId("startedTime"); + + Label originalLabel = new Label(); + originalLabel.setId("originalExpireTime"); + originalLabel.setValue(String.valueOf(getExpireTime())); - addComponent(new Button("clicky", new Button.ClickListener() { + final Label expiresLabel = new Label(); + expiresLabel.setId("actualExpireTime"); + + Button button = new Button("Reset", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { - // NOOP + expiresLabel.setValue(String.valueOf(getExpireTime())); } - })); + + }); + button.setId("reset"); + + addComponent(button); + + addComponent(startedLabel); + addComponent(originalLabel); + addComponent(expiresLabel); + } + + private long getExpireTime() { + return System.currentTimeMillis() + + (maxActiveInterval + timeoutOverhead) * 1000; } - private void setupTimout(VaadinRequest request) { + private void setupTimeout(VaadinRequest request) { request.getService().setSystemMessagesProvider( new SystemMessagesProvider() { @Override @@ -57,7 +85,7 @@ public class TimeoutRedirectResetsOnActivity extends AbstractTestUI { * implementation details in * com.vaadin.server.communication.MetadataWriter */ - getSession().getSession().setMaxInactiveInterval(10); + getSession().getSession().setMaxInactiveInterval(maxActiveInterval); } @Override diff --git a/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java index 272bacb8d5..f4a7a68983 100644 --- a/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java +++ b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java @@ -15,71 +15,62 @@ */ package com.vaadin.tests.components.ui; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.Rule; import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebElement; import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.tb3.RetryOnFail; public class TimeoutRedirectResetsOnActivityTest extends MultiBrowserTest { + + @Rule + // Timing issues are really hard to resolve in a way that this test would be + // 100% reliable on all browsers. Hence we shall allow one retry. + public RetryOnFail retry = new RetryOnFail(); + + private int waitBeforeActivity = 4000; + private int communicationOverhead = 2000; + + private static int i = 0; + @Test public void verifyRedirectWorks() throws Exception { setDebug(true); openTestURL(); - long startTime = System.currentTimeMillis(); - while (System.currentTimeMillis() - startTime < 30000) { - clickTheButton(); - Thread.sleep(1000); - } + long startedTime = getTime("startedTime"); + long originalExpireTime = getTime("originalExpireTime"); - assertTrue("button disappeared before timeout", buttonIsStillThere()); + Thread.sleep(waitBeforeActivity); + hitButton("reset"); - Thread.sleep(30000); - assertTrue("no redirection occurred within 30 seconds", - !buttonIsStillThere()); - } + Thread.sleep(200); - private boolean buttonIsStillThere() { - try { - return getButton() != null; - } catch (NoSuchElementException e) { - return false; - } - } + long actualExpireTime = getTime("actualExpireTime"); + + Thread.sleep(originalExpireTime - startedTime - waitBeforeActivity); + + assertThat(driver.getCurrentUrl(), is(getTestUrl())); + + testBench().disableWaitForVaadin(); + Thread.sleep(actualExpireTime - originalExpireTime + + communicationOverhead); - private void clickTheButton() { - getButton().click(); + assertThat(driver.getCurrentUrl(), is(not(getTestUrl()))); } - private WebElement getButton() { - /* - * For some reason, the vaadinElement() method doesn't work when tests - * are run outside of "/run/" and "/run-push/" contexts. The given error - * message says that the generated Vaadin path doesn't match any - * elements, but when that selector is put into the recorder, the - * recorder finds it. - * - * XPath works fine. - */ - /*- - return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]"); - */ - return getDriver().findElement( - By.xpath("//div[contains(@class,'v-button')]")); + private long getTime(String id) { + WebElement element = vaadinElementById(id); + return Long.parseLong(element.getText()); } @Override - protected String getDeploymentPath() { - /* - * AbstractTB3Test assumes only /run/ and /run-push/ contexts, so this - * method needs some overriding. - */ - return "/12446/" - + TimeoutRedirectResetsOnActivity.class.getCanonicalName() - + "?restartApplication&debug"; + protected String getTestUrl() { + return super.getTestUrl() + "?restartApplication"; } } diff --git a/uitest/src/com/vaadin/tests/integration/WebSpherePortalIntegrationTest.java b/uitest/src/com/vaadin/tests/integration/WebSpherePortalIntegrationTest.java new file mode 100644 index 0000000000..16c4d80b6e --- /dev/null +++ b/uitest/src/com/vaadin/tests/integration/WebSpherePortalIntegrationTest.java @@ -0,0 +1,163 @@ +/* + * Copyright 2000-2013 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 static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.jcraft.jsch.ChannelExec; +import com.jcraft.jsch.ChannelSftp; +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.Session; +import com.jcraft.jsch.SftpException; +import com.vaadin.tests.tb3.PrivateTB3Configuration; + +public class WebSpherePortalIntegrationTest extends PrivateTB3Configuration { + + @BeforeClass + public static void deployPortlet() throws JSchException, SftpException { + Session session = openSession(); + + uploadDemoApplication(session); + + sendCommand(session, "ant -f deploy.xml get-lock startup-and-deploy"); + + session.disconnect(); + } + + private static void uploadDemoApplication(Session session) + throws JSchException, SftpException { + ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp"); + sftpChannel.connect(); + + String applicationPath = System.getProperty("demo.war"); + if (new File(applicationPath).exists()) { + sftpChannel.put(applicationPath, "demo.war"); + sftpChannel.disconnect(); + } else { + sftpChannel.disconnect(); + throw new AssertionError("Demo application not found at " + + applicationPath); + } + } + + private static void sendCommand(Session session, String command) + throws JSchException { + ChannelExec channel = (ChannelExec) session.openChannel("exec"); + channel.setCommand(command); + BufferedReader in; + try { + in = new BufferedReader(new InputStreamReader( + channel.getInputStream())); + + channel.connect(); + + String msg = null; + + while ((msg = in.readLine()) != null) { + System.out.println(msg); + } + } catch (IOException e) { + e.printStackTrace(); + } + + channel.disconnect(); + } + + private static Session openSession() throws JSchException { + JSch jsch = new JSch(); + Session session = jsch.getSession("integration", + "websphereportal8.devnet.vaadin.com", 22); + jsch.addIdentity("~/.ssh/id_dsa"); + session.setConfig("StrictHostKeyChecking", "no"); + + session.connect(); + return session; + } + + @AfterClass + public static void teardown() throws JSchException { + Session session = openSession(); + + sendCommand(session, "ant -f deploy.xml release-lock"); + + session.disconnect(); + } + + @Override + protected java.lang.String getTestUrl() { + return "http://websphereportal8.devnet.vaadin.com:10039/wps/portal"; + } + + @Override + public void setup() throws Exception { + super.setup(); + + openTestURL(); + + if (!isLoggedIn()) { + login(); + } + + waitUntilPortletIsLoaded(); + } + + private void waitUntilPortletIsLoaded() { + WebDriverWait wait = new WebDriverWait(driver, 15); + wait.until(ExpectedConditions.visibilityOfElementLocated(By + .className("v-app"))); + } + + private boolean isLoggedIn() { + return driver.findElements(By.linkText("Log Out")).size() == 1; + } + + private void login() { + driver.findElement(By.linkText("Log In")).click(); + driver.findElement(By.id("userID")).sendKeys("test"); + driver.findElement(By.id("password")).sendKeys("testtest"); + + hitButton("login.button.login"); + } + + @Test + public void portletHasExpectedLayout() throws IOException { + compareScreen("initial"); + } + + @Test + public void viewModeIsSetToEdit() throws IOException { + driver.findElement(By.linkText("Edit")).click(); + + assertThat(driver.findElement(By.tagName("input")).isEnabled(), + is(true)); + + } + +} diff --git a/uitest/src/com/vaadin/tests/tb3/RetryOnFail.java b/uitest/src/com/vaadin/tests/tb3/RetryOnFail.java new file mode 100644 index 0000000000..b8a3c0e5f3 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/RetryOnFail.java @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2013 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.tb3; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +/** + * <strong>ALWAYS</strong> declare the reason for using this test rule in a + * test. + * + * <p> + * Violators and abusers of this rule will be punished. + * </p> + * + * @since 7.1.14 + * @author Vaadin Ltd + */ +public class RetryOnFail implements TestRule { + private int retryCount = 1; + + @Override + public Statement apply(Statement base, Description description) { + return statement(base, description); + } + + private Statement statement(final Statement base, + final Description description) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + Throwable caughtThrowable = null; + + for (int i = 0; i <= retryCount; i++) { + try { + base.evaluate(); + return; + } catch (Throwable t) { + caughtThrowable = t; + System.err.println(String.format( + "%s: run %s/%s failed.", + description.getDisplayName(), i + 1, + retryCount + 1)); + System.err.println(t.getMessage()); + } + } + throw caughtThrowable; + } + }; + } +} |