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.

PushHandlerTest 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2000-2020 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.server.communication;
  17. import java.util.concurrent.Future;
  18. import org.atmosphere.cpr.AtmosphereRequest;
  19. import org.atmosphere.cpr.AtmosphereResource;
  20. import org.atmosphere.cpr.AtmosphereResourceEvent;
  21. import org.junit.Assert;
  22. import org.junit.Test;
  23. import org.mockito.Mockito;
  24. import com.vaadin.server.MockVaadinServletService;
  25. import com.vaadin.server.MockVaadinSession;
  26. import com.vaadin.server.ServiceException;
  27. import com.vaadin.server.SessionExpiredException;
  28. import com.vaadin.server.VaadinRequest;
  29. import com.vaadin.server.VaadinSession;
  30. import com.vaadin.ui.UI;
  31. public class PushHandlerTest {
  32. MockVaadinSession session = null;
  33. @Test
  34. public void connectionLost_currentInstancesAreCleared()
  35. throws SessionExpiredException, ServiceException {
  36. session = new MockVaadinSession() {
  37. @Override
  38. public Future<Void> access(Runnable runnable) {
  39. runnable.run();
  40. return Mockito.mock(Future.class);
  41. }
  42. };
  43. VaadinSession.setCurrent(session);
  44. Assert.assertNotNull(VaadinSession.getCurrent());
  45. MockVaadinServletService service = null;
  46. service = new MockVaadinServletService() {
  47. @Override
  48. public com.vaadin.server.VaadinSession findVaadinSession(
  49. VaadinRequest request) throws SessionExpiredException {
  50. return session;
  51. }
  52. @Override
  53. public UI findUI(VaadinRequest request) {
  54. return null;
  55. }
  56. };
  57. service.init();
  58. PushHandler handler = new PushHandler(service);
  59. AtmosphereResource resource = Mockito.mock(AtmosphereResource.class);
  60. AtmosphereRequest request = Mockito.mock(AtmosphereRequest.class);
  61. Mockito.when(resource.getRequest()).thenReturn(request);
  62. AtmosphereResourceEvent event = Mockito
  63. .mock(AtmosphereResourceEvent.class);
  64. Mockito.when(event.getResource()).thenReturn(resource);
  65. handler.connectionLost(event);
  66. Assert.assertNull(VaadinSession.getCurrent());
  67. }
  68. }