]> source.dussan.org Git - vaadin-framework.git/commitdiff
Split UIAccessTest into separate test methods.
authorSauli Tähkäpää <sauli@vaadin.com>
Thu, 18 Sep 2014 07:32:57 +0000 (10:32 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 19 Sep 2014 05:43:55 +0000 (05:43 +0000)
Change-Id: I4cc0dd2a97a702cff0506543cc9608ae819f82f8

uitest/src/com/vaadin/tests/components/ui/UIAccess.java
uitest/src/com/vaadin/tests/components/ui/UIAccessTest.java

index 648e3aff8b06ed31ec51127a24f84db558ed2464..70a69ef7d3ef0083ce676f29af7960c36bc563d5 100644 (file)
@@ -168,7 +168,7 @@ public class UIAccess extends AbstractTestUIWithLog {
                             }
                         });
                         future.cancel(false);
-                        log("future was cancled, should not start");
+                        log("future was cancelled, should not start");
                     }
                 }));
         addComponent(new Button("Cancel running future",
index 39d6c12bfcc5326b1592afbe4da3eaabf647f31f..9ecaa053150eb9f21c5f6e9148ca97cde033b6d2 100644 (file)
  */
 package com.vaadin.tests.components.ui;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.junit.Assert;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
 import org.junit.Test;
-import org.openqa.selenium.WebElement;
-import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.ui.ExpectedCondition;
 
-import com.vaadin.testbench.By;
-import com.vaadin.tests.tb3.MultiBrowserTest;
+import static org.junit.Assert.assertTrue;
 
 public class UIAccessTest extends MultiBrowserTest {
+
+    @Override
+    public void setup() throws Exception {
+        super.setup();
+
+        setPush(false);
+        openTestURL();
+    }
+
     @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());
 
+        $(ButtonElement.class).get(7).click();
+
+        waitForLogToContainText("0. Current UI matches in beforeResponse? true");
+        waitForLogToContainText("1. Current session matches in beforeResponse? true");
+    }
+    
+    @Test
+    public void canBeAccessedFromUIThread() {
+        $(ButtonElement.class).first().click();
+
+        assertTrue(logContainsText("0. Access from UI thread future is done? false"));
+        assertTrue(logContainsText("1. Access from UI thread is run"));
+        assertTrue(logContainsText("2. beforeClientResponse future is done? true"));
     }
 
     @Test
-    public void testAccessMethod() throws Exception {
-        openTestURL();
+    public void canBeAccessedFromBackgroundThread() {
+        $(ButtonElement.class).get(1).click();
 
-        vaadinElement(
-                "/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]")
-                .click();
-        driver.findElement(
-                By.vaadin("runcomvaadintestscomponentsuiUIAccess::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]"))
-                .click();
-        assertTrue(driver
-                .findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_2"))
-                .getText()
-                .matches(
-                        "^0\\. Access from UI thread future is done[\\s\\S] false$"));
-        assertEquals(
-                "1. Access from UI thread is run",
-                driver.findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_1"))
-                        .getText());
-        assertTrue(driver
-                .findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_0"))
-                .getText()
-                .matches(
-                        "^2\\. beforeClientResponse future is done[\\s\\S] true$"));
-        driver.findElement(
-                By.vaadin("runcomvaadintestscomponentsuiUIAccess::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]"))
-                .click();
-        assertEquals(
-                "0. Initial background message",
-                driver.findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_1"))
-                        .getText());
-        assertTrue(driver
-                .findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_0"))
-                .getText()
-                .matches("^1\\. Thread has current response[\\s\\S] false$"));
-        for (int second = 0;; second++) {
-            if (second >= 30) {
-                fail("timeout");
-            }
-            try {
-                if ("0. Initial background message"
-                        .equals(driver
-                                .findElement(
-                                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_2"))
-                                .getText())) {
-                    break;
-                }
-            } catch (Exception e) {
+        assertTrue(logContainsText("0. Initial background message"));
+        assertTrue(logContainsText("1. Thread has current response? false"));
+
+        waitForLogToContainText("2. Thread got lock, inital future done? true");
+    }
+
+    private void waitForLogToContainText(final String text) {
+        waitUntil(new ExpectedCondition<Object>() {
+            @Override
+            public Object apply(WebDriver input) {
+                return logContainsText(text);
             }
-            Thread.sleep(1000);
-        }
-
-        assertTrue(driver
-                .findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_0"))
-                .getText()
-                .matches(
-                        "^2\\. Thread got lock, inital future done[\\s\\S] true$"));
-        driver.findElement(
-                By.vaadin("runcomvaadintestscomponentsuiUIAccess::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]"))
-                .click();
-        assertEquals(
-                "0. Throwing exception in access",
-                driver.findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_2"))
-                        .getText());
-        assertTrue(driver
-                .findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_1"))
-                .getText().matches("^1\\. firstFuture is done[\\s\\S] true$"));
-        assertEquals(
-                "2. Got exception from firstFuture: java.lang.RuntimeException: Catch me if you can",
-                driver.findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_0"))
-                        .getText());
-        driver.findElement(
-                By.vaadin("runcomvaadintestscomponentsuiUIAccess::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]"))
-                .click();
-        assertEquals(
-                "0. future was cancled, should not start",
-                driver.findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_0"))
-                        .getText());
-        driver.findElement(
-                By.vaadin("runcomvaadintestscomponentsuiUIAccess::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[4]/VButton[0]/domChild[0]/domChild[0]"))
-                .click();
-        assertEquals(
-                "0. Waiting for thread to start",
-                driver.findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_2"))
-                        .getText());
-        assertEquals(
-                "1. Thread started, waiting for interruption",
-                driver.findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_1"))
-                        .getText());
-        assertEquals(
-                "2. I was interrupted",
-                driver.findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_0"))
-                        .getText());
-        driver.findElement(
-                By.vaadin("runcomvaadintestscomponentsuiUIAccess::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]"))
-                .click();
-        assertTrue(driver
-                .findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_3"))
-                .getText()
-                .matches("^0\\. accessSynchronously has request[\\s\\S] true$"));
-        assertEquals(
-                "1. Test value in accessSynchronously: Set before accessSynchronosly",
-                driver.findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_2"))
-                        .getText());
-        assertTrue(driver
-                .findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_1"))
-                .getText()
-                .matches(
-                        "^2\\. has request after accessSynchronously[\\s\\S] true$"));
-        assertEquals(
-                "3. Test value after accessSynchornously: Set in accessSynchronosly",
-                driver.findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_0"))
-                        .getText());
-        driver.findElement(
-                By.vaadin("runcomvaadintestscomponentsuiUIAccess::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[6]/VButton[0]/domChild[0]/domChild[0]"))
-                .click();
-        assertTrue(driver
-                .findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_3"))
-                .getText().matches("^0\\. access has request[\\s\\S] false$"));
-        assertEquals(
-                "1. Test value in access: Set before access",
-                driver.findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_2"))
-                        .getText());
-        assertTrue(driver
-                .findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_1"))
-                .getText()
-                .matches("^2\\. has request after access[\\s\\S] true$"));
-        assertEquals(
-                "3. Test value after access: Set before run pending",
-                driver.findElement(
-                        By.vaadin("runcomvaadintestscomponentsuiUIAccess::PID_SLog_row_0"))
-                        .getText());
+        });
+    }
 
+    @Test
+    public void exceptionCanBeThrown() {
+        $(ButtonElement.class).get(2).click();
+
+        assertTrue(logContainsText("0. Throwing exception in access"));
+        assertTrue(logContainsText("1. firstFuture is done? true"));
+        assertTrue(logContainsText("2. Got exception from firstFuture: java.lang.RuntimeException: Catch me if you can"));
     }
 
-    private WebElement getCurrentInstanceWhenPushingButton() {
-        return vaadinElement("/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[7]/VButton[0]");
+    @Test
+    public void futureIsCancelledBeforeStarted() {
+        $(ButtonElement.class).get(3).click();
+
+        assertTrue(logContainsText("0. future was cancelled, should not start"));
     }
+
+    @Test
+    public void runningThreadIsCancelled() {
+        $(ButtonElement.class).get(4).click();
+
+        waitForLogToContainText("0. Waiting for thread to start");
+        waitForLogToContainText("1. Thread started, waiting for interruption");
+        waitForLogToContainText("2. I was interrupted");
+    }
+    
+    @Test
+    public void testAccessSynchronously() {
+        $(ButtonElement.class).get(5).click();
+
+        assertTrue(logContainsText("0. accessSynchronously has request? true"));
+        assertTrue(logContainsText("1. Test value in accessSynchronously: Set before accessSynchronosly"));
+        assertTrue(logContainsText("2. has request after accessSynchronously? true"));
+        assertTrue(logContainsText("3. Test value after accessSynchornously: Set in accessSynchronosly"));
+    }
+    
+    @Test
+    public void currentInstanceCanAccessValue() {
+        $(ButtonElement.class).get(6).click();
+
+        assertTrue(logContainsText("0. access has request? false"));
+        assertTrue(logContainsText("1. Test value in access: Set before access"));
+        assertTrue(logContainsText("2. has request after access? true"));
+        assertTrue(logContainsText("3. Test value after access: Set before run pending"));
+    }
+
 }