diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-02-15 10:45:06 +0200 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-02-15 10:45:06 +0200 |
commit | a2d315550fb0fc8f557698ef60cd1c1b7631a42e (patch) | |
tree | 50a4079cba6331fbd88f284fb9f8c9ca6592bb41 | |
parent | 21544c9df3317d68fb1d01037d6f4a52315fcc24 (diff) | |
download | vaadin-framework-a2d315550fb0fc8f557698ef60cd1c1b7631a42e.tar.gz vaadin-framework-a2d315550fb0fc8f557698ef60cd1c1b7631a42e.zip |
Remove vaadin-uitest-common dependency from server tests (#8551)
Uses custom reference and error files in test project.
17 files changed, 350 insertions, 402 deletions
diff --git a/test/servlet-containers/generic/pom.xml b/test/servlet-containers/generic/pom.xml index 4c1c9b8292..e68e6be2fa 100644 --- a/test/servlet-containers/generic/pom.xml +++ b/test/servlet-containers/generic/pom.xml @@ -1,6 +1,6 @@ <?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"> + 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> @@ -13,6 +13,7 @@ <packaging>war</packaging> <properties> <osgi.bundle.version>8.0.0</osgi.bundle.version> + <jetty.skip>true</jetty.skip> </properties> <dependencies> @@ -41,8 +42,7 @@ </dependency> <dependency> <groupId>com.vaadin</groupId> - <artifactId>vaadin-uitest-common</artifactId> - <version>${project.version}</version> + <artifactId>vaadin-testbench-api</artifactId> <scope>test</scope> </dependency> </dependencies> @@ -51,13 +51,15 @@ <build> <plugins> - <!--TODO run this on different servers--> + <!--TODO run this on different servers --> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>${jetty.version}</version> <configuration> - <skip>true</skip> + <webApp> + <contextPath>/demo</contextPath> + </webApp> </configuration> </plugin> <plugin> @@ -73,13 +75,21 @@ </configuration> </plugin> <plugin> + <artifactId>maven-failsafe-plugin</artifactId> + <!-- Currently tested using an Ant script. --> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> <artifactId>maven-war-plugin</artifactId> <configuration> <archive> <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> </archive> </configuration> - <!-- This execution builds an additional .war file with JBoss 6 specific descriptor --> + <!-- This execution builds an additional .war file with JBoss + 6 specific descriptor --> <executions> <execution> <id>jboss6-war</id> diff --git a/test/servlet-containers/generic/reference-screenshots/finland-phantomjs.png b/test/servlet-containers/generic/reference-screenshots/finland-phantomjs.png Binary files differnew file mode 100644 index 0000000000..e372c198e2 --- /dev/null +++ b/test/servlet-containers/generic/reference-screenshots/finland-phantomjs.png diff --git a/test/servlet-containers/generic/reference-screenshots/initial-phantomjs.png b/test/servlet-containers/generic/reference-screenshots/initial-phantomjs.png Binary files differnew file mode 100644 index 0000000000..642759734e --- /dev/null +++ b/test/servlet-containers/generic/reference-screenshots/initial-phantomjs.png 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 index da0d6cb08e..6a948f63d8 100644 --- 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 @@ -1,37 +1,91 @@ -/* - * 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 java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.logging.Logger; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.imageio.ImageIO; + +import org.junit.After; +import org.junit.runner.RunWith; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.vaadin.testbench.annotations.BrowserConfiguration; +import com.vaadin.testbench.annotations.BrowserFactory; +import com.vaadin.testbench.annotations.RunOnHub; import com.vaadin.testbench.elements.UIElement; +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.testbench.parallel.ParallelRunner; +import com.vaadin.testbench.parallel.ParallelTest; 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 - */ +import com.vaadin.testbench.screenshot.ImageFileUtil; + +@RunOnHub("tb3-hub.intra.itmill.com") +@RunWith(ParallelRunner.class) +@BrowserFactory(CustomBrowserFactory.class) @TestNameSuffix(property = "server-name") -public abstract class AbstractIntegrationTest - extends SingleBrowserTestPhantomJS2 { +public abstract class AbstractIntegrationTest extends ParallelTest { + + /** + * Height of the screenshots we want to capture + */ + private static final int SCREENSHOT_HEIGHT = 850; + + /** + * Width of the screenshots we want to capture + */ + private static final int SCREENSHOT_WIDTH = 1500; + + private boolean screenshotErrors; + + @BrowserConfiguration + public final List<DesiredCapabilities> getBrowsersToTest() { + return getBrowsers().map(BrowserUtil.getBrowserFactory()::create) + .collect(Collectors.toList()); + } + + protected Stream<Browser> getBrowsers() { + return Stream.of(Browser.PHANTOMJS); + } + @Override - protected String getBaseURL() { + public void setup() throws Exception { + super.setup(); + + testBench().resizeViewPortTo(SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT); + + openTestURL(); + } + + private void openTestURL() { + String url = getDeploymentURL() + getContextPath() + getTestPath() + "?" + + getParameters().collect(Collectors.joining("&")); + driver.get(url); + + if (!isElementPresent(UIElement.class)) { + waitUntil(e -> isElementPresent(UIElement.class), 10); + } + } + + protected Stream<String> getParameters() { + return Stream.of("restartApplication"); + } + + /** + * Returns a path where the test UI is found. + * + * @return path for test + */ + protected abstract String getTestPath(); + + private String getDeploymentURL() { String deploymentUrl = System.getProperty("deployment.url"); if (deploymentUrl == null || deploymentUrl.equals("")) { throw new RuntimeException( @@ -40,17 +94,48 @@ public abstract class AbstractIntegrationTest return deploymentUrl; } - @Override - protected void openTestURL() { - super.openTestURL(); - - waitForApplication(); + protected void compareScreen(String identifier) throws IOException { + String refFileName = identifier + "-" + + getDesiredCapabilities().getBrowserName().toLowerCase() + + ".png"; + String errorFileName = identifier + "-" + + getDesiredCapabilities().getBrowserName().toLowerCase() + "-" + + System.getProperty("server-name") + ".png"; + File referenceFile = ImageFileUtil + .getReferenceScreenshotFile(refFileName); + try { + BufferedImage reference = ImageIO.read(referenceFile); + if (testBench().compareScreen(reference, errorFileName)) { + return; + } + } catch (IOException e) { + Logger.getLogger(getClass().getName()).warning( + "Missing screenshot reference: " + referenceFile.getPath()); + } + screenshotErrors = true; } - protected void waitForApplication() { - if (!isElementPresent(UIElement.class)) { - // Wait for UI element. - waitForElementPresent(By.vaadin("//com.vaadin.ui.UI")); + @After + public void teardown() { + if (screenshotErrors) { + throw new RuntimeException("Screenshots failed."); } } + + /** + * Waits the given number of seconds for the given condition to become true. + * Use e.g. as + * {@link #waitUntil(ExpectedConditions.textToBePresentInElement(by, text))} + * + * @param condition + * the condition to wait for to become true + */ + protected <T> void waitUntil(ExpectedCondition<T> condition, + long timeoutInSeconds) { + new WebDriverWait(driver, timeoutInSeconds).until(condition); + } + + protected String getContextPath() { + return "/demo"; + } } 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 index a8f291d79d..fd3600df38 100644 --- 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 @@ -1,81 +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; -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(); + public void runTest() throws Exception { // make sure no fading progress indicator from table update is lingering - sleep(2000); + Thread.sleep(2000); compareScreen("initial"); $(TableElement.class).first().getCell(0, 1).click(); // without this, table fetch might have a fading progress indicator - sleep(2000); + Thread.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/CustomBrowserFactory.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/CustomBrowserFactory.java new file mode 100644 index 0000000000..e66d4b6df5 --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/CustomBrowserFactory.java @@ -0,0 +1,21 @@ +package com.vaadin.tests.integration; + +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.testbench.parallel.DefaultBrowserFactory; + +public class CustomBrowserFactory extends DefaultBrowserFactory { + + @Override + public DesiredCapabilities create(Browser browser) { + DesiredCapabilities capabilities = super.create(browser); + if (BrowserUtil.isPhantomJS(capabilities)) { + capabilities.setVersion("2"); + capabilities.setCapability("phantomjs.binary.path", + "/usr/bin/phantomjs2"); + } + return capabilities; + } +} 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/ServletIntegrationDefaultPushIT.java index 204b1e29b3..68b8f36205 100644 --- 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/ServletIntegrationDefaultPushIT.java @@ -15,7 +15,12 @@ */ package com.vaadin.tests.integration; -public class ServletIntegrationWebsocketUITest +public class ServletIntegrationDefaultPushIT extends AbstractServletIntegrationTest { // Uses the test method declared in the super class + + @Override + protected String getTestPath() { + return "/run/ServletIntegrationDefaultPushUI"; + } } 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/ServletIntegrationIT.java index 16c3c24685..2d37779eb7 100644 --- 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/ServletIntegrationIT.java @@ -15,6 +15,11 @@ */ package com.vaadin.tests.integration; -public class ServletIntegrationUITest extends AbstractServletIntegrationTest { +public class ServletIntegrationIT extends AbstractServletIntegrationTest { // Uses the test method declared in the super class + + @Override + protected String getTestPath() { + return "/run/ServletIntegrationUI"; + } } 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 deleted file mode 100644 index 32338e2c37..0000000000 --- a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/ServletIntegrationJSR356WebsocketUITest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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/ServletIntegrationLongPollingIT.java index 06f51de57d..10e36d87bb 100644 --- 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/ServletIntegrationLongPollingIT.java @@ -15,7 +15,12 @@ */ package com.vaadin.tests.integration; -public class ServletIntegrationLongPollingUITest +public class ServletIntegrationLongPollingIT extends AbstractServletIntegrationTest { // Uses the test method declared in the super class + + @Override + protected String getTestPath() { + return "/run/ServletIntegrationLongPollingUI"; + } } 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/ServletIntegrationStreamingIT.java index 20c17a3424..5aad9899f7 100644 --- 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/ServletIntegrationStreamingIT.java @@ -15,7 +15,12 @@ */ package com.vaadin.tests.integration; -public class ServletIntegrationDefaultPushUITest +public class ServletIntegrationStreamingIT extends AbstractServletIntegrationTest { // Uses the test method declared in the super class + + @Override + protected String getTestPath() { + return "/run/ServletIntegrationStreamingUI"; + } } 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 index ff30d645bf..3f9fdd78de 100644 --- 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 @@ -1,31 +1,15 @@ -/* - * 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.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.testbench.parallel.ParallelTestSuite; import com.vaadin.tests.integration.ServletIntegrationTests.ServletIntegrationTestSuite; @RunWith(ServletIntegrationTestSuite.class) @@ -33,12 +17,8 @@ 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"); + static { notWebsocketCompatible.add("tomcat7apacheproxy"); notWebsocketCompatible.add("weblogic10"); notWebsocketCompatible.add("wildfly9-nginx"); @@ -46,38 +26,35 @@ public class ServletIntegrationTests { // 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); + notJSR356Compatible.add("jetty8"); + notJSR356Compatible.add("tomcat7"); } - public static class ServletIntegrationTestSuite extends TB3TestSuite { + public static class ServletIntegrationTestSuite extends ParallelTestSuite { + public ServletIntegrationTestSuite(Class<?> klass) throws InitializationError, IOException { super(klass, AbstractIntegrationTest.class, - "com.vaadin.tests.integration", new String[] {}, - new ServletTestLocator()); + "com.vaadin.tests.integration", getIgnoredPackages()); } - } - 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); + private static String[] getIgnoredPackages() { + List<String> ignoredPackages = new ArrayList<>(); String serverName = System.getProperty("server-name"); - - if (notJSR356Compatible.contains(serverName)) { - allClasses - .remove(ServletIntegrationJSR356WebsocketUITest.class); + if (serverName == null) { + serverName = ""; + } + if (!serverName.equals("widfly9-nginx")) { + ignoredPackages.add("com.vaadin.tests.integration.push"); } - if (notWebsocketCompatible.contains(serverName)) { - allClasses.remove(ServletIntegrationWebsocketUITest.class); + ignoredPackages.add("com.vaadin.tests.integration.websocket"); + } else if (notJSR356Compatible.contains(serverName)) { + ignoredPackages + .add("com.vaadin.tests.integration.websocket.jsr356"); } - return allClasses; + + return ignoredPackages.toArray(new String[ignoredPackages.size()]); } } } 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 deleted file mode 100644 index 082710992b..0000000000 --- a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/push/BasicPushTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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/LongPollingProxyServerIT.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/push/LongPollingProxyServerIT.java new file mode 100644 index 0000000000..dc1fe4e6a8 --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/push/LongPollingProxyServerIT.java @@ -0,0 +1,106 @@ +/* + * 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 java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.tests.integration.AbstractIntegrationTest; + +@RunWith(Parameterized.class) +public class LongPollingProxyServerIT extends AbstractIntegrationTest { + + @Parameters(name = "{0}") + public static List<String[]> getTestParameters() { + List<String[]> parameters = new ArrayList<>(); + addTestParams(parameters, "Buffering+Timeout", "buffering-timeout"); + addTestParams(parameters, "NonBuffering+Timeout", + "nonbuffering-timeout"); + addTestParams(parameters, "Buffering", "buffering"); + addTestParams(parameters, "NonBuffering", "nonbuffering"); + return parameters; + } + + private static void addTestParams(List<String[]> parameters, + String... pair) { + parameters.add(pair); + } + + @Parameter(0) + public String name; + + @Parameter(1) + public String path; + + @Override + public void setup() throws Exception { + setDesiredCapabilities(Browser.PHANTOMJS.getDesiredCapabilities()); + + super.setup(); + } + + @Test + public void actionAfterFirstTimeout() throws Exception { + // The wildfly9-nginx server has a configured timeout of 10s for + // *-timeout urls + Thread.sleep(15000); + Assert.assertEquals(0, getClientCounter()); + getIncrementButton().click(); + Assert.assertEquals(1, getClientCounter()); + } + + @Test + public void basicPush() { + Assert.assertEquals(0, getServerCounter()); + getServerCounterStartButton().click(); + waitUntil(e -> getServerCounter() > 1, 10); + } + + @Override + protected String getTestPath() { + return "/" + path + "/demo"; + } + + private int getClientCounter() { + WebElement clientCounterElem = findElement( + By.id(BasicPush.CLIENT_COUNTER_ID)); + return Integer.parseInt(clientCounterElem.getText()); + } + + private int getServerCounter() { + WebElement serverCounterElem = findElement( + By.id(BasicPush.SERVER_COUNTER_ID)); + return Integer.parseInt(serverCounterElem.getText()); + } + + private WebElement getServerCounterStartButton() { + return findElement(By.id(BasicPush.START_TIMER_ID)); + } + + private WebElement getIncrementButton() { + return findElement(By.id(BasicPush.INCREMENT_BUTTON_ID)); + } +} 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 deleted file mode 100644 index 3357b143a5..0000000000 --- a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/push/LongPollingProxyServerTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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()); - } -} 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/websocket/ServletIntegrationWebsocketIT.java index 29d5afc06f..525e4545e4 100644 --- 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/websocket/ServletIntegrationWebsocketIT.java @@ -13,9 +13,16 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.integration; +package com.vaadin.tests.integration.websocket; -public class ServletIntegrationStreamingUITest +import com.vaadin.tests.integration.AbstractServletIntegrationTest; + +public class ServletIntegrationWebsocketIT extends AbstractServletIntegrationTest { // Uses the test method declared in the super class + + @Override + protected String getTestPath() { + return "/run/ServletIntegrationWebsocketUI"; + } } diff --git a/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/websocket/jsr356/ServletIntegrationJSR356WebsocketIT.java b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/websocket/jsr356/ServletIntegrationJSR356WebsocketIT.java new file mode 100644 index 0000000000..f49d3656db --- /dev/null +++ b/test/servlet-containers/generic/src/test/java/com/vaadin/tests/integration/websocket/jsr356/ServletIntegrationJSR356WebsocketIT.java @@ -0,0 +1,28 @@ +/* + * 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.websocket.jsr356; + +import com.vaadin.tests.integration.websocket.ServletIntegrationWebsocketIT; + +public class ServletIntegrationJSR356WebsocketIT + extends ServletIntegrationWebsocketIT { + // Uses the test method declared in the super class + + @Override + protected String getTestPath() { + return super.getTestPath().replace("/run/", "/run-jsr356/"); + } +} |