Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

UIAccessTest.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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(
  47. "1. Exception occurred, java.lang.RuntimeException: Catch me if you can"));
  48. assertTrue(logContainsText("2. firstFuture is done? true"));
  49. assertTrue(logContainsText(
  50. "3. Got exception from firstFuture: java.lang.RuntimeException: Catch me if you can"));
  51. }
  52. @Test
  53. public void futureIsCancelledBeforeStarted() {
  54. $(ButtonElement.class).get(3).click();
  55. assertTrue(
  56. logContainsText("0. future was cancelled, should not start"));
  57. }
  58. @Test
  59. public void runningThreadIsCancelled() {
  60. $(ButtonElement.class).get(4).click();
  61. waitForLogToContainText("0. Waiting for thread to start");
  62. waitForLogToContainText("1. Thread started, waiting for interruption");
  63. waitForLogToContainText("2. I was interrupted");
  64. }
  65. @Test
  66. public void testAccessSynchronously() {
  67. $(ButtonElement.class).get(5).click();
  68. assertTrue(logContainsText("0. accessSynchronously has request? true"));
  69. assertTrue(logContainsText(
  70. "1. Test value in accessSynchronously: Set before accessSynchronosly"));
  71. assertTrue(logContainsText(
  72. "2. has request after accessSynchronously? true"));
  73. assertTrue(logContainsText(
  74. "3. Test value after accessSynchornously: Set in accessSynchronosly"));
  75. }
  76. }