diff options
author | Artur Signell <artur@vaadin.com> | 2013-10-07 18:12:06 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-10-08 12:25:17 +0000 |
commit | f488825d46c984cea841534178b094be3a562eea (patch) | |
tree | 2fe8898d4bb7a520ddfdb7b81e0392abe7a505da /uitest/src/com/vaadin/tests/push | |
parent | 63e16e6547b4a7c067a9a1fa53dcecb9d704016b (diff) | |
download | vaadin-framework-f488825d46c984cea841534178b094be3a562eea.tar.gz vaadin-framework-f488825d46c984cea841534178b094be3a562eea.zip |
Update TB3+ convention to use a separate *Test file
For any issue there should be a UI class, e.g. LabelSomething and a
Test class which has the name of the UI + Test, e.g. LabelSomethingTest.
The LabelSomethingTest contains ALL tests which depend on LabelSomething
and are named accordingly to what they test.
For special and legacy cases also LegacyApplication and UIProvider are
supported in addition to UI classes
Change-Id: Ifc0180b377284bbd029202494ad194d324f8213b
Diffstat (limited to 'uitest/src/com/vaadin/tests/push')
17 files changed, 568 insertions, 495 deletions
diff --git a/uitest/src/com/vaadin/tests/push/BarInUIDL.java b/uitest/src/com/vaadin/tests/push/BarInUIDL.java index ebf349683d..bc05f7c306 100644 --- a/uitest/src/com/vaadin/tests/push/BarInUIDL.java +++ b/uitest/src/com/vaadin/tests/push/BarInUIDL.java @@ -16,15 +16,10 @@ package com.vaadin.tests.push; -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.WebElement; - import com.vaadin.annotations.Push; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.ui.Transport; import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Label; @@ -32,29 +27,6 @@ import com.vaadin.ui.Label; @Push(transport = Transport.STREAMING) public class BarInUIDL extends AbstractTestUI { - public static class BarInUIDLTest extends MultiBrowserTest { - @Test - public void sendBarInUIDL() { - openTestURL(); - getButton().click(); - Assert.assertEquals( - "Thank you for clicking | bar", - vaadinElement( - "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]") - .getText()); - getButton().click(); - Assert.assertEquals( - "Thank you for clicking | bar", - vaadinElement( - "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VLabel[0]") - .getText()); - } - - private WebElement getButton() { - return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]"); - } - } - /* * (non-Javadoc) * diff --git a/uitest/src/com/vaadin/tests/push/BarInUIDLTest.java b/uitest/src/com/vaadin/tests/push/BarInUIDLTest.java new file mode 100644 index 0000000000..840d653e1e --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/BarInUIDLTest.java @@ -0,0 +1,45 @@ +/* + * 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 org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class BarInUIDLTest extends MultiBrowserTest { + @Test + public void sendBarInUIDL() { + openTestURL(); + getButton().click(); + Assert.assertEquals( + "Thank you for clicking | bar", + vaadinElement( + "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]") + .getText()); + getButton().click(); + Assert.assertEquals( + "Thank you for clicking | bar", + vaadinElement( + "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VLabel[0]") + .getText()); + } + + private WebElement getButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]"); + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/push/BasicPush.java b/uitest/src/com/vaadin/tests/push/BasicPush.java index d1a9fb575f..d6c45a2ed0 100644 --- a/uitest/src/com/vaadin/tests/push/BasicPush.java +++ b/uitest/src/com/vaadin/tests/push/BasicPush.java @@ -18,16 +18,11 @@ package com.vaadin.tests.push; import java.util.Timer; import java.util.TimerTask; -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.WebElement; - import com.vaadin.annotations.Push; import com.vaadin.data.util.ObjectProperty; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Label; @@ -35,76 +30,6 @@ import com.vaadin.ui.Label; @Push public class BasicPush extends AbstractTestUI { - public static abstract class BasicPushTest extends MultiBrowserTest { - - @Test - public void testPush() { - openTestURL(); - - // Test client initiated push - Assert.assertEquals(0, getClientCounter()); - getIncrementButton().click(); - Assert.assertEquals( - "Client counter not incremented by button click", 1, - getClientCounter()); - getIncrementButton().click(); - getIncrementButton().click(); - getIncrementButton().click(); - Assert.assertEquals( - "Four clicks should have incremented counter to 4", 4, - getClientCounter()); - - // Test server initiated push - getServerCounterStartButton().click(); - try { - Assert.assertEquals(0, getServerCounter()); - sleep(3000); - int serverCounter = getServerCounter(); - if (serverCounter < 1) { - // No push has happened - Assert.fail("No push has occured within 3s"); - } - sleep(3000); - if (getServerCounter() <= serverCounter) { - // No push has happened - Assert.fail("Only one push took place within 6s"); - - } - } finally { - // Avoid triggering push assertions - getServerCounterStopButton().click(); - } - } - - private int getServerCounter() { - return Integer.parseInt(getServerCounterElement().getText()); - } - - private int getClientCounter() { - return Integer.parseInt(getClientCounterElement().getText()); - } - - private WebElement getServerCounterElement() { - return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]"); - } - - private WebElement getServerCounterStartButton() { - return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]"); - } - - private WebElement getServerCounterStopButton() { - return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[6]/VButton[0]/domChild[0]/domChild[0]"); - } - - private WebElement getIncrementButton() { - return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]"); - } - - private WebElement getClientCounterElement() { - return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]"); - } - } - private ObjectProperty<Integer> counter = new ObjectProperty<Integer>(0); private ObjectProperty<Integer> counter2 = new ObjectProperty<Integer>(0); diff --git a/uitest/src/com/vaadin/tests/push/BasicPushStreaming.java b/uitest/src/com/vaadin/tests/push/BasicPushStreaming.java index b63f782cc9..f9dc78dd43 100644 --- a/uitest/src/com/vaadin/tests/push/BasicPushStreaming.java +++ b/uitest/src/com/vaadin/tests/push/BasicPushStreaming.java @@ -28,7 +28,4 @@ public class BasicPushStreaming extends BasicPush { getPushConfiguration().setFallbackTransport(Transport.STREAMING); } - - public static class BasicPushStreamingTest extends BasicPushTest { - } } diff --git a/uitest/src/com/vaadin/tests/push/BasicPushStreamingTest.java b/uitest/src/com/vaadin/tests/push/BasicPushStreamingTest.java new file mode 100644 index 0000000000..67730f72c8 --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/BasicPushStreamingTest.java @@ -0,0 +1,19 @@ +/* + * 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; + +public class BasicPushStreamingTest extends BasicPushTest { +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/push/BasicPushTest.java b/uitest/src/com/vaadin/tests/push/BasicPushTest.java new file mode 100644 index 0000000000..57af8524bc --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/BasicPushTest.java @@ -0,0 +1,92 @@ +/* + * 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 org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public abstract class BasicPushTest extends MultiBrowserTest { + + @Test + public void testPush() { + openTestURL(); + + // Test client initiated push + Assert.assertEquals(0, getClientCounter()); + getIncrementButton().click(); + Assert.assertEquals( + "Client counter not incremented by button click", 1, + getClientCounter()); + getIncrementButton().click(); + getIncrementButton().click(); + getIncrementButton().click(); + Assert.assertEquals( + "Four clicks should have incremented counter to 4", 4, + getClientCounter()); + + // Test server initiated push + getServerCounterStartButton().click(); + try { + Assert.assertEquals(0, getServerCounter()); + sleep(3000); + int serverCounter = getServerCounter(); + if (serverCounter < 1) { + // No push has happened + Assert.fail("No push has occured within 3s"); + } + sleep(3000); + if (getServerCounter() <= serverCounter) { + // No push has happened + Assert.fail("Only one push took place within 6s"); + + } + } finally { + // Avoid triggering push assertions + getServerCounterStopButton().click(); + } + } + + private int getServerCounter() { + return Integer.parseInt(getServerCounterElement().getText()); + } + + private int getClientCounter() { + return Integer.parseInt(getClientCounterElement().getText()); + } + + private WebElement getServerCounterElement() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]"); + } + + private WebElement getServerCounterStartButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]"); + } + + private WebElement getServerCounterStopButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[6]/VButton[0]/domChild[0]/domChild[0]"); + } + + private WebElement getIncrementButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]"); + } + + private WebElement getClientCounterElement() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]"); + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/push/BasicPushWebsocket.java b/uitest/src/com/vaadin/tests/push/BasicPushWebsocket.java index 4765183fca..96793a90f8 100644 --- a/uitest/src/com/vaadin/tests/push/BasicPushWebsocket.java +++ b/uitest/src/com/vaadin/tests/push/BasicPushWebsocket.java @@ -15,14 +15,9 @@ */ package com.vaadin.tests.push; -import java.util.Collection; - -import org.openqa.selenium.remote.DesiredCapabilities; - import com.vaadin.annotations.Push; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.ui.Transport; -import com.vaadin.tests.tb3.WebsocketTest; @Push(transport = Transport.WEBSOCKET) public class BasicPushWebsocket extends BasicPush { @@ -34,11 +29,4 @@ public class BasicPushWebsocket extends BasicPush { getPushConfiguration().setFallbackTransport(Transport.WEBSOCKET); } - public static class BasicPushWebsocketTest extends BasicPushTest { - @Override - public Collection<DesiredCapabilities> getBrowsersToTest() { - return WebsocketTest.getWebsocketBrowsers(); - } - } - } diff --git a/uitest/src/com/vaadin/tests/push/BasicPushWebsocketTest.java b/uitest/src/com/vaadin/tests/push/BasicPushWebsocketTest.java new file mode 100644 index 0000000000..ae4e64ad6b --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/BasicPushWebsocketTest.java @@ -0,0 +1,29 @@ +/* + * 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 java.util.Collection; + +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.tests.tb3.WebsocketTest; + +public class BasicPushWebsocketTest extends BasicPushTest { + @Override + public Collection<DesiredCapabilities> getBrowsersToTest() { + return WebsocketTest.getWebsocketBrowsers(); + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/push/PushConfiguration.java b/uitest/src/com/vaadin/tests/push/PushConfiguration.java new file mode 100644 index 0000000000..a7ba4e43ba --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/PushConfiguration.java @@ -0,0 +1,117 @@ +/* + * 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 java.util.Date; +import java.util.Timer; +import java.util.TimerTask; + +import com.vaadin.data.util.ObjectProperty; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Label; + +public class PushConfiguration extends AbstractTestUI { + + private ObjectProperty<Integer> counter = new ObjectProperty<Integer>(0); + + private ObjectProperty<Integer> counter2 = new ObjectProperty<Integer>(0); + + private final Timer timer = new Timer(true); + + private final TimerTask task = new TimerTask() { + + @Override + public void run() { + access(new Runnable() { + @Override + public void run() { + counter2.setValue(counter2.getValue() + 1); + } + }); + } + }; + + @Override + protected void setup(VaadinRequest request) { + addComponent(new PushConfigurator(this)); + spacer(); + + /* + * Client initiated push. + */ + Label lbl = new Label(counter); + lbl.setCaption("Client counter (click 'increment' to update):"); + addComponent(lbl); + + addComponent(new Button("Increment", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + counter.setValue(counter.getValue() + 1); + } + })); + + spacer(); + + /* + * Server initiated push. + */ + lbl = new Label(counter2); + lbl.setCaption("Server counter (updates each 1s by server thread) :"); + addComponent(lbl); + + addComponent(new Button("Reset", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + counter2.setValue(0); + } + })); + } + + @Override + protected String getTestDescription() { + return "This test tests the very basic operations of push. " + + "It tests that client initiated changes are " + + "recieved back to the client as well as server " + + "initiated changes are correctly updated to the client."; + } + + @Override + protected Integer getTicketNumber() { + return 11494; + } + + private void spacer() { + addComponent(new Label("<hr/>", ContentMode.HTML)); + } + + @Override + public void attach() { + super.attach(); + timer.scheduleAtFixedRate(task, new Date(), 1000); + } + + @Override + public void detach() { + super.detach(); + timer.cancel(); + } +} diff --git a/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java b/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java index 5100e8a4ea..d23c48e14a 100644 --- a/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java +++ b/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java @@ -15,198 +15,98 @@ */ package com.vaadin.tests.push; -import java.util.Date; -import java.util.Timer; -import java.util.TimerTask; - import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.Select; -import com.vaadin.data.util.ObjectProperty; -import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.ui.label.ContentMode; -import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.tb3.WebsocketTest; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Label; - -public class PushConfigurationTest extends AbstractTestUI { - - public static class PushConfigurationWebsocket extends WebsocketTest { - - @Test - public void testWebsocketAndStreaming() { - setDebug(true); - openTestURL(); - // Websocket - Assert.assertEquals(1, getServerCounter()); - 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(); - - 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.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()); - Assert.assertEquals(1, getServerCounter()); - - 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) { - } +public class PushConfigurationTest extends WebsocketTest { + + @Test + public void testWebsocketAndStreaming() { + setDebug(true); + openTestURL(); + // Websocket + Assert.assertEquals(1, getServerCounter()); + 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(); + + 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")); - - } - - private 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() { - 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() { - return Integer.parseInt(getServerCounterElement().getText()); - } - - private WebElement getServerCounterElement() { - return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]"); - } - } - - private ObjectProperty<Integer> counter = new ObjectProperty<Integer>(0); - - private ObjectProperty<Integer> counter2 = new ObjectProperty<Integer>(0); - - private final Timer timer = new Timer(true); - - private final TimerTask task = new TimerTask() { - - @Override - public void run() { - access(new Runnable() { - @Override - public void run() { - counter2.setValue(counter2.getValue() + 1); - } - }); } - }; - - @Override - protected void setup(VaadinRequest request) { - addComponent(new PushConfigurator(this)); - spacer(); - - /* - * Client initiated push. - */ - Label lbl = new Label(counter); - lbl.setCaption("Client counter (click 'increment' to update):"); - addComponent(lbl); - - addComponent(new Button("Increment", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - counter.setValue(counter.getValue() + 1); + // 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()); + Assert.assertEquals(1, getServerCounter()); + + 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"); } - })); - - spacer(); - - /* - * Server initiated push. - */ - lbl = new Label(counter2); - lbl.setCaption("Server counter (updates each 1s by server thread) :"); - addComponent(lbl); - - addComponent(new Button("Reset", new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - counter2.setValue(0); + 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 - protected String getTestDescription() { - return "This test tests the very basic operations of push. " - + "It tests that client initiated changes are " - + "recieved back to the client as well as server " - + "initiated changes are correctly updated to the client."; } - @Override - protected Integer getTicketNumber() { - return 11494; + private 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 void spacer() { - addComponent(new Label("<hr/>", ContentMode.HTML)); + private WebElement getTransportSelect() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[1]/VNativeSelect[0]/domChild[0]"); } - @Override - public void attach() { - super.attach(); - timer.scheduleAtFixedRate(task, new Date(), 1000); + private int getServerCounter() { + return Integer.parseInt(getServerCounterElement().getText()); } - @Override - public void detach() { - super.detach(); - timer.cancel(); + private WebElement getServerCounterElement() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]"); } -} +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/push/PushFromInit.java b/uitest/src/com/vaadin/tests/push/PushFromInit.java index de3334f707..cb084f1232 100644 --- a/uitest/src/com/vaadin/tests/push/PushFromInit.java +++ b/uitest/src/com/vaadin/tests/push/PushFromInit.java @@ -15,45 +15,12 @@ */ package com.vaadin.tests.push; -import org.junit.Assert; -import org.junit.Test; - import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.Button; public class PushFromInit extends AbstractTestUIWithLog { - public static class PushFromInitTB3 extends MultiBrowserTest { - @Test - public void testPushFromInit() { - openTestURL(); - - for (int second = 0;; second++) { - if (second >= 30) { - Assert.fail("timeout"); - } - try { - if ("1. Logged in init".equals(vaadinElementById( - "Log_row_1").getText())) { - break; - } - } catch (Exception e) { - } - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } - } - - Assert.assertEquals( - "2. Logged from background thread started in init", - vaadinElementById("Log_row_0").getText()); - - } - } - @Override protected void setup(VaadinRequest request) { new Thread() { diff --git a/uitest/src/com/vaadin/tests/push/PushFromInitTest.java b/uitest/src/com/vaadin/tests/push/PushFromInitTest.java new file mode 100644 index 0000000000..3c1bc1b610 --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/PushFromInitTest.java @@ -0,0 +1,50 @@ +/* + * 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 org.junit.Assert; +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class PushFromInitTest extends MultiBrowserTest { + @Test + public void testPushFromInit() { + openTestURL(); + + for (int second = 0;; second++) { + if (second >= 30) { + Assert.fail("timeout"); + } + try { + if ("1. Logged in init".equals(vaadinElementById( + "Log_row_1").getText())) { + break; + } + } catch (Exception e) { + } + try { + Thread.sleep(200); + } catch (InterruptedException e) { + } + } + + Assert.assertEquals( + "2. Logged from background thread started in init", + vaadinElementById("Log_row_0").getText()); + + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/push/PushReattachedComponent.java b/uitest/src/com/vaadin/tests/push/PushReattachedComponent.java deleted file mode 100644 index 0bc796e0ee..0000000000 --- a/uitest/src/com/vaadin/tests/push/PushReattachedComponent.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 org.junit.Assert; -import org.junit.Test; - -import com.vaadin.tests.components.panel.PanelChangeContents; -import com.vaadin.tests.tb3.MultiBrowserTest; - -public class PushReattachedComponent extends MultiBrowserTest { - - @Override - protected Class<?> getUIClass() { - return PanelChangeContents.class; - } - - @Test - public void testReattachComponentUsingPush() { - setPush(true); - openTestURL(); - - Assert.assertEquals( - "stats", - vaadinElement( - "/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]") - .getText()); - vaadinElement( - "/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]") - .click(); - Assert.assertEquals( - "companies", - vaadinElement( - "/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]") - .getText()); - vaadinElement( - "/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]") - .click(); - Assert.assertEquals( - "stats", - vaadinElement( - "/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]") - .getText()); - - } -} diff --git a/uitest/src/com/vaadin/tests/push/TogglePush.java b/uitest/src/com/vaadin/tests/push/TogglePush.java index 3ef369b408..6ec8903d65 100644 --- a/uitest/src/com/vaadin/tests/push/TogglePush.java +++ b/uitest/src/com/vaadin/tests/push/TogglePush.java @@ -18,112 +18,17 @@ package com.vaadin.tests.push; import java.util.Timer; import java.util.TimerTask; -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.WebElement; - import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.Property.ValueChangeListener; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.communication.PushMode; import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.CheckBox; import com.vaadin.ui.Label; public class TogglePush extends AbstractTestUI { - public static class TogglePushTB3 extends MultiBrowserTest { - - @Test - public void togglePushInInit() { - setPush(true); - String url = getTestUrl(); - - // Open with push disabled - driver.get(addParameter(url, "push=disabled")); - - Assert.assertFalse(getPushToggle().isSelected()); - - getDelayedCounterUpdateButton().click(); - sleep(2000); - Assert.assertEquals("Counter has been updated 0 times", - getCounterText()); - - // Open with push enabled - driver.get(addParameter(url, "push=enabled")); - Assert.assertTrue(getPushToggle().isSelected()); - - getDelayedCounterUpdateButton().click(); - sleep(2000); - Assert.assertEquals("Counter has been updated 1 times", - getCounterText()); - - } - - private String addParameter(String url, String queryParameter) { - if (url.contains("?")) { - return url + "&" + queryParameter; - } else { - return url + "?" + queryParameter; - } - } - - @Test - public void togglePush() { - setPush(true); - openTestURL(); - getDelayedCounterUpdateButton().click(); - sleep(2000); - - // Push is enabled, so text gets updated - Assert.assertEquals("Counter has been updated 1 times", - getCounterText()); - - // Disable push - getPushToggle().click(); - getDelayedCounterUpdateButton().click(); - sleep(2000); - // Push is disabled, so text is not updated - Assert.assertEquals("Counter has been updated 1 times", - getCounterText()); - - getDirectCounterUpdateButton().click(); - // Direct update is visible, and includes previous update - Assert.assertEquals("Counter has been updated 3 times", - getCounterText()); - - // Re-enable push - getPushToggle().click(); - getDelayedCounterUpdateButton().click(); - sleep(2000); - - // Push is enabled again, so text gets updated - Assert.assertEquals("Counter has been updated 4 times", - getCounterText()); - } - - private WebElement getDirectCounterUpdateButton() { - return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]"); - } - - private WebElement getPushToggle() { - return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]"); - } - - private WebElement getDelayedCounterUpdateButton() { - return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]"); - } - - private String getCounterText() { - return vaadinElement( - "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]") - .getText(); - } - - } - private final Label counterLabel = new Label(); private int counter = 0; diff --git a/uitest/src/com/vaadin/tests/push/TogglePushTest.java b/uitest/src/com/vaadin/tests/push/TogglePushTest.java new file mode 100644 index 0000000000..68d6f52b9f --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/TogglePushTest.java @@ -0,0 +1,112 @@ +/* + * 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 org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TogglePushTest extends MultiBrowserTest { + + @Test + public void togglePushInInit() { + setPush(true); + String url = getTestUrl(); + + // Open with push disabled + driver.get(addParameter(url, "push=disabled")); + + Assert.assertFalse(getPushToggle().isSelected()); + + getDelayedCounterUpdateButton().click(); + sleep(2000); + Assert.assertEquals("Counter has been updated 0 times", + getCounterText()); + + // Open with push enabled + driver.get(addParameter(url, "push=enabled")); + Assert.assertTrue(getPushToggle().isSelected()); + + getDelayedCounterUpdateButton().click(); + sleep(2000); + Assert.assertEquals("Counter has been updated 1 times", + getCounterText()); + + } + + private String addParameter(String url, String queryParameter) { + if (url.contains("?")) { + return url + "&" + queryParameter; + } else { + return url + "?" + queryParameter; + } + } + + @Test + public void togglePush() { + setPush(true); + openTestURL(); + getDelayedCounterUpdateButton().click(); + sleep(2000); + + // Push is enabled, so text gets updated + Assert.assertEquals("Counter has been updated 1 times", + getCounterText()); + + // Disable push + getPushToggle().click(); + getDelayedCounterUpdateButton().click(); + sleep(2000); + // Push is disabled, so text is not updated + Assert.assertEquals("Counter has been updated 1 times", + getCounterText()); + + getDirectCounterUpdateButton().click(); + // Direct update is visible, and includes previous update + Assert.assertEquals("Counter has been updated 3 times", + getCounterText()); + + // Re-enable push + getPushToggle().click(); + getDelayedCounterUpdateButton().click(); + sleep(2000); + + // Push is enabled again, so text gets updated + Assert.assertEquals("Counter has been updated 4 times", + getCounterText()); + } + + private WebElement getDirectCounterUpdateButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]"); + } + + private WebElement getPushToggle() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]"); + } + + private WebElement getDelayedCounterUpdateButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]"); + } + + private String getCounterText() { + return vaadinElement( + "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]") + .getText(); + } + +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/push/TrackMessageSizeUnitTests.java b/uitest/src/com/vaadin/tests/push/TrackMessageSizeUI.java index cb3033aa58..67715339da 100644 --- a/uitest/src/com/vaadin/tests/push/TrackMessageSizeUnitTests.java +++ b/uitest/src/com/vaadin/tests/push/TrackMessageSizeUI.java @@ -25,29 +25,17 @@ import javax.servlet.ServletContext; import org.apache.commons.io.IOUtils; import org.json.JSONArray; import org.json.JSONException; -import org.junit.Assert; -import org.junit.Test; import com.vaadin.annotations.JavaScript; import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinService; import com.vaadin.server.VaadinServletService; import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.JavaScriptFunction; // Load vaadinPush.js so that jQueryVaadin is defined @JavaScript("vaadin://vaadinPush.js") -public class TrackMessageSizeUnitTests extends AbstractTestUIWithLog { - - public static class TrackMessageSizeUnitTestsTB3 extends MultiBrowserTest { - @Test - public void runTests() { - openTestURL(); - Assert.assertEquals("1. All tests run", - vaadinElementById("Log_row_0").getText()); - } - } +public class TrackMessageSizeUI extends AbstractTestUIWithLog { private String testMethod = "function testSequence(expected, data) {\n" + " var request = {trackMessageLength: true, messageDelimiter: '|'};\n" diff --git a/uitest/src/com/vaadin/tests/push/TrackMessageSizeUITest.java b/uitest/src/com/vaadin/tests/push/TrackMessageSizeUITest.java new file mode 100644 index 0000000000..f904675b5e --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/TrackMessageSizeUITest.java @@ -0,0 +1,30 @@ +/* + * 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 org.junit.Assert; +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TrackMessageSizeUITest extends MultiBrowserTest { + @Test + public void runTests() { + openTestURL(); + Assert.assertEquals("1. All tests run", + vaadinElementById("Log_row_0").getText()); + } +}
\ No newline at end of file |