Search in sources :

Example 1 with DevModeHandlerManager

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"));
}
Also used : DevModeHandlerManager(com.vaadin.flow.internal.DevModeHandlerManager) VaadinContext(com.vaadin.flow.server.VaadinContext) HttpURLConnection(java.net.HttpURLConnection) Set(java.util.Set) ByteArrayInputStream(java.io.ByteArrayInputStream) DevModeHandler(com.vaadin.flow.internal.DevModeHandler) ResourceProvider(com.vaadin.flow.di.ResourceProvider) Lookup(com.vaadin.flow.di.Lookup) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) URL(java.net.URL) Test(org.junit.Test)

Example 2 with DevModeHandlerManager

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);
}
Also used : DevModeHandlerManager(com.vaadin.flow.internal.DevModeHandlerManager) Lookup(com.vaadin.flow.di.Lookup)

Aggregations

Lookup (com.vaadin.flow.di.Lookup)2 DevModeHandlerManager (com.vaadin.flow.internal.DevModeHandlerManager)2 ResourceProvider (com.vaadin.flow.di.ResourceProvider)1 DevModeHandler (com.vaadin.flow.internal.DevModeHandler)1 VaadinContext (com.vaadin.flow.server.VaadinContext)1 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 Set (java.util.Set)1 Test (org.junit.Test)1