diff options
author | Sauli Tähkäpää <sauli@vaadin.com> | 2014-04-08 15:34:13 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-04-10 10:10:51 +0000 |
commit | 00a9af50f3a56a0d1e51113d1ae9690ba37f5052 (patch) | |
tree | 72b850e3c270a8d5d6d712835a397cc8e6865992 /uitest/src/com/vaadin/tests | |
parent | 901a0bb7527a4c8b33dae7997c7754d01b33be7a (diff) | |
download | vaadin-framework-00a9af50f3a56a0d1e51113d1ae9690ba37f5052.tar.gz vaadin-framework-00a9af50f3a56a0d1e51113d1ae9690ba37f5052.zip |
Refactor PushConfigurationTest.
Change-Id: Iec0aecc64e16052c522eb831f13cadbd2758ae69
Diffstat (limited to 'uitest/src/com/vaadin/tests')
5 files changed, 209 insertions, 103 deletions
diff --git a/uitest/src/com/vaadin/tests/push/PushConfigurationLongPollingTest.java b/uitest/src/com/vaadin/tests/push/PushConfigurationLongPollingTest.java new file mode 100644 index 0000000000..c0503d5240 --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/PushConfigurationLongPollingTest.java @@ -0,0 +1,58 @@ +/* + * 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.push; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.Select; + +public class PushConfigurationLongPollingTest extends PushConfigurationTest { + + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + List<DesiredCapabilities> browsers = super.getBrowsersToTest(); + + browsers.remove(Browser.IE8.getDesiredCapabilities()); + + return browsers; + } + + @Test + public void testLongPolling() throws InterruptedException { + new Select(getTransportSelect()).selectByVisibleText("LONG_POLLING"); + new Select(getPushModeSelect()).selectByVisibleText("AUTOMATIC"); + + assertThat(getStatusText(), + containsString("fallbackTransport: long-polling")); + assertThat(getStatusText(), containsString("transport: long-polling")); + + waitForServerCounterToUpdate(); + + // Use debug console to verify we used the correct transport type + assertThat( + driver.getPageSource(), + containsString("Push connection established using long-polling")); + + new Select(getPushModeSelect()).selectByVisibleText("DISABLED"); + + } + +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/push/PushConfigurationStreamingTest.java b/uitest/src/com/vaadin/tests/push/PushConfigurationStreamingTest.java new file mode 100644 index 0000000000..46fcc5f44b --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/PushConfigurationStreamingTest.java @@ -0,0 +1,57 @@ +/* + * 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.push; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.Select; + +public class PushConfigurationStreamingTest extends PushConfigurationTest { + + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + List<DesiredCapabilities> browsers = super.getBrowsersToTest(); + + browsers.remove(Browser.IE8.getDesiredCapabilities()); + + return browsers; + } + + @Test + public void testStreaming() throws InterruptedException { + new Select(getTransportSelect()).selectByVisibleText("STREAMING"); + new Select(getPushModeSelect()).selectByVisibleText("AUTOMATIC"); + + assertThat(getStatusText(), + containsString("fallbackTransport: long-polling")); + assertThat(getStatusText(), containsString("transport: streaming")); + + waitForServerCounterToUpdate(); + + // Use debug console to verify we used the correct transport type + assertThat( + driver.getPageSource(), + not(containsString("Push connection established using websocket"))); + assertThat(driver.getPageSource(), + containsString("Push connection established using streaming")); + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java b/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java index d7ffb47bbc..20399fc67e 100644 --- a/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java +++ b/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java @@ -17,139 +17,71 @@ package com.vaadin.tests.push; import static org.junit.Assert.assertEquals; -import org.junit.Assert; -import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.Select; -import com.vaadin.tests.tb3.WebsocketTest; +import com.vaadin.tests.annotations.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; -public class PushConfigurationTest extends WebsocketTest { +@TestCategory("push") +abstract class PushConfigurationTest extends MultiBrowserTest { - @Test - public void testWebsocketAndStreaming() throws InterruptedException { - setDebug(true); - openTestURL(); - // Websocket - verifyPushDisabled(); - new Select(getTransportSelect()).selectByVisibleText("WEBSOCKET"); - new Select(getPushModeSelect()).selectByVisibleText("AUTOMATIC"); - Assert.assertTrue(vaadinElement( - "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]") - .getText() - .matches( - "^[\\s\\S]*fallbackTransport: streaming[\\s\\S]*transport: websocket[\\s\\S]*$")); - int counter = getServerCounter(); - final int waitCounter = counter + 2; - waitUntil(new ExpectedCondition<Boolean>() { - - @Override - public Boolean apply(WebDriver input) { - return (getServerCounter() >= waitCounter); - } - }); - - // Use debug console to verify we used the correct transport type - Assert.assertTrue(driver.getPageSource().contains( - "Push connection established using websocket")); - Assert.assertFalse(driver.getPageSource().contains( - "Push connection established using streaming")); - - new Select(getPushModeSelect()).selectByVisibleText("DISABLED"); - - // Streaming - driver.get(getTestUrl()); - verifyPushDisabled(); - - new Select(getTransportSelect()).selectByVisibleText("STREAMING"); - new Select(getPushModeSelect()).selectByVisibleText("AUTOMATIC"); - Assert.assertTrue(vaadinElement( - "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]") - .getText() - .matches( - "^[\\s\\S]*fallbackTransport: streaming[\\s\\S]*transport: streaming[\\s\\S]*$")); - - counter = getServerCounter(); - for (int second = 0;; second++) { - if (second >= 5) { - Assert.fail("timeout"); - } - if (getServerCounter() >= (counter + 2)) { - break; - } - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - } - } - - // Use debug console to verify we used the correct transport type - Assert.assertFalse(driver.getPageSource().contains( - "Push connection established using websocket")); - Assert.assertTrue(driver.getPageSource().contains( - "Push connection established using streaming")); + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + disablePush(); } - @Test - public void testLongPolling() throws InterruptedException { - setDebug(true); - openTestURL(); - verifyPushDisabled(); - new Select(getTransportSelect()).selectByVisibleText("LONG_POLLING"); - new Select(getPushModeSelect()).selectByVisibleText("AUTOMATIC"); - Assert.assertTrue(vaadinElement( - "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]") - .getText() - .matches( - "^[\\s\\S]*fallbackTransport: streaming[\\s\\S]*transport: long-polling[\\s\\S]*$")); - int counter = getServerCounter(); - final int waitCounter = counter + 2; - waitUntil(new ExpectedCondition<Boolean>() { + @Override + protected String getDeploymentPath() { + return "/run/" + PushConfiguration.class.getCanonicalName() + + "?restartApplication&debug"; + } - @Override - public Boolean apply(WebDriver input) { - return (getServerCounter() >= waitCounter); - } - }); + protected String getStatusText() { + WebElement statusLabel = vaadinElementById("status"); - // Use debug console to verify we used the correct transport type - Assert.assertTrue(driver.getPageSource().contains( - "Push connection established using long-polling")); - Assert.assertFalse(driver.getPageSource().contains( - "Push connection established using streaming")); + return statusLabel.getText(); + } + protected void disablePush() throws InterruptedException { new Select(getPushModeSelect()).selectByVisibleText("DISABLED"); - } - - /** - * Verifies that push is currently not enabled. - * - * @throws InterruptedException - */ - private void verifyPushDisabled() throws InterruptedException { int counter = getServerCounter(); sleep(2000); assertEquals("Server count changed without push enabled", counter, getServerCounter()); } - private WebElement getPushModeSelect() { + protected WebElement getPushModeSelect() { return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]"); } - private WebElement getTransportSelect() { + protected WebElement getTransportSelect() { return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[1]/VNativeSelect[0]/domChild[0]"); } - private int getServerCounter() { + protected int getServerCounter() { return Integer.parseInt(getServerCounterElement().getText()); } - private WebElement getServerCounterElement() { + protected WebElement getServerCounterElement() { return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]"); } + + protected void waitForServerCounterToUpdate() { + int counter = getServerCounter(); + final int waitCounter = counter + 2; + waitUntil(new ExpectedCondition<Boolean>() { + + @Override + public Boolean apply(WebDriver input) { + return (getServerCounter() >= waitCounter); + } + }); + } }
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/push/PushConfigurationWebSocketTest.java b/uitest/src/com/vaadin/tests/push/PushConfigurationWebSocketTest.java new file mode 100644 index 0000000000..c8308e72f1 --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/PushConfigurationWebSocketTest.java @@ -0,0 +1,58 @@ +/* + * 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.push; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.Select; + +public class PushConfigurationWebSocketTest extends PushConfigurationTest { + + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + + List<DesiredCapabilities> browsers = super.getBrowsersToTest(); + browsers.remove(Browser.IE8.getDesiredCapabilities()); + browsers.remove(Browser.IE9.getDesiredCapabilities()); + + return browsers; + } + + @Test + public void testWebsocket() throws InterruptedException { + new Select(getTransportSelect()).selectByVisibleText("WEBSOCKET"); + new Select(getPushModeSelect()).selectByVisibleText("AUTOMATIC"); + + assertThat(getStatusText(), + containsString("fallbackTransport: long-polling")); + assertThat(getStatusText(), containsString("transport: websocket")); + + waitForServerCounterToUpdate(); + + // Use debug console to verify we used the correct transport type + assertThat(driver.getPageSource(), + containsString("Push connection established using websocket")); + assertThat( + driver.getPageSource(), + not(containsString("Push connection established using streaming"))); + } +} diff --git a/uitest/src/com/vaadin/tests/push/PushConfigurator.java b/uitest/src/com/vaadin/tests/push/PushConfigurator.java index 6528366b59..6dbe130b73 100644 --- a/uitest/src/com/vaadin/tests/push/PushConfigurator.java +++ b/uitest/src/com/vaadin/tests/push/PushConfigurator.java @@ -101,6 +101,7 @@ public class PushConfigurator extends VerticalLayout { paramValue.setDefaultComponentAlignment(Alignment.BOTTOM_RIGHT); paramValue.addComponents(parameter, value, set); + status.setId("status"); vl.addComponents(pushMode, transport, fallbackTransport, paramValue, new Label("<hr/>", ContentMode.HTML), status); addComponent(vl); |