use of com.vaadin.flow.internal.DevModeHandlerManager 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.internal.DevModeHandlerManager in project flow by vaadin.
the class DevModeStartupListener method initialize.
@Override
public void initialize(Set<Class<?>> classes, VaadinContext context) throws VaadinInitializerException {
Lookup lookup = context.getAttribute(Lookup.class);
DevModeHandlerManager devModeHandlerManager = lookup.lookup(DevModeHandlerManager.class);
devModeHandlerManager.initDevModeHandler(classes, context);
}
Aggregations