diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-10-05 10:09:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-05 10:09:22 +0300 |
commit | 3cbd834842319d151d9248706bc14e14a3abca42 (patch) | |
tree | a2e918d9632512acecf0fcadc31a2ac1a10de71c /test/servlet-containers/generic-tests | |
parent | eda970f667f5784977b63a158b24bd1c1f28ffc4 (diff) | |
download | vaadin-framework-3cbd834842319d151d9248706bc14e14a3abca42.tar.gz vaadin-framework-3cbd834842319d151d9248706bc14e14a3abca42.zip |
Add maven based server tests for Wildfly and Jetty (#10116)
This patch refactors the generic integration test war into
two jar dependencies and individual modules for different servers.
There is now a common approach for making configurations for the
remaining server tests still executed through an Ant build script.
Diffstat (limited to 'test/servlet-containers/generic-tests')
11 files changed, 519 insertions, 0 deletions
diff --git a/test/servlet-containers/generic-tests/pom.xml b/test/servlet-containers/generic-tests/pom.xml new file mode 100644 index 0000000000..b107c40d0a --- /dev/null +++ b/test/servlet-containers/generic-tests/pom.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.vaadin</groupId> + <artifactId>vaadin-servlet-containers-test</artifactId> + <version>8.2-SNAPSHOT</version> + </parent> + <artifactId>vaadin-test-server-tests</artifactId> + <name>vaadin-test-server-tests</name> + <packaging>jar</packaging> + <properties> + <jetty.skip>true</jetty.skip> + </properties> + + <dependencies> + <dependency> + <groupId>com.vaadin</groupId> + <artifactId>vaadin-test-server-ui</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.vaadin</groupId> + <artifactId>vaadin-testbench-api</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + </dependencies> +</project> diff --git a/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/AbstractIntegrationTest.java b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/AbstractIntegrationTest.java new file mode 100644 index 0000000000..79d75f6651 --- /dev/null +++ b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/AbstractIntegrationTest.java @@ -0,0 +1,126 @@ +package com.vaadin.tests.integration; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +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.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.vaadin.testbench.annotations.RunLocally; +import com.vaadin.testbench.elements.UIElement; +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.testbench.parallel.ParallelRunner; +import com.vaadin.testbench.parallel.ParallelTest; +import com.vaadin.testbench.parallel.TestNameSuffix; +import com.vaadin.testbench.screenshot.ImageFileUtil; + +@RunLocally(Browser.PHANTOMJS) +@RunWith(ParallelRunner.class) +@TestNameSuffix(property = "server-name") +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; + + @Override + 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.isEmpty()) { + // Default to http://localhost:8080 + return "http://localhost:8080"; + } + return deploymentUrl; + } + + protected void compareScreen(String identifier) throws IOException { + String refFileName = identifier + "-" + + getDesiredCapabilities().getBrowserName().toLowerCase() + + ".png"; + String errorFileName = identifier + "-" + + getDesiredCapabilities().getBrowserName().toLowerCase() + "-" + + System.getProperty("server-name") + "[" + + getClass().getSimpleName() + "].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; + } + + @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-tests/src/main/java/com/vaadin/tests/integration/AbstractServletIntegrationTest.java b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/AbstractServletIntegrationTest.java new file mode 100644 index 0000000000..03d4f1ce18 --- /dev/null +++ b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/AbstractServletIntegrationTest.java @@ -0,0 +1,30 @@ +package com.vaadin.tests.integration; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.LabelElement; + +public abstract class AbstractServletIntegrationTest + extends AbstractIntegrationTest { + + @Test + public void runTest() throws Exception { + // Test initial state + GridElement grid = $(GridElement.class).first(); + Assert.assertFalse("Row should not be initially selected", + grid.getRow(0).isSelected()); + compareScreen("initial"); + + // Test selection and side effects + grid.getCell(0, 1).click(); + Assert.assertTrue("Row should be selected on click", + grid.getRow(0).isSelected()); + Assert.assertEquals("Text label should contain 'FI'", "FI", + $(LabelElement.class).first().getText()); + compareScreen("finland"); + + } + +} diff --git a/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushIT.java b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushIT.java new file mode 100644 index 0000000000..68b8f36205 --- /dev/null +++ b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationDefaultPushIT.java @@ -0,0 +1,26 @@ +/* + * 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 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-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationIT.java b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationIT.java new file mode 100644 index 0000000000..2d37779eb7 --- /dev/null +++ b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationIT.java @@ -0,0 +1,25 @@ +/* + * 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 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-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationLongPollingIT.java b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationLongPollingIT.java new file mode 100644 index 0000000000..10e36d87bb --- /dev/null +++ b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationLongPollingIT.java @@ -0,0 +1,26 @@ +/* + * 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 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-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationStreamingIT.java b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationStreamingIT.java new file mode 100644 index 0000000000..5aad9899f7 --- /dev/null +++ b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationStreamingIT.java @@ -0,0 +1,26 @@ +/* + * 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 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-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationTests.java b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationTests.java new file mode 100644 index 0000000000..36b6c5b9f7 --- /dev/null +++ b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/ServletIntegrationTests.java @@ -0,0 +1,57 @@ +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 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) +public class ServletIntegrationTests { + + public static Set<String> notJSR356Compatible = new HashSet<>(); + public static Set<String> notWebsocketCompatible = new HashSet<>(); + + static { + notWebsocketCompatible.add("tomcat7apacheproxy"); + notWebsocketCompatible.add("weblogic10"); + notWebsocketCompatible.add("wildfly9-nginx"); + + notJSR356Compatible.add("jetty8"); + notJSR356Compatible.add("tomcat7"); + } + + public static class ServletIntegrationTestSuite extends ParallelTestSuite { + + public ServletIntegrationTestSuite(Class<?> klass) + throws InitializationError, IOException { + super(klass, AbstractIntegrationTest.class, + "com.vaadin.tests.integration", getIgnoredPackages()); + } + + private static String[] getIgnoredPackages() { + List<String> ignoredPackages = new ArrayList<>(); + String serverName = System.getProperty("server-name"); + if (serverName == null) { + serverName = ""; + } + if (!serverName.equals("widfly9-nginx")) { + ignoredPackages.add("com.vaadin.tests.integration.push"); + } + if (notWebsocketCompatible.contains(serverName)) { + ignoredPackages.add("com.vaadin.tests.integration.websocket"); + } else if (notJSR356Compatible.contains(serverName)) { + ignoredPackages + .add("com.vaadin.tests.integration.websocket.jsr356"); + } + + return ignoredPackages.toArray(new String[ignoredPackages.size()]); + } + } +} diff --git a/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/push/LongPollingProxyServerIT.java b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/push/LongPollingProxyServerIT.java new file mode 100644 index 0000000000..7dfd2aa6e6 --- /dev/null +++ b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/push/LongPollingProxyServerIT.java @@ -0,0 +1,114 @@ +/* + * 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 static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assume; +import org.junit.Before; +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.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; + + @Before + public void setup() throws Exception { + Assume.assumeTrue( + "wildfly9-nginx".equals(System.getProperty("server-name"))); + + super.setup(); + } + + @Test + public void actionAfterFirstTimeout() throws Exception { + // The wildfly9-nginx server has a configured timeout of 10s for + // *-timeout urls + Thread.sleep(15000); + assertEquals(0, getClientCounter()); + getIncrementButton().click(); + assertEquals(1, getClientCounter()); + } + + @Test + public void basicPush() { + assertEquals(0, getServerCounter()); + getServerCounterStartButton().click(); + waitUntil(e -> getServerCounter() > 1, 10); + } + + @Override + protected String getContextPath() { + return "/" + path + "/demo"; + } + + @Override + protected String getTestPath() { + return "/"; + } + + 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-tests/src/main/java/com/vaadin/tests/integration/websocket/ServletIntegrationWebsocketIT.java b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/websocket/ServletIntegrationWebsocketIT.java new file mode 100644 index 0000000000..525e4545e4 --- /dev/null +++ b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/websocket/ServletIntegrationWebsocketIT.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; + +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-tests/src/main/java/com/vaadin/tests/integration/websocket/jsr356/ServletIntegrationJSR356WebsocketIT.java b/test/servlet-containers/generic-tests/src/main/java/com/vaadin/tests/integration/websocket/jsr356/ServletIntegrationJSR356WebsocketIT.java new file mode 100644 index 0000000000..f49d3656db --- /dev/null +++ b/test/servlet-containers/generic-tests/src/main/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/"); + } +} |