You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UIAccessTest.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package com.vaadin.tests.components.ui;
  2. import static org.junit.Assert.assertTrue;
  3. import org.junit.Test;
  4. import com.vaadin.testbench.elements.ButtonElement;
  5. import com.vaadin.tests.tb3.MultiBrowserTest;
  6. public class UIAccessTest extends MultiBrowserTest {
  7. @Override
  8. public void setup() throws Exception {
  9. super.setup();
  10. setPush(false);
  11. openTestURL();
  12. }
  13. @Test
  14. public void testThreadLocals() {
  15. setPush(true);
  16. openTestURL();
  17. $(ButtonElement.class).get(7).click();
  18. waitForLogToContainText(
  19. "0. Current UI matches in beforeResponse? true");
  20. waitForLogToContainText(
  21. "1. Current session matches in beforeResponse? true");
  22. }
  23. @Test
  24. public void canBeAccessedFromUIThread() {
  25. $(ButtonElement.class).first().click();
  26. assertTrue(logContainsText(
  27. "0. Access from UI thread future is done? false"));
  28. assertTrue(logContainsText("1. Access from UI thread is run"));
  29. assertTrue(logContainsText(
  30. "2. beforeClientResponse future is done? true"));
  31. }
  32. @Test
  33. public void canBeAccessedFromBackgroundThread() {
  34. $(ButtonElement.class).get(1).click();
  35. assertTrue(logContainsText("0. Initial background message"));
  36. assertTrue(logContainsText("1. Thread has current response? false"));
  37. waitForLogToContainText("2. Thread got lock, inital future done? true");
  38. }
  39. private void waitForLogToContainText(final String text) {
  40. waitUntil(input -> logContainsText(text));
  41. }
  42. @Test
  43. public void exceptionCanBeThrown() {
  44. $(ButtonElement.class).get(2).click();
  45. assertTrue(logContainsText("0. Throwing exception in access"));
  46. assertTrue(logContainsText("1. firstFuture is done? true"));
  47. assertTrue(logContainsText(
  48. "2. Got exception from firstFuture: java.lang.RuntimeException: Catch me if you can"));
  49. }
  50. @Test
  51. public void futureIsCancelledBeforeStarted() {
  52. $(ButtonElement.class).get(3).click();
  53. assertTrue(
  54. logContainsText("0. future was cancelled, should not start"));
  55. }
  56. @Test
  57. public void runningThreadIsCancelled() {
  58. $(ButtonElement.class).get(4).click();
  59. waitForLogToContainText("0. Waiting for thread to start");
  60. waitForLogToContainText("1. Thread started, waiting for interruption");
  61. waitForLogToContainText("2. I was interrupted");
  62. }
  63. @Test
  64. public void testAccessSynchronously() {
  65. $(ButtonElement.class).get(5).click();
  66. assertTrue(logContainsText("0. accessSynchronously has request? true"));
  67. assertTrue(logContainsText(
  68. "1. Test value in accessSynchronously: Set before accessSynchronosly"));
  69. assertTrue(logContainsText(
  70. "2. has request after accessSynchronously? true"));
  71. assertTrue(logContainsText(
  72. "3. Test value after accessSynchornously: Set in accessSynchronosly"));
  73. }
  74. }