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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.ui;
  17. import static org.junit.Assert.assertTrue;
  18. import org.junit.Test;
  19. import com.vaadin.testbench.elements.ButtonElement;
  20. import com.vaadin.tests.tb3.MultiBrowserTest;
  21. public class UIAccessTest extends MultiBrowserTest {
  22. @Override
  23. public void setup() throws Exception {
  24. super.setup();
  25. setPush(false);
  26. openTestURL();
  27. }
  28. @Test
  29. public void testThreadLocals() {
  30. setPush(true);
  31. openTestURL();
  32. $(ButtonElement.class).get(7).click();
  33. waitForLogToContainText(
  34. "0. Current UI matches in beforeResponse? true");
  35. waitForLogToContainText(
  36. "1. Current session matches in beforeResponse? true");
  37. }
  38. @Test
  39. public void canBeAccessedFromUIThread() {
  40. $(ButtonElement.class).first().click();
  41. assertTrue(logContainsText(
  42. "0. Access from UI thread future is done? false"));
  43. assertTrue(logContainsText("1. Access from UI thread is run"));
  44. assertTrue(logContainsText(
  45. "2. beforeClientResponse future is done? true"));
  46. }
  47. @Test
  48. public void canBeAccessedFromBackgroundThread() {
  49. $(ButtonElement.class).get(1).click();
  50. assertTrue(logContainsText("0. Initial background message"));
  51. assertTrue(logContainsText("1. Thread has current response? false"));
  52. waitForLogToContainText("2. Thread got lock, inital future done? true");
  53. }
  54. private void waitForLogToContainText(final String text) {
  55. waitUntil(input -> logContainsText(text));
  56. }
  57. @Test
  58. public void exceptionCanBeThrown() {
  59. $(ButtonElement.class).get(2).click();
  60. assertTrue(logContainsText("0. Throwing exception in access"));
  61. assertTrue(logContainsText("1. firstFuture is done? true"));
  62. assertTrue(logContainsText(
  63. "2. Got exception from firstFuture: java.lang.RuntimeException: Catch me if you can"));
  64. }
  65. @Test
  66. public void futureIsCancelledBeforeStarted() {
  67. $(ButtonElement.class).get(3).click();
  68. assertTrue(
  69. logContainsText("0. future was cancelled, should not start"));
  70. }
  71. @Test
  72. public void runningThreadIsCancelled() {
  73. $(ButtonElement.class).get(4).click();
  74. waitForLogToContainText("0. Waiting for thread to start");
  75. waitForLogToContainText("1. Thread started, waiting for interruption");
  76. waitForLogToContainText("2. I was interrupted");
  77. }
  78. @Test
  79. public void testAccessSynchronously() {
  80. $(ButtonElement.class).get(5).click();
  81. assertTrue(logContainsText("0. accessSynchronously has request? true"));
  82. assertTrue(logContainsText(
  83. "1. Test value in accessSynchronously: Set before accessSynchronosly"));
  84. assertTrue(logContainsText(
  85. "2. has request after accessSynchronously? true"));
  86. assertTrue(logContainsText(
  87. "3. Test value after accessSynchornously: Set in accessSynchronosly"));
  88. }
  89. }