use of org.atmosphere.cpr.AtmosphereResource in project flow by vaadin.
the class PushHandlerTest method runTest.
private VaadinServletService runTest(VaadinServletService service, BiConsumer<PushHandler, AtmosphereResource> testExec) throws ServiceException {
PushHandler handler = Mockito.spy(new PushHandler(service));
AtmosphereResource resource = Mockito.mock(AtmosphereResource.class);
AtmosphereRequest request = Mockito.mock(AtmosphereRequest.class);
Mockito.when(resource.getRequest()).thenReturn(request);
testExec.accept(handler, resource);
return service;
}
use of org.atmosphere.cpr.AtmosphereResource in project flow by vaadin.
the class PushHandlerTest method onMessage_devMode_websocket_refreshConnection_callWithUIIsNotCalled.
@Test
public void onMessage_devMode_websocket_refreshConnection_callWithUIIsNotCalled() throws ServiceException {
MockVaadinServletService service = Mockito.spy(MockVaadinServletService.class);
MockDeploymentConfiguration deploymentConfiguration = (MockDeploymentConfiguration) service.getDeploymentConfiguration();
deploymentConfiguration.setProductionMode(false);
deploymentConfiguration.setDevModeLiveReloadEnabled(true);
deploymentConfiguration.setDevModeGizmoEnabled(true);
VaadinContext context = service.getContext();
mockBrowserLiveReloadImpl(context);
AtomicReference<AtmosphereResource> res = new AtomicReference<>();
runTest(service, (handler, resource) -> {
AtmosphereRequest request = resource.getRequest();
try {
Mockito.when(request.getReader()).thenReturn(new BufferedReader(new StringReader("")));
} catch (IOException e) {
throw new RuntimeException(e);
}
Mockito.when(request.getParameter(ApplicationConstants.DEBUG_WINDOW_CONNECTION)).thenReturn("");
Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET);
try {
Mockito.when(request.getReader()).thenReturn(new BufferedReader(new StringReader("{}")));
} catch (IOException e) {
throw new RuntimeException(e);
}
handler.onMessage(resource);
res.set(resource);
});
Mockito.verify(service, Mockito.times(0)).requestStart(Mockito.any(), Mockito.any());
}
use of org.atmosphere.cpr.AtmosphereResource in project flow by vaadin.
the class DebugWindowConnectionTest method reload_resourceIsDisconnected_reloadCommandIsNotSent.
@Test
public void reload_resourceIsDisconnected_reloadCommandIsNotSent() {
AtmosphereResource resource = Mockito.mock(AtmosphereResource.class);
Broadcaster broadcaster = Mockito.mock(Broadcaster.class);
Mockito.when(resource.getBroadcaster()).thenReturn(broadcaster);
reload.onConnect(resource);
Assert.assertTrue(reload.isLiveReload(resource));
Mockito.reset(broadcaster);
reload.onDisconnect(resource);
Assert.assertFalse(reload.isLiveReload(resource));
reload.reload();
Mockito.verifyNoInteractions(broadcaster);
}
use of org.atmosphere.cpr.AtmosphereResource in project flow by vaadin.
the class DebugWindowConnectionTest method reload_twoConnections_sendReloadCommand.
@Test
public void reload_twoConnections_sendReloadCommand() {
AtmosphereResource resource1 = Mockito.mock(AtmosphereResource.class);
AtmosphereResource resource2 = Mockito.mock(AtmosphereResource.class);
Broadcaster broadcaster = Mockito.mock(Broadcaster.class);
Mockito.when(resource1.getBroadcaster()).thenReturn(broadcaster);
Mockito.when(resource2.getBroadcaster()).thenReturn(broadcaster);
reload.onConnect(resource1);
reload.onConnect(resource2);
Assert.assertTrue(reload.isLiveReload(resource1));
Assert.assertTrue(reload.isLiveReload(resource2));
reload.reload();
Mockito.verify(broadcaster).broadcast("{\"command\": \"reload\"}", resource1);
Mockito.verify(broadcaster).broadcast("{\"command\": \"reload\"}", resource2);
}
use of org.atmosphere.cpr.AtmosphereResource in project cxf by apache.
the class SseAtmosphereEventSinkContextProvider method createContext.
@Override
public SseEventSink createContext(Message message) {
final HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
if (request == null) {
throw new IllegalStateException("Unable to retrieve HTTP request from the context");
}
final AtmosphereResource resource = (AtmosphereResource) request.getAttribute(AtmosphereResource.class.getName());
if (resource == null) {
throw new IllegalStateException("AtmosphereResource is not present, " + "is AtmosphereServlet configured properly?");
}
final Broadcaster broadcaster = resource.getAtmosphereConfig().getBroadcasterFactory().lookup(resource.uuid(), true);
resource.removeFromAllBroadcasters();
resource.setBroadcaster(broadcaster);
final MessageBodyWriter<OutboundSseEvent> writer = new OutboundSseEventBodyWriter(ServerProviderFactory.getInstance(message), message.getExchange());
return new SseAtmosphereEventSinkImpl(writer, resource);
}
Aggregations