Search in sources :

Example 31 with ApplicationConfiguration

use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.

the class AbstractDnDUnitTest method setup.

@Before
public void setup() {
    ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
    Mockito.when(appConfig.getBuildFolder()).thenReturn(".");
    VaadinContext context = Mockito.mock(VaadinContext.class);
    Mockito.when(appConfig.getContext()).thenReturn(context);
    Lookup lookup = Mockito.mock(Lookup.class);
    Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
    DefaultDeploymentConfiguration configuration = new DefaultDeploymentConfiguration(appConfig, VaadinServlet.class, new Properties());
    VaadinService service = Mockito.mock(VaadinService.class);
    Mockito.when(service.resolveResource(Mockito.anyString())).thenReturn("");
    VaadinSession session = Mockito.mock(VaadinSession.class);
    Mockito.when(session.getConfiguration()).thenReturn(configuration);
    Mockito.when(session.getService()).thenReturn(service);
    ui = new MockUI(session);
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) Lookup(com.vaadin.flow.di.Lookup) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Before(org.junit.Before)

Example 32 with ApplicationConfiguration

use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.

the class VaadinSession method writeObject.

private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
    boolean serializeUIs = true;
    // the same way again
    if (getService() != null) {
        ApplicationConfiguration appConfiguration = ApplicationConfiguration.get(getService().getContext());
        if (!appConfiguration.isProductionMode() && !appConfiguration.isDevModeSessionSerializationEnabled()) {
            serializeUIs = false;
        }
    }
    stream.defaultWriteObject();
    if (serializeUIs) {
        stream.writeObject(uIs);
    } else {
        stream.writeObject(new HashMap<>());
    }
}
Also used : ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 33 with ApplicationConfiguration

use of com.vaadin.flow.server.startup.ApplicationConfiguration 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 34 with ApplicationConfiguration

use of com.vaadin.flow.server.startup.ApplicationConfiguration 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());
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) BrowserLiveReload(com.vaadin.flow.internal.BrowserLiveReload) AtomicReference(java.util.concurrent.atomic.AtomicReference) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 35 with ApplicationConfiguration

use of com.vaadin.flow.server.startup.ApplicationConfiguration 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());
    });
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Aggregations

ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)61 Properties (java.util.Properties)39 Test (org.junit.Test)39 VaadinContext (com.vaadin.flow.server.VaadinContext)14 Lookup (com.vaadin.flow.di.Lookup)9 VaadinService (com.vaadin.flow.server.VaadinService)7 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)6 ServletContext (javax.servlet.ServletContext)5 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)4 VaadinServletService (com.vaadin.flow.server.VaadinServletService)4 VaadinSession (com.vaadin.flow.server.VaadinSession)4 File (java.io.File)4 Before (org.junit.Before)4 UI (com.vaadin.flow.component.UI)3 ResourceProvider (com.vaadin.flow.di.ResourceProvider)3 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)3 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2