From ddbb619651a9073666274592359124ce271725ed Mon Sep 17 00:00:00 2001 From: Ilia Motornyi Date: Thu, 26 Jan 2017 16:27:54 +0200 Subject: JspIntegrationTest as a separate module (#8228) Part of vaadin/framework8-issues#539 --- test/pom.xml | 3 + test/servlet-containers/jsp-integration/pom.xml | 30 ++++++ .../vaadin/tests/integration/AnotherTrivialUI.java | 28 ++++++ .../com/vaadin/tests/integration/TrivialUI.java | 30 ++++++ .../src/main/webapp/WEB-INF/web.xml | 57 +++++++++++ .../src/main/webapp/staticfiles/vaadinsessions.jsp | 54 +++++++++++ .../vaadin/tests/integration/JSPIntegrationIT.java | 105 +++++++++++++++++++++ uitest/src/main/webapp/WEB-INF/web.xml | 5 - .../main/webapp/statictestfiles/vaadinsessions.jsp | 54 ----------- .../tests/integration/JSPIntegrationTest.java | 100 -------------------- 10 files changed, 307 insertions(+), 159 deletions(-) create mode 100644 test/servlet-containers/jsp-integration/pom.xml create mode 100644 test/servlet-containers/jsp-integration/src/main/java/com/vaadin/tests/integration/AnotherTrivialUI.java create mode 100644 test/servlet-containers/jsp-integration/src/main/java/com/vaadin/tests/integration/TrivialUI.java create mode 100644 test/servlet-containers/jsp-integration/src/main/webapp/WEB-INF/web.xml create mode 100644 test/servlet-containers/jsp-integration/src/main/webapp/staticfiles/vaadinsessions.jsp create mode 100644 test/servlet-containers/jsp-integration/src/test/java/com/vaadin/tests/integration/JSPIntegrationIT.java delete mode 100644 uitest/src/main/webapp/statictestfiles/vaadinsessions.jsp delete mode 100644 uitest/src/test/java/com/vaadin/tests/integration/JSPIntegrationTest.java diff --git a/test/pom.xml b/test/pom.xml index d0a148cbfa..b9493fcb55 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -17,6 +17,8 @@ ${vaadin.version} false 2.0-SNAPSHOT + UTF-8 + UTF-8 true @@ -99,6 +101,7 @@ vaadinservletconfiguration-widget-set spring-boot cdi + servlet-containers/jsp-integration bean-api-validation bean-impl-validation diff --git a/test/servlet-containers/jsp-integration/pom.xml b/test/servlet-containers/jsp-integration/pom.xml new file mode 100644 index 0000000000..c32914c3c0 --- /dev/null +++ b/test/servlet-containers/jsp-integration/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + com.vaadin + vaadin-test + 8.0-SNAPSHOT + ../.. + + vaadin-test-jsp-integration + vaadin-test-jsp-integration + war + + + + + com.vaadin + vaadin-client-compiled + + + + com.vaadin + vaadin-uitest-common + ${project.version} + test + + + + diff --git a/test/servlet-containers/jsp-integration/src/main/java/com/vaadin/tests/integration/AnotherTrivialUI.java b/test/servlet-containers/jsp-integration/src/main/java/com/vaadin/tests/integration/AnotherTrivialUI.java new file mode 100644 index 0000000000..a165b81282 --- /dev/null +++ b/test/servlet-containers/jsp-integration/src/main/java/com/vaadin/tests/integration/AnotherTrivialUI.java @@ -0,0 +1,28 @@ +package com.vaadin.tests.integration; +/* + * Copyright 2000-2017 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. + */ + +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Label; +import com.vaadin.ui.UI; + +public class AnotherTrivialUI extends UI { + @Override + protected void init(VaadinRequest request) { + setContent(new Label("Another Trivial UI")); + } + +} diff --git a/test/servlet-containers/jsp-integration/src/main/java/com/vaadin/tests/integration/TrivialUI.java b/test/servlet-containers/jsp-integration/src/main/java/com/vaadin/tests/integration/TrivialUI.java new file mode 100644 index 0000000000..b7c7a56b52 --- /dev/null +++ b/test/servlet-containers/jsp-integration/src/main/java/com/vaadin/tests/integration/TrivialUI.java @@ -0,0 +1,30 @@ +package com.vaadin.tests.integration; +/* + * Copyright 2000-2017 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. + */ + +import com.vaadin.annotations.VaadinServletConfiguration; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinServlet; +import com.vaadin.ui.Label; +import com.vaadin.ui.UI; + +public class TrivialUI extends UI { + @Override + protected void init(VaadinRequest request) { + setContent(new Label("Trivial UI")); + } + +} diff --git a/test/servlet-containers/jsp-integration/src/main/webapp/WEB-INF/web.xml b/test/servlet-containers/jsp-integration/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..1d0326bd19 --- /dev/null +++ b/test/servlet-containers/jsp-integration/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,57 @@ + + + + + + Vaadin + Vaadin JSP Integration Test + + + productionMode + false + + + + VaadinStaticFiles + com.vaadin.server.VaadinServlet + false + + + + PrimaryUIServlet + com.vaadin.server.VaadinServlet + + UI + com.vaadin.tests.integration.TrivialUI + + true + + + + SecondaryUIServlet + com.vaadin.server.VaadinServlet + + UI + com.vaadin.tests.integration.AnotherTrivialUI + + true + + + + PrimaryUIServlet + /primaryui/* + + + + SecondaryUIServlet + /secondaryui/* + + + + VaadinStaticFiles + /VAADIN/* + + + diff --git a/test/servlet-containers/jsp-integration/src/main/webapp/staticfiles/vaadinsessions.jsp b/test/servlet-containers/jsp-integration/src/main/webapp/staticfiles/vaadinsessions.jsp new file mode 100644 index 0000000000..b22787a203 --- /dev/null +++ b/test/servlet-containers/jsp-integration/src/main/webapp/staticfiles/vaadinsessions.jsp @@ -0,0 +1,54 @@ + +<%@page import="com.vaadin.ui.UI"%> +<%@page import="com.vaadin.server.VaadinSession"%> + + +JSP integration + + + + + + + + + + + + + + + <% + HttpSession httpSession = request.getSession(false); + for (VaadinSession vs : VaadinSession.getAllSessions(httpSession)) { + try { + vs.lock(); + for (UI ui : vs.getUIs()) { + out.append(""); + out.append(""); + out.append(""); + out.append(""); + out.append(""); + out.append(""); + out.append(""); + + } + } finally { + vs.unlock(); + } + + } + %> +
Available UIs:
Service NameCSRF tokenUI idUI typeMain content
" + vs.getService().getServiceName() + + "" + vs.getCsrfToken() + "" + ui.getUIId() + "" + ui.getClass().getName() + "" + ui.getContent().getClass().getName() + "
+ + \ No newline at end of file diff --git a/test/servlet-containers/jsp-integration/src/test/java/com/vaadin/tests/integration/JSPIntegrationIT.java b/test/servlet-containers/jsp-integration/src/test/java/com/vaadin/tests/integration/JSPIntegrationIT.java new file mode 100644 index 0000000000..5a6c62724e --- /dev/null +++ b/test/servlet-containers/jsp-integration/src/test/java/com/vaadin/tests/integration/JSPIntegrationIT.java @@ -0,0 +1,105 @@ +package com.vaadin.tests.integration; +/* + * Copyright 2000-2017 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. + */ + +import com.vaadin.testbench.TestBenchTestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.phantomjs.PhantomJSDriver; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +public class JSPIntegrationIT extends TestBenchTestCase { + + private static final String URL_PREFIX = "http://localhost:8080/"; + + private static final String primaryUIUrl = URL_PREFIX + "primaryui"; + private static final String jspUrl = URL_PREFIX + "staticfiles/vaadinsessions.jsp"; + private static final String secondaryUIUrl = URL_PREFIX + "secondaryui"; + + @Test + public void listVaadinSessions() { + + assertUICount(0); + + // Open a new UI + getDriver().navigate().to(primaryUIUrl); + + + assertUICount(1); + UIData firstUI = getUIs().get(0); + + // Open a new UI + getDriver().navigate().to(primaryUIUrl); + UIData secondUI = getUIs().get(0); + + // Should now have UI for the same service with different uiId + assertUICount(1); + assertNotEquals(firstUI.uiId, secondUI.uiId); + assertEquals(firstUI.serviceName, secondUI.serviceName); + + getDriver().navigate().to(secondaryUIUrl); + // Should now have another services + List twoUIs = getUIs(); + assertEquals(2, twoUIs.size()); + assertNotEquals(twoUIs.get(0).serviceName, twoUIs.get(1).serviceName); + } + + private static class UIData { + private String serviceName; + private int uiId; + } + + private List getUIs() { + List uis = new ArrayList<>(); + + getDriver().get(jspUrl); + List rows = getDriver() + .findElements(By.xpath("//tr[@class='uirow']")); + for (WebElement row : rows) { + UIData data = new UIData(); + List tds = row.findElements(By.xpath("./td")); + + data.serviceName = tds.get(0).getText(); + data.uiId = Integer.parseInt(tds.get(2).getText()); + + uis.add(data); + } + + return uis; + } + + private void assertUICount(int i) { + assertEquals(i, getUIs().size()); + } + + @Before + public void setup() { + setDriver(new PhantomJSDriver()); + } + + @After + public void teardown() { + getDriver().quit(); + } +} diff --git a/uitest/src/main/webapp/WEB-INF/web.xml b/uitest/src/main/webapp/WEB-INF/web.xml index 31f535e383..4f7ed062a8 100644 --- a/uitest/src/main/webapp/WEB-INF/web.xml +++ b/uitest/src/main/webapp/WEB-INF/web.xml @@ -210,11 +210,6 @@ /run-jsr356/* - - IntegrationTest - /integration/* - - CommErrorEmulator /commerror/* diff --git a/uitest/src/main/webapp/statictestfiles/vaadinsessions.jsp b/uitest/src/main/webapp/statictestfiles/vaadinsessions.jsp deleted file mode 100644 index b22787a203..0000000000 --- a/uitest/src/main/webapp/statictestfiles/vaadinsessions.jsp +++ /dev/null @@ -1,54 +0,0 @@ - -<%@page import="com.vaadin.ui.UI"%> -<%@page import="com.vaadin.server.VaadinSession"%> - - -JSP integration - - - - - - - - - - - - - - - <% - HttpSession httpSession = request.getSession(false); - for (VaadinSession vs : VaadinSession.getAllSessions(httpSession)) { - try { - vs.lock(); - for (UI ui : vs.getUIs()) { - out.append(""); - out.append(""); - out.append(""); - out.append(""); - out.append(""); - out.append(""); - out.append(""); - - } - } finally { - vs.unlock(); - } - - } - %> -
Available UIs:
Service NameCSRF tokenUI idUI typeMain content
" + vs.getService().getServiceName() - + "" + vs.getCsrfToken() + "" + ui.getUIId() + "" + ui.getClass().getName() + "" + ui.getContent().getClass().getName() + "
- - \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/integration/JSPIntegrationTest.java b/uitest/src/test/java/com/vaadin/tests/integration/JSPIntegrationTest.java deleted file mode 100644 index 3a7f907354..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/integration/JSPIntegrationTest.java +++ /dev/null @@ -1,100 +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; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import com.vaadin.tests.tb3.SingleBrowserTestPhantomJS2; - -public class JSPIntegrationTest extends SingleBrowserTestPhantomJS2 { - - final String appRunnerTestUrl = getBaseURL() + "/run/Buttons"; - final String jspUrl = getBaseURL() + "/statictestfiles/vaadinsessions.jsp"; - final String integrationUrl = getBaseURL() + "/integration"; - - @Test - public void listVaadinSessions() { - - assertUICount(0); - - // Open a new UI - getDriver().get(integrationUrl); - assertUICount(1); - - // Open a new UI - getDriver().get(integrationUrl); - - // Should now have two UIs for the same service with different uiIds - List twoUIs = getUIs(); - assertEquals(2, twoUIs.size()); - assertNotEquals(twoUIs.get(0).uiId, twoUIs.get(1).uiId); - assertEquals(twoUIs.get(0).serviceName, twoUIs.get(1).serviceName); - - getDriver().get(appRunnerTestUrl); - // Should now have two services with 2 + 1 UIs - List threeUIs = getUIs(); - assertEquals(3, threeUIs.size()); - Set serviceNames = new HashSet<>(); - Set uiIds = new HashSet<>(); - for (UIData uiData : threeUIs) { - serviceNames.add(uiData.serviceName); - uiIds.add(uiData.uiId); - } - assertGreaterOrEqual( - "There should be at least two unique service names", - serviceNames.size(), 2); - assertGreaterOrEqual("There should be at least two unique ui ids", - uiIds.size(), 2); - } - - private static class UIData { - private String serviceName; - private int uiId; - } - - private List getUIs() { - List uis = new ArrayList<>(); - - getDriver().get(jspUrl); - List rows = getDriver() - .findElements(By.xpath("//tr[@class='uirow']")); - for (WebElement row : rows) { - UIData data = new UIData(); - List tds = row.findElements(By.xpath("./td")); - - data.serviceName = tds.get(0).getText(); - data.uiId = Integer.parseInt(tds.get(2).getText()); - - uis.add(data); - } - - return uis; - } - - private void assertUICount(int i) { - assertEquals(i, getUIs().size()); - } -} -- cgit v1.2.3