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.

LongPollingProxyServerIT.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright 2000-2018 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.integration.push;
  17. import static org.junit.Assert.assertEquals;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import org.junit.Assume;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. import org.junit.runner.RunWith;
  24. import org.junit.runners.Parameterized;
  25. import org.junit.runners.Parameterized.Parameter;
  26. import org.junit.runners.Parameterized.Parameters;
  27. import org.openqa.selenium.By;
  28. import org.openqa.selenium.WebDriver;
  29. import org.openqa.selenium.WebElement;
  30. import com.vaadin.tests.integration.AbstractIntegrationTest;
  31. import org.openqa.selenium.support.ui.ExpectedCondition;
  32. import org.openqa.selenium.support.ui.ExpectedConditions;
  33. import org.openqa.selenium.support.ui.WebDriverWait;
  34. @RunWith(Parameterized.class)
  35. public class LongPollingProxyServerIT extends AbstractIntegrationTest {
  36. @Parameters(name = "{0}")
  37. public static List<String[]> getTestParameters() {
  38. List<String[]> parameters = new ArrayList<String[]>();
  39. addTestParams(parameters, "Buffering+Timeout", "buffering-timeout");
  40. addTestParams(parameters, "NonBuffering+Timeout",
  41. "nonbuffering-timeout");
  42. addTestParams(parameters, "Buffering", "buffering");
  43. addTestParams(parameters, "NonBuffering", "nonbuffering");
  44. return parameters;
  45. }
  46. private static void addTestParams(List<String[]> parameters,
  47. String... pair) {
  48. parameters.add(pair);
  49. }
  50. @Parameter(0)
  51. public String name;
  52. @Parameter(1)
  53. public String path;
  54. @Override
  55. @Before
  56. public void setup() throws Exception {
  57. Assume.assumeTrue(
  58. "wildfly9-nginx".equals(System.getProperty("server-name")));
  59. super.setup();
  60. }
  61. @Test
  62. public void actionAfterFirstTimeout() throws Exception {
  63. // The wildfly9-nginx server has a configured timeout of 10s for
  64. // *-timeout urls
  65. Thread.sleep(15000);
  66. assertEquals(0, getClientCounter());
  67. getIncrementButton().click();
  68. assertEquals(1, getClientCounter());
  69. }
  70. @Test
  71. public void basicPush() {
  72. assertEquals(0, getServerCounter());
  73. getServerCounterStartButton().click();
  74. waitUntil(new ExpectedCondition<Boolean>() {
  75. @Override
  76. public Boolean apply(WebDriver webDriver) {
  77. return getServerCounter() > 1;
  78. }
  79. });
  80. }
  81. @Override
  82. protected String getContextPath() {
  83. // Prefix with the context path with the parameter
  84. return "/" + path + super.getContextPath();
  85. }
  86. @Override
  87. protected String getTestPath() {
  88. return "/";
  89. }
  90. private int getClientCounter() {
  91. WebElement clientCounterElem = findElement(
  92. By.id(BasicPush.CLIENT_COUNTER_ID));
  93. return Integer.parseInt(clientCounterElem.getText());
  94. }
  95. private int getServerCounter() {
  96. WebElement serverCounterElem = findElement(
  97. By.id(BasicPush.SERVER_COUNTER_ID));
  98. return Integer.parseInt(serverCounterElem.getText());
  99. }
  100. private WebElement getServerCounterStartButton() {
  101. return findElement(By.id(BasicPush.START_TIMER_ID));
  102. }
  103. private WebElement getIncrementButton() {
  104. return findElement(By.id(BasicPush.INCREMENT_BUTTON_ID));
  105. }
  106. }