PushHandler { void onConnect(AtmosphereResource resource) { if (isLiveReloadConnection(resource)) { BrowserLiveReloadAccess access = service.getInstantiator() .getOrCreate(BrowserLiveReloadAccess.class); BrowserLiveReload liveReload = access.getLiveReload(service); liveReload.onConnect(resource); } else { callWithUi(resource, establishCallback); } } PushHandler(VaadinServletService service); void setLongPollingSuspendTimeout(int longPollingSuspendTimeout); int getLongPollingSuspendTimeout();  }
@Test public void onConnect_websocketTransport_requestStartIsCalledOnServiceInstance() { VaadinServletService service = runTest((handler, resource) -> { Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET); handler.onConnect(resource); }); Mockito.verify(service).requestStart(Mockito.any(), Mockito.any()); }
@Test public void onConnect_notWebsocketTransport_requestStartIsNotCalledOnServiceInstance() { VaadinServletService service = runTest((handler, resource) -> { Mockito.when(resource.transport()).thenReturn(TRANSPORT.AJAX); handler.onConnect(resource); }); Mockito.verify(service, Mockito.times(0)).requestStart(Mockito.any(), Mockito.any()); }
@Test public void onConnect_devMode_websocket_refreshConnection_onConnectIsCalled_callWithUIIsNotCalled() throws ServiceException { MockVaadinServletService service = Mockito .spy(MockVaadinServletService.class); MockDeploymentConfiguration deploymentConfiguration = (MockDeploymentConfiguration) service .getDeploymentConfiguration(); deploymentConfiguration.setProductionMode(false); deploymentConfiguration.setDevModeLiveReloadEnabled(true); VaadinContext context = service.getContext(); BrowserLiveReload liveReload = BrowserLiveReloadAccessTest .mockBrowserLiveReloadImpl(context); AtomicReference<AtmosphereResource> res = new AtomicReference<>(); runTest(service, (handler, resource) -> { AtmosphereRequest request = resource.getRequest(); Mockito.when(request .getParameter(ApplicationConstants.LIVE_RELOAD_CONNECTION)) .thenReturn(""); Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET); handler.onConnect(resource); res.set(resource); }); Mockito.verify(service, Mockito.times(0)).requestStart(Mockito.any(), Mockito.any()); Mockito.verify(liveReload).onConnect(res.get()); }
@Test public void onConnect_productionMode_websocket_refreshConnection_delegteCallWithUI() throws ServiceException { MockVaadinServletService service = Mockito .spy(MockVaadinServletService.class); MockDeploymentConfiguration deploymentConfiguration = (MockDeploymentConfiguration) service .getDeploymentConfiguration(); deploymentConfiguration.setProductionMode(true); runTest(service, (handler, resource) -> { AtmosphereRequest request = resource.getRequest(); Mockito.when(request .getParameter(ApplicationConstants.LIVE_RELOAD_CONNECTION)) .thenReturn(""); Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET); handler.onConnect(resource); }); Mockito.verify(service).requestStart(Mockito.any(), Mockito.any()); }
@Test public void onConnect_devMode_websocket_noRefreshConnection_delegteCallWithUI() throws ServiceException { MockVaadinServletService service = Mockito .spy(MockVaadinServletService.class); MockDeploymentConfiguration deploymentConfiguration = (MockDeploymentConfiguration) service .getDeploymentConfiguration(); deploymentConfiguration.setProductionMode(false); runTest(service, (handler, resource) -> { AtmosphereRequest request = resource.getRequest(); Mockito.when(request .getParameter(ApplicationConstants.LIVE_RELOAD_CONNECTION)) .thenReturn(null); Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET); handler.onConnect(resource); }); Mockito.verify(service).requestStart(Mockito.any(), Mockito.any()); }
@Test public void onConnect_devMode_notWebsocket_refreshConnection_delegteCallWithUI() throws ServiceException, SessionExpiredException { MockVaadinServletService service = Mockito .spy(MockVaadinServletService.class); MockDeploymentConfiguration deploymentConfiguration = (MockDeploymentConfiguration) service .getDeploymentConfiguration(); deploymentConfiguration.setProductionMode(false); runTest(service, (handler, resource) -> { AtmosphereRequest request = resource.getRequest(); Mockito.when(request .getParameter(ApplicationConstants.LIVE_RELOAD_CONNECTION)) .thenReturn(""); Mockito.when(resource.transport()).thenReturn(TRANSPORT.AJAX); handler.onConnect(resource); }); Mockito.verify(service).findVaadinSession(Mockito.any()); }