use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class IndexHtmlRequestHandlerTest method should_attachWebpackErrors.
@Test
public void should_attachWebpackErrors() throws Exception {
deploymentConfiguration.setEnableDevServer(true);
deploymentConfiguration.setProductionMode(false);
DevModeHandler devServer = Mockito.mock(DevModeHandler.class);
Mockito.when(devServer.getFailedOutput()).thenReturn("Failed to compile");
Mockito.when(devServer.prepareConnection(Mockito.anyString(), Mockito.anyString())).thenReturn(Mockito.mock(HttpURLConnection.class));
service.setContext(context);
DevModeHandlerManager devModeHandlerManager = new DevModeHandlerManager() {
@Override
public Class<?>[] getHandlesTypes() {
return new Class[0];
}
@Override
public void initDevModeHandler(Set<Class<?>> classes, VaadinContext context) throws VaadinInitializerException {
}
@Override
public void setDevModeHandler(DevModeHandler devModeHandler) {
}
@Override
public DevModeHandler getDevModeHandler() {
return devServer;
}
};
ResourceProvider resourceProvider = Mockito.mock(ResourceProvider.class);
Lookup lookup = Lookup.compose(Lookup.of(devModeHandlerManager, DevModeHandlerManager.class), Lookup.of(resourceProvider, ResourceProvider.class));
Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
mockApplicationConfiguration(appConfig);
URL resource = Mockito.mock(URL.class);
Mockito.when(resourceProvider.getApplicationResource(VAADIN_WEBAPP_RESOURCES + INDEX_HTML)).thenReturn(resource);
when(resource.openStream()).thenReturn(new ByteArrayInputStream("<html><head></head></html>".getBytes()));
// Send the request
indexHtmlRequestHandler.synchronizedHandleRequest(session, createVaadinRequest("/"), response);
String indexHtml = responseOutput.toString(StandardCharsets.UTF_8.name());
Assert.assertTrue("Should have a system error dialog", indexHtml.contains("<div class=\"v-system-error\">"));
Assert.assertTrue("Should show webpack failure error", indexHtml.contains("Failed to compile"));
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class WebComponentProviderTest method mockRequest.
private VaadinRequest mockRequest(boolean hasConfig) {
VaadinContext context = Mockito.mock(VaadinContext.class);
VaadinService service = Mockito.mock(VaadinService.class);
VaadinRequest request = Mockito.mock(VaadinRequest.class);
Mockito.when(request.getService()).thenReturn(service);
Mockito.when(service.getContext()).thenReturn(context);
WebComponentConfigurationRegistry registry = Mockito.mock(WebComponentConfigurationRegistry.class);
Mockito.when(context.getAttribute(Mockito.eq(WebComponentConfigurationRegistry.class), Mockito.any())).thenReturn(registry);
Mockito.when(registry.hasConfigurations()).thenReturn(hasConfig);
Mockito.when(request.getPathInfo()).thenReturn("/web-component/a-b.js");
return request;
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class WebComponentBootstrapHandlerTest method getMockResponse.
private VaadinResponse getMockResponse(ByteArrayOutputStream stream) throws IOException {
VaadinResponse response = Mockito.mock(VaadinResponse.class);
VaadinService service = Mockito.mock(VaadinService.class);
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(response.getOutputStream()).thenReturn(stream);
Mockito.when(response.getService()).thenReturn(service);
Mockito.when(service.getContext()).thenReturn(context);
Mockito.when(context.getAttribute(eq(WebComponentConfigurationRegistry.class), any())).thenReturn(Mockito.mock(WebComponentConfigurationRegistry.class));
return response;
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class PushHandlerTest method onConnect_devMode_websocket_refreshConnection_onConnectIsCalled_callWithUIIsNotCalled.
@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);
deploymentConfiguration.setDevModeGizmoEnabled(true);
ApplicationConfiguration applicationConfiguration = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(applicationConfiguration.isProductionMode()).thenReturn(false);
VaadinContext context = service.getContext();
context.setAttribute(ApplicationConfiguration.class, applicationConfiguration);
BrowserLiveReload liveReload = mockBrowserLiveReloadImpl(context);
AtomicReference<AtmosphereResource> res = new AtomicReference<>();
runTest(service, (handler, resource) -> {
AtmosphereRequest request = resource.getRequest();
Mockito.when(request.getParameter(ApplicationConstants.DEBUG_WINDOW_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());
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class PushHandlerTest method debugWindowConnection_productionMode_mustNeverBeConnected.
@Test
public void debugWindowConnection_productionMode_mustNeverBeConnected() throws Exception {
ApplicationConfiguration applicationConfiguration = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(applicationConfiguration.isProductionMode()).thenReturn(true);
MockVaadinServletService service = Mockito.spy(MockVaadinServletService.class);
VaadinContext context = service.getContext();
context.setAttribute(ApplicationConfiguration.class, applicationConfiguration);
runTest(service, (handler, resource) -> {
Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET);
Mockito.when(resource.getRequest().getParameter(ApplicationConstants.DEBUG_WINDOW_CONNECTION)).thenReturn("");
Mockito.doNothing().when(handler).callWithService(Mockito.any(), Mockito.any());
handler.onConnect(resource);
Mockito.verify(handler, Mockito.never()).callWithService(Mockito.any(), Mockito.any());
Mockito.verify(handler, Mockito.never()).callWithUi(Mockito.any(), Mockito.any());
});
}
Aggregations