diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-10-10 12:50:13 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2013-10-10 12:50:13 +0300 |
commit | 1f5a4871658ce31bbfb0bb7403a7509b23835782 (patch) | |
tree | f4dbf3fd2cc10c89f686f7c0b75c58b960435c97 | |
parent | 5ab1d95fac5ff5cede39629227b8836ca093df14 (diff) | |
parent | daf06e935ab932e2b9194d35ad81cb36a4911338 (diff) | |
download | vaadin-framework-1f5a4871658ce31bbfb0bb7403a7509b23835782.tar.gz vaadin-framework-1f5a4871658ce31bbfb0bb7403a7509b23835782.zip |
Merge changes from origin/7.1
503e575 Fix NullPointerException in logger when message is null (#12588)
d9f6dad Fixed Table range selection IE regression #12407
6453055 Run tests on Tomcat 8 (#12326)
10bcbdc Actually open integration test.
3cba6bf Rebuild OptionGroup on HtmlContentAllowed/Multiselect changes (#10451)
4f3cc4c Converted push test to TB3 (#12226, #12522)
281fc43 Fixed incorrect logging (#12241)
63e16e6 Mark as deprecated to discourage usage for new tests
f488825 Update TB3+ convention to use a separate *Test file
5fb877b Makes test stable and adds helper comparison methods
daf06e9 Use class name and not enclosing class for screenshot name
Change-Id: Ie4557c2003f9cbc121cf287cf6f41bc5eaefe929
39 files changed, 1053 insertions, 695 deletions
diff --git a/client/src/com/vaadin/client/VConsole.java b/client/src/com/vaadin/client/VConsole.java index 37ed8e6370..32eb206a70 100644 --- a/client/src/com/vaadin/client/VConsole.java +++ b/client/src/com/vaadin/client/VConsole.java @@ -41,25 +41,35 @@ public class VConsole { public static void log(String msg) { if (LogConfiguration.loggingIsEnabled(Level.INFO)) { - getLogger().log(Level.INFO, msg); + // Check for null, so no NullPointerException is generated when + // formatting (#12588) + getLogger().log(Level.INFO, msg == null ? "null" : msg); } } public static void log(Throwable e) { if (LogConfiguration.loggingIsEnabled(Level.INFO)) { - getLogger().log(Level.INFO, e.getMessage(), e); + // Check for null, so no NullPointerException is generated when + // formatting (#12588) + getLogger().log(Level.INFO, + e.getMessage() == null ? "" : e.getMessage(), e); } } public static void error(Throwable e) { if (LogConfiguration.loggingIsEnabled(Level.SEVERE)) { - getLogger().log(Level.SEVERE, e.getMessage(), e); + // Check for null, so no NullPointerException is generated when + // formatting (#12588) + getLogger().log(Level.SEVERE, + e.getMessage() == null ? "" : e.getMessage(), e); } } public static void error(String msg) { if (LogConfiguration.loggingIsEnabled(Level.SEVERE)) { - getLogger().log(Level.SEVERE, msg); + // Check for null, so no NullPointerException is generated when + // formatting (#12588) + getLogger().log(Level.SEVERE, msg == null ? "null" : msg); } } diff --git a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java index ccb01c5a30..acca80f02b 100644 --- a/client/src/com/vaadin/client/communication/AtmospherePushConnection.java +++ b/client/src/com/vaadin/client/communication/AtmospherePushConnection.java @@ -225,12 +225,14 @@ public class AtmospherePushConnection implements PushConnection { } protected void onReopen(AtmosphereResponse response) { - VConsole.log("Push connection re-established using " + transport); + VConsole.log("Push connection re-established using " + + response.getTransport()); onConnect(response); } protected void onOpen(AtmosphereResponse response) { - VConsole.log("Push connection established using " + transport); + VConsole.log("Push connection established using " + + response.getTransport()); onConnect(response); } diff --git a/client/src/com/vaadin/client/debug/internal/LogSection.java b/client/src/com/vaadin/client/debug/internal/LogSection.java index 1e7524b56d..f792ec95be 100644 --- a/client/src/com/vaadin/client/debug/internal/LogSection.java +++ b/client/src/com/vaadin/client/debug/internal/LogSection.java @@ -73,6 +73,12 @@ public class LogSection implements Section { return; } + // If no message is provided, record.getMessage will be null and so + // the formatter.format will fail with NullPointerException (#12588) + if (record.getMessage() == null) { + record.setMessage(""); + } + Formatter formatter = getFormatter(); String msg = formatter.format(record); diff --git a/client/src/com/vaadin/client/ui/VOptionGroup.java b/client/src/com/vaadin/client/ui/VOptionGroup.java index 455c7669f5..fee1c313f5 100644 --- a/client/src/com/vaadin/client/ui/VOptionGroup.java +++ b/client/src/com/vaadin/client/ui/VOptionGroup.java @@ -87,11 +87,16 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, /** For internal use only. May be removed or replaced in the future. */ public boolean htmlContentAllowed = false; + private boolean wasHtmlContentAllowed = false; + private boolean wasMultiselect = false; + public VOptionGroup() { super(CLASSNAME); panel = (Panel) optionsContainer; optionsToKeys = new HashMap<CheckBox, String>(); optionsEnabled = new ArrayList<Boolean>(); + + wasMultiselect = isMultiselect(); } /* @@ -143,7 +148,11 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, String key = opUidl.getStringAttribute("key"); CheckBox op = keysToOptions.get(key); - if (op == null) { + + // Need to recreate object if isMultiselect is changed (#10451) + // OR if htmlContentAllowed changed due to Safari 5 issue + if ((op == null) || (htmlContentAllowed != wasHtmlContentAllowed) + || (isMultiselect() != wasMultiselect)) { // Create a new element if (isMultiselect()) { op = new VCheckBox(); @@ -184,6 +193,9 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, panel.add(wid); } } + + wasHtmlContentAllowed = htmlContentAllowed; + wasMultiselect = isMultiselect(); } @Override diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 6b2893f2bb..ea724ea034 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -6123,7 +6123,13 @@ public class VScrollTable extends FlowPanel implements HasWidgets, .next(); setRowFocus(endRow); } + } else if (!startRow.isSelected()) { + // The start row is no longer selected (probably removed) + // and so we select from above + startRow = (VScrollTableRow) scrollBody.iterator().next(); + setRowFocus(endRow); } + // Deselect previous items if so desired if (deselectPrevious) { deselectAll(); diff --git a/uitest/integration_tests.xml b/uitest/integration_tests.xml index f1b2070bc8..1c9c2b1f8f 100644 --- a/uitest/integration_tests.xml +++ b/uitest/integration_tests.xml @@ -124,6 +124,12 @@ <param name="target-server" value="tomcat7" /> </antcall> </target> + <target name="integration-test-tomcat8"> + <antcall target="run-generic-integration-test"> + <param name="startDelay" value="10" /> + <param name="target-server" value="tomcat8" /> + </antcall> + </target> <target name="integration-test-tomcat5"> <antcall target="run-generic-integration-test"> <param name="startDelay" value="10" /> @@ -397,6 +403,7 @@ <antcall target="integration-test-tomcat5" /> <antcall target="integration-test-tomcat6" /> <antcall target="integration-test-tomcat7" /> + <antcall target="integration-test-tomcat8" /> <antcall target="integration-test-websphere8" /> </parallel> diff --git a/uitest/src/com/vaadin/tests/VerifyBrowserVersion.java b/uitest/src/com/vaadin/tests/VerifyBrowserVersion.java index 47c09bdfd7..1b21f08aa7 100644 --- a/uitest/src/com/vaadin/tests/VerifyBrowserVersion.java +++ b/uitest/src/com/vaadin/tests/VerifyBrowserVersion.java @@ -1,59 +1,11 @@ package com.vaadin.tests; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.remote.DesiredCapabilities; - import com.vaadin.server.WebBrowser; import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.Label; public class VerifyBrowserVersion extends TestBase { - public static class BrowserVersionTest extends MultiBrowserTest { - - private Map<DesiredCapabilities, String> expectedUserAgent = new HashMap<DesiredCapabilities, String>(); - - { - expectedUserAgent - .put(BrowserUtil.firefox(24), - "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"); - expectedUserAgent - .put(BrowserUtil.ie(8), - "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"); - expectedUserAgent - .put(BrowserUtil.ie(9), - "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"); - expectedUserAgent - .put(BrowserUtil.ie(10), - "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"); - expectedUserAgent - .put(BrowserUtil.ie(11), - "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"); - expectedUserAgent - .put(BrowserUtil.chrome(29), - "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36"); - expectedUserAgent - .put(BrowserUtil.opera(12), - "Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.15"); - - } - - @Test - public void verifyUserAgent() { - openTestURL(); - Assert.assertEquals( - expectedUserAgent.get(getDesiredCapabilities()), - vaadinElementById("userAgent").getText()); - Assert.assertEquals("Touch device? No", - vaadinElementById("touchDevice").getText()); - } - } - @Override protected void setup() { WebBrowser browser = getBrowser(); diff --git a/uitest/src/com/vaadin/tests/VerifyBrowserVersionTest.java b/uitest/src/com/vaadin/tests/VerifyBrowserVersionTest.java new file mode 100644 index 0000000000..6704f55226 --- /dev/null +++ b/uitest/src/com/vaadin/tests/VerifyBrowserVersionTest.java @@ -0,0 +1,66 @@ +/* + * 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; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.tb3.AbstractTB3Test.BrowserUtil; + +public class VerifyBrowserVersionTest extends MultiBrowserTest { + + private Map<DesiredCapabilities, String> expectedUserAgent = new HashMap<DesiredCapabilities, String>(); + + { + expectedUserAgent + .put(BrowserUtil.firefox(24), + "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"); + expectedUserAgent + .put(BrowserUtil.ie(8), + "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"); + expectedUserAgent + .put(BrowserUtil.ie(9), + "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"); + expectedUserAgent + .put(BrowserUtil.ie(10), + "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"); + expectedUserAgent + .put(BrowserUtil.ie(11), + "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"); + expectedUserAgent + .put(BrowserUtil.chrome(29), + "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36"); + expectedUserAgent + .put(BrowserUtil.opera(12), + "Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.15"); + + } + + @Test + public void verifyUserAgent() { + openTestURL(); + Assert.assertEquals( + expectedUserAgent.get(getDesiredCapabilities()), + vaadinElementById("userAgent").getText()); + Assert.assertEquals("Touch device? No", + vaadinElementById("touchDevice").getText()); + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/label/LabelModes.java b/uitest/src/com/vaadin/tests/components/label/LabelModes.java index 9e51978743..e5bc539f36 100644 --- a/uitest/src/com/vaadin/tests/components/label/LabelModes.java +++ b/uitest/src/com/vaadin/tests/components/label/LabelModes.java @@ -2,20 +2,10 @@ package com.vaadin.tests.components.label; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.tests.components.ComponentTestCase; -import com.vaadin.tests.tb3.SimpleMultiBrowserTest; import com.vaadin.ui.Label; public class LabelModes extends ComponentTestCase<Label> { - public static class LabelModesTest extends SimpleMultiBrowserTest { - @Override - public void test() throws Exception { - openTestURL(); - compareScreen("labelmodes"); - } - - } - @Override protected Class<Label> getTestClass() { return Label.class; diff --git a/uitest/src/com/vaadin/tests/components/label/LabelModesTest.java b/uitest/src/com/vaadin/tests/components/label/LabelModesTest.java new file mode 100644 index 0000000000..efad615510 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/label/LabelModesTest.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.components.label; + +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class LabelModesTest extends MultiBrowserTest { + + @Test + public void testLabelModes() throws Exception { + openTestURL(); + compareScreen("labelmodes"); + } + +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutFullsizeContentWithErrorMsg.java b/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutFullsizeContentWithErrorMsg.java index 25675e07c5..030bfa693e 100644 --- a/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutFullsizeContentWithErrorMsg.java +++ b/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutFullsizeContentWithErrorMsg.java @@ -1,15 +1,8 @@ package com.vaadin.tests.components.orderedlayout; -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Point; -import org.openqa.selenium.WebElement; - import com.vaadin.server.UserError; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; @@ -19,8 +12,8 @@ import com.vaadin.ui.TextField; public class HorizontalLayoutFullsizeContentWithErrorMsg extends AbstractTestUI { - private static final String FIELD_ID = "f"; - private static final String BUTTON_ID = "b"; + static final String FIELD_ID = "f"; + static final String BUTTON_ID = "b"; private TextField tf; @Override @@ -70,27 +63,4 @@ public class HorizontalLayoutFullsizeContentWithErrorMsg extends AbstractTestUI return "TextField should remain at same level vertically, horizontally width should adjust to fit error indicator."; } - public static class TbTest extends MultiBrowserTest { - - @Test - public void test() { - openTestURL(); - WebElement element = getDriver().findElement(By.id(FIELD_ID)); - Point location = element.getLocation(); - - WebElement errorToggleButton = getDriver().findElement( - By.id(BUTTON_ID)); - - errorToggleButton.click(); - - Assert.assertEquals(location, element.getLocation()); - - errorToggleButton.click(); - - Assert.assertEquals(location, element.getLocation()); - - } - - } - } diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutFullsizeContentWithErrorMsgTest.java b/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutFullsizeContentWithErrorMsgTest.java new file mode 100644 index 0000000000..24ebf24688 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutFullsizeContentWithErrorMsgTest.java @@ -0,0 +1,49 @@ +/* + * 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.components.orderedlayout; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Point; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class HorizontalLayoutFullsizeContentWithErrorMsgTest extends + MultiBrowserTest { + + @Test + public void test() { + openTestURL(); + WebElement element = getDriver().findElement( + By.id(HorizontalLayoutFullsizeContentWithErrorMsg.FIELD_ID)); + Point location = element.getLocation(); + + WebElement errorToggleButton = getDriver().findElement( + By.id(HorizontalLayoutFullsizeContentWithErrorMsg.BUTTON_ID)); + + errorToggleButton.click(); + + Assert.assertEquals(location, element.getLocation()); + + errorToggleButton.click(); + + Assert.assertEquals(location, element.getLocation()); + + } + +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/push/PushReattachedComponent.java b/uitest/src/com/vaadin/tests/components/panel/PanelChangeContentsTest.java index 0bc796e0ee..5bc505dbc8 100644 --- a/uitest/src/com/vaadin/tests/push/PushReattachedComponent.java +++ b/uitest/src/com/vaadin/tests/components/panel/PanelChangeContentsTest.java @@ -13,24 +13,14 @@ * License for the specific language governing permissions and limitations under * the License. */ - -/** - * - */ -package com.vaadin.tests.push; +package com.vaadin.tests.components.panel; 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; - } +public class PanelChangeContentsTest extends MultiBrowserTest { @Test public void testReattachComponentUsingPush() { diff --git a/uitest/src/com/vaadin/tests/components/slider/SliderDisable.java b/uitest/src/com/vaadin/tests/components/slider/SliderDisable.java index ea29a1657c..bd1d175119 100644 --- a/uitest/src/com/vaadin/tests/components/slider/SliderDisable.java +++ b/uitest/src/com/vaadin/tests/components/slider/SliderDisable.java @@ -15,15 +15,8 @@ */ package com.vaadin.tests.components.slider; -import java.io.IOException; - -import org.junit.Test; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - import com.vaadin.server.VaadinRequest; 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.Button.ClickListener; @@ -32,18 +25,6 @@ import com.vaadin.ui.VerticalLayout; public class SliderDisable extends AbstractTestUI { - public static class SliderDisableTest extends MultiBrowserTest { - @Test - public void disableSlider() throws IOException { - openTestURL(); - WebElement element = vaadinElement("/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]"); - new Actions(driver).dragAndDropBy(element, 112, 0).perform(); - compareScreen("enabled"); - vaadinElementById("disableButton").click(); - compareScreen("disabled"); - } - } - @Override protected void setup(VaadinRequest request) { VerticalLayout content = new VerticalLayout(); diff --git a/uitest/src/com/vaadin/tests/components/slider/SliderDisableTest.java b/uitest/src/com/vaadin/tests/components/slider/SliderDisableTest.java new file mode 100644 index 0000000000..f6ec3dac3b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/slider/SliderDisableTest.java @@ -0,0 +1,36 @@ +/* + * 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.components.slider; + +import java.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class SliderDisableTest extends MultiBrowserTest { + @Test + public void disableSlider() throws IOException { + openTestURL(); + WebElement element = vaadinElement("/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]"); + new Actions(driver).dragAndDropBy(element, 112, 0).perform(); + compareScreen("enabled"); + vaadinElementById("disableButton").click(); + compareScreen("disabled"); + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/ui/UIAccess.java b/uitest/src/com/vaadin/tests/components/ui/UIAccess.java index 7515b3ede8..d036827159 100644 --- a/uitest/src/com/vaadin/tests/components/ui/UIAccess.java +++ b/uitest/src/com/vaadin/tests/components/ui/UIAccess.java @@ -21,17 +21,11 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.locks.ReentrantLock; -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.ExpectedConditions; - import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinService; import com.vaadin.server.VaadinSession; import com.vaadin.shared.communication.PushMode; import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.UI; @@ -39,28 +33,6 @@ import com.vaadin.util.CurrentInstance; public class UIAccess extends AbstractTestUIWithLog { - public static class UIAccessTest extends MultiBrowserTest { - @Test - public void testThreadLocals() { - setPush(true); - openTestURL(); - getCurrentInstanceWhenPushingButton().click(); - waitUntil(ExpectedConditions.textToBePresentInElement( - vaadinLocatorById("Log_row_0"), "1.")); - Assert.assertEquals( - "0. Current UI matches in beforeResponse? true", - vaadinElementById("Log_row_1").getText()); - Assert.assertEquals( - "1. Current session matches in beforeResponse? true", - vaadinElementById("Log_row_0").getText()); - - } - - private WebElement getCurrentInstanceWhenPushingButton() { - return vaadinElement("/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[7]/VButton[0]"); - } - } - private volatile boolean checkCurrentInstancesBeforeResponse = false; private Future<Void> checkFromBeforeClientResponse; diff --git a/uitest/src/com/vaadin/tests/components/ui/UIAccessTest.java b/uitest/src/com/vaadin/tests/components/ui/UIAccessTest.java new file mode 100644 index 0000000000..8d04ceae71 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UIAccessTest.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.components.ui; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UIAccessTest extends MultiBrowserTest { + @Test + public void testThreadLocals() { + setPush(true); + openTestURL(); + getCurrentInstanceWhenPushingButton().click(); + waitUntil(ExpectedConditions.textToBePresentInElement( + vaadinLocatorById("Log_row_0"), "1.")); + Assert.assertEquals( + "0. Current UI matches in beforeResponse? true", + vaadinElementById("Log_row_1").getText()); + Assert.assertEquals( + "1. Current session matches in beforeResponse? true", + vaadinElementById("Log_row_0").getText()); + + } + + private WebElement getCurrentInstanceWhenPushingButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[7]/VButton[0]"); + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/integration/ServletIntegrationTestTB3.java b/uitest/src/com/vaadin/tests/integration/ServletIntegrationTestTB3.java index ae83083d85..2a2f8ab3d1 100644 --- a/uitest/src/com/vaadin/tests/integration/ServletIntegrationTestTB3.java +++ b/uitest/src/com/vaadin/tests/integration/ServletIntegrationTestTB3.java @@ -31,6 +31,7 @@ public abstract class ServletIntegrationTestTB3 extends @Test public void runTest() throws IOException, AssertionError { + openTestURL(); compareScreen("initial"); WebElement cell = vaadinElement(getTableCell(getTable(), 0, 1)); 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/EnableDisablePush.html b/uitest/src/com/vaadin/tests/push/EnableDisablePush.html deleted file mode 100644 index 87dfa8428f..0000000000 --- a/uitest/src/com/vaadin/tests/push/EnableDisablePush.html +++ /dev/null @@ -1,97 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="" /> -<title>EnableDisablePush</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">EnableDisablePush</td></tr> -</thead><tbody> -<tr> - <td>open</td> - <td>/run/EnableDisablePush?restartApplication</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runEnableDisablePush::PID_SLog_row_0</td> - <td>1. Push enabled</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runEnableDisablePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runEnableDisablePush::PID_SLog_row_0</td> - <td>3. Push disabled</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runEnableDisablePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runEnableDisablePush::PID_SLog_row_0</td> - <td>5. Poll enabled</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runEnableDisablePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runEnableDisablePush::PID_SLog_row_0</td> - <td>7. Push enabled</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runEnableDisablePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runEnableDisablePush::PID_SLog_row_0</td> - <td>9. Poll disabled</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runEnableDisablePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runEnableDisablePush::PID_SLog_row_0</td> - <td>11. Push disabled, polling enabled</td> -</tr> -<tr> - <td>pause</td> - <td>3500</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runEnableDisablePush::PID_SLog_row_0</td> - <td>16. Polling disabled, push enabled</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runEnableDisablePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runEnableDisablePush::PID_SLog_row_0</td> - <td>18. Push disabled</td> -</tr> - -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/push/EnableDisablePush.java b/uitest/src/com/vaadin/tests/push/EnableDisablePush.java index 1911c66c2d..50dab43667 100644 --- a/uitest/src/com/vaadin/tests/push/EnableDisablePush.java +++ b/uitest/src/com/vaadin/tests/push/EnableDisablePush.java @@ -1,19 +1,74 @@ package com.vaadin.tests.push; +import static org.junit.Assert.assertEquals; + import java.util.Date; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.TimeUnit; +import org.junit.Test; +import org.openqa.selenium.WebElement; + 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.tests.util.Log; import com.vaadin.ui.Button; import com.vaadin.ui.UIDetachedException; public class EnableDisablePush extends AbstractTestUI { + public static class EnableDisablePushTest extends MultiBrowserTest { + @Test + public void testEnablePushWhenUsingPolling() throws Exception { + openTestURL(); + + assertEquals("1. Push enabled", getLogRow(0)); + + getDisablePushButton().click(); + assertEquals("3. Push disabled", getLogRow(0)); + + getEnablePollButton().click(); + assertEquals("5. Poll enabled", getLogRow(0)); + + getEnablePushButton().click(); + assertEquals("7. Push enabled", getLogRow(0)); + + getDisablePollButton().click(); + assertEquals("9. Poll disabled", getLogRow(0)); + + getDisablePushButtonAndReenableFromBackground().click(); + Thread.sleep(2500); + assertEquals("16. Polling disabled, push enabled", getLogRow(0)); + + getDisablePushButton().click(); + assertEquals("18. Push disabled", getLogRow(0)); + } + + private WebElement getDisablePushButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]"); + } + + private WebElement getEnablePushButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VButton[0]"); + } + + private WebElement getDisablePollButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]"); + } + + private WebElement getEnablePollButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]"); + } + + private WebElement getDisablePushButtonAndReenableFromBackground() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VButton[0]"); + } + + } + private int c = 0; private Log log = new Log(15); @@ -27,7 +82,7 @@ public class EnableDisablePush extends AbstractTestUI { try { while (true) { - TimeUnit.MILLISECONDS.sleep(1000); + TimeUnit.MILLISECONDS.sleep(500); access(new Runnable() { @Override @@ -42,6 +97,9 @@ public class EnableDisablePush extends AbstractTestUI { } } }); + if (c == 3) { + return; + } } } catch (InterruptedException e) { } catch (UIDetachedException e) { 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..1f8c4c0e38 100644 --- a/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java +++ b/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java @@ -15,198 +15,97 @@ */ 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.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; 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) { - } - } - - // 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() { +public class PushConfigurationTest extends WebsocketTest { + + @Test + public void testWebsocketAndStreaming() { + setDebug(true); + openTestURL(); + // Websocket + int counter = getServerCounter(); + assertGreaterOrEqual("Counter should be >= 1. Was: " + counter, + counter, 1); + 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]*$")); + counter = getServerCounter(); + final int waitCounter = counter + 2; + waitUntil(new ExpectedCondition<Boolean>() { @Override - public void buttonClick(ClickEvent event) { - counter.setValue(counter.getValue() + 1); + public Boolean apply(WebDriver input) { + return (getServerCounter() >= waitCounter); } - })); - - 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); + }); + + // 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) { + } + } + + // 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/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 diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index 054492444d..38c5b29bf9 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -19,6 +19,7 @@ package com.vaadin.tests.tb3; import java.net.URL; import java.util.Collection; import java.util.Collections; +import java.util.logging.Logger; import org.junit.After; import org.junit.Before; @@ -35,8 +36,10 @@ import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import com.vaadin.server.LegacyApplication; +import com.vaadin.server.UIProvider; import com.vaadin.testbench.TestBench; import com.vaadin.testbench.TestBenchTestCase; +import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.ui.UI; /** @@ -298,6 +301,110 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { } /** + * For tests extending {@link AbstractTestUIWithLog}, returns the element + * for the Nth log row + * + * @param rowNr + * The log row to retrieve + * @return the Nth log row + */ + protected WebElement getLogRowElement(int rowNr) { + return vaadinElementById("Log_row_" + rowNr); + } + + /** + * For tests extending {@link AbstractTestUIWithLog}, returns the text in + * the Nth log row + * + * @param rowNr + * The log row to retrieve text for + * @return the text in the log row + */ + protected String getLogRow(int rowNr) { + return getLogRowElement(rowNr).getText(); + } + + /** + * Asserts that {@literal a} is >= {@literal b} + * + * @param message + * The message to include in the {@link AssertionError} + * @param a + * @param b + * @throws AssertionError + * If comparison fails + */ + public static final <T> void assertGreaterOrEqual(String message, + Comparable<T> a, T b) throws AssertionError { + if (a.compareTo(b) >= 0) { + return; + } + + throw new AssertionError(decorate(message, a, b)); + } + + /** + * Asserts that {@literal a} is > {@literal b} + * + * @param message + * The message to include in the {@link AssertionError} + * @param a + * @param b + * @throws AssertionError + * If comparison fails + */ + public static final <T> void assertGreater(String message, Comparable<T> a, + T b) throws AssertionError { + if (a.compareTo(b) > 0) { + return; + } + throw new AssertionError(decorate(message, a, b)); + } + + /** + * Asserts that {@literal a} is <= {@literal b} + * + * @param message + * The message to include in the {@link AssertionError} + * @param a + * @param b + * @throws AssertionError + * If comparison fails + */ + public static final <T> void assertLessThanOrEqual(String message, + Comparable<T> a, T b) throws AssertionError { + if (a.compareTo(b) <= 0) { + return; + } + + throw new AssertionError(decorate(message, a, b)); + } + + /** + * Asserts that {@literal a} is < {@literal b} + * + * @param message + * The message to include in the {@link AssertionError} + * @param a + * @param b + * @throws AssertionError + * If comparison fails + */ + public static final <T> void assertLessThan(String message, + Comparable<T> a, T b) throws AssertionError { + if (a.compareTo(b) < 0) { + return; + } + throw new AssertionError(decorate(message, a, b)); + } + + private static <T> String decorate(String message, Comparable<T> a, T b) { + message = message.replace("{0}", a.toString()); + message = message.replace("{1}", b.toString()); + return message; + } + + /** * Returns the path that should be used for the test. The path contains the * full path (appended to hostname+port) and must start with a slash. * @@ -319,8 +426,9 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { } /** - * Returns the UI class the current test is connected to. Uses the enclosing - * class if the test class is a static inner class to a UI class. + * Returns the UI class the current test is connected to (or in special + * cases UIProvider or LegacyApplication). Uses the enclosing class if the + * test class is a static inner class to a UI class. * * Test which are not enclosed by a UI class must implement this method and * return the UI class they want to test. @@ -331,11 +439,43 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { * @return the UI class the current test is connected to */ protected Class<?> getUIClass() { + try { + // Convention: SomeUITest uses the SomeUI UI class + String uiClassName = getClass().getName().replaceFirst("Test$", ""); + Class<?> cls = Class.forName(uiClassName); + if (isSupportedRunnerClass(cls)) { + return cls; + } + } catch (Exception e) { + } Class<?> enclosingClass = getClass().getEnclosingClass(); if (enclosingClass != null) { - return enclosingClass; + if (UI.class.isAssignableFrom(enclosingClass)) { + Logger.getLogger(getClass().getName()) + .severe("Test is an static inner class to the UI. This will no longer be supported in the future. The test should be named UIClassTest and reside in the same package as the UI"); + return enclosingClass; + } } - return null; + throw new RuntimeException( + "Could not determine UI class. Ensure the test is named UIClassTest and is in the same package as the UIClass"); + } + + /** + * @return true if the given class is supported by ApplicationServletRunner + */ + @SuppressWarnings("deprecation") + private boolean isSupportedRunnerClass(Class<?> cls) { + if (UI.class.isAssignableFrom(cls)) { + return true; + } + if (UIProvider.class.isAssignableFrom(cls)) { + return true; + } + if (LegacyApplication.class.isAssignableFrom(cls)) { + return true; + } + + return false; } /** diff --git a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java index 94bcebde84..cbdae1a6c1 100644 --- a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java @@ -61,10 +61,6 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test { testMethod = testMethod.replaceAll("\\[.*\\]", ""); String className = testClass.getSimpleName(); - if (testClass.getEnclosingClass() != null) { - className = testClass.getEnclosingClass().getSimpleName(); - } - screenshotBaseName = className + "-" + testMethod; } diff --git a/uitest/src/com/vaadin/tests/tb3/SimpleMultiBrowserTest.java b/uitest/src/com/vaadin/tests/tb3/SimpleMultiBrowserTest.java index a7ade3f9f7..aeeed4198c 100644 --- a/uitest/src/com/vaadin/tests/tb3/SimpleMultiBrowserTest.java +++ b/uitest/src/com/vaadin/tests/tb3/SimpleMultiBrowserTest.java @@ -32,6 +32,7 @@ import org.junit.Test; * * @author Vaadin Ltd */ +@Deprecated public abstract class SimpleMultiBrowserTest extends MultiBrowserTest { @Test |