Search in sources :

Example 11 with VaadinService

use of com.vaadin.flow.server.VaadinService in project flow by vaadin.

the class SerializationTest method testSerializeVaadinSession_accessQueueIsRecreated.

@Test
public void testSerializeVaadinSession_accessQueueIsRecreated() throws Exception {
    VaadinService vaadinService = new MockVaadinService(true);
    VaadinSession session = new VaadinSession(vaadinService);
    session = serializeAndDeserialize(session);
    Assert.assertNotNull("Pending access queue was not recreated after deserialization", session.getPendingAccessQueue());
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) Test(org.junit.Test)

Example 12 with VaadinService

use of com.vaadin.flow.server.VaadinService in project flow by vaadin.

the class SerializationTest method serializeAndDeserializeWithUI.

private static VaadinSession serializeAndDeserializeWithUI(boolean serializeUI) throws IOException, ClassNotFoundException {
    VaadinService vaadinService = new MockVaadinService(false, serializeUI);
    VaadinSession session = new VaadinSession(vaadinService);
    // This is done only for test purpose to init the session lock,
    // should be called by Flow internally as soon as the session has
    // been created.
    session.refreshTransients(null, vaadinService);
    MockUI ui = new MockUI(session);
    ui.doInit(null, 42);
    session.addUI(ui);
    session = serializeAndDeserialize(session);
    // This is done only for test purpose to refresh the session lock,
    // should be called by Flow internally as soon as the session has
    // been retrieved from http session.
    session.refreshTransients(null, vaadinService);
    return session;
}
Also used : MockUI(com.vaadin.tests.util.MockUI) VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinService(com.vaadin.flow.server.VaadinService)

Example 13 with VaadinService

use of com.vaadin.flow.server.VaadinService in project flow by vaadin.

the class AbstractDevModeTest method setup.

@Before
public void setup() throws Exception {
    baseDir = temporaryFolder.getRoot().getPath();
    npmFolder = temporaryFolder.getRoot();
    Boolean enablePnpm = Boolean.TRUE;
    appConfig = Mockito.mock(ApplicationConfiguration.class);
    servletContext = Mockito.mock(ServletContext.class);
    Mockito.when(servletContext.getAttribute(ApplicationConfiguration.class.getName())).thenReturn(appConfig);
    Mockito.when(servletContext.getClassLoader()).thenReturn(servletContext.getClass().getClassLoader());
    vaadinContext = new VaadinServletContext(servletContext);
    mockApplicationConfiguration(appConfig, enablePnpm);
    lookup = Mockito.mock(Lookup.class);
    Mockito.when(servletContext.getAttribute(Lookup.class.getName())).thenReturn(lookup);
    ResourceProvider resourceProvider = Mockito.mock(ResourceProvider.class);
    Mockito.when(lookup.lookup(ResourceProvider.class)).thenReturn(resourceProvider);
    devModeHandlerManager = new DevModeHandlerManagerImpl();
    Mockito.when(lookup.lookup(DevModeHandlerManager.class)).thenReturn(devModeHandlerManager);
    configuration = new MockDeploymentConfiguration();
    Mockito.when(lookup.lookup(DeploymentConfiguration.class)).thenReturn(configuration);
    Mockito.when(lookup.lookup(ApplicationConfiguration.class)).thenReturn(appConfig);
    Mockito.when(lookup.lookup(StaticFileHandlerFactory.class)).thenReturn(service -> new StaticFileServer(service));
    vaadinService = Mockito.mock(VaadinService.class);
    Mockito.when(vaadinService.getContext()).thenReturn(vaadinContext);
    Mockito.when(vaadinService.getDeploymentConfiguration()).thenReturn(configuration);
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) StaticFileServer(com.vaadin.flow.server.StaticFileServer) ResourceProvider(com.vaadin.flow.di.ResourceProvider) DevModeHandlerManagerImpl(com.vaadin.base.devserver.DevModeHandlerManagerImpl) MockDeploymentConfiguration(com.vaadin.base.devserver.MockDeploymentConfiguration) VaadinService(com.vaadin.flow.server.VaadinService) VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) ServletContext(javax.servlet.ServletContext) Lookup(com.vaadin.flow.di.Lookup) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Before(org.junit.Before)

Example 14 with VaadinService

use of com.vaadin.flow.server.VaadinService in project flow by vaadin.

the class BrowserLiveReloadAccessorImplTest method getLiveReload_devMode_contextHasReloadInstance_instanceIsReturned.

@Test
public void getLiveReload_devMode_contextHasReloadInstance_instanceIsReturned() {
    VaadinService service = Mockito.mock(VaadinService.class);
    DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(config);
    Mockito.when(config.isProductionMode()).thenReturn(false);
    Mockito.when(config.isDevModeLiveReloadEnabled()).thenReturn(true);
    VaadinContext context = Mockito.mock(VaadinContext.class);
    Mockito.when(service.getContext()).thenReturn(context);
    BrowserLiveReload reload = Mockito.mock(BrowserLiveReload.class);
    Mockito.when(context.getAttribute(Mockito.eq(BrowserLiveReload.class), Mockito.any())).thenReturn(reload);
    Assert.assertSame(reload, access.getLiveReload(service));
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) VaadinService(com.vaadin.flow.server.VaadinService) BrowserLiveReload(com.vaadin.flow.internal.BrowserLiveReload) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Test(org.junit.Test)

Example 15 with VaadinService

use of com.vaadin.flow.server.VaadinService in project flow by vaadin.

the class BrowserLiveReloadAccessorImplTest method getLiveReload_devMode_contextHasNoReloadInstance_instanceIsCreated.

@Test
public void getLiveReload_devMode_contextHasNoReloadInstance_instanceIsCreated() {
    VaadinService service = Mockito.mock(VaadinService.class);
    DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(config);
    Mockito.when(config.isProductionMode()).thenReturn(false);
    Mockito.when(config.isDevModeLiveReloadEnabled()).thenReturn(true);
    VaadinContext context = Mockito.mock(VaadinContext.class);
    Mockito.when(context.getAttribute(Mockito.eq(BrowserLiveReload.class), Mockito.any())).thenReturn(Mockito.mock(BrowserLiveReload.class));
    Mockito.when(service.getContext()).thenReturn(context);
    Assert.assertNotNull(access.getLiveReload(service));
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) VaadinService(com.vaadin.flow.server.VaadinService) BrowserLiveReload(com.vaadin.flow.internal.BrowserLiveReload) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Test(org.junit.Test)

Aggregations

VaadinService (com.vaadin.flow.server.VaadinService)86 Test (org.junit.Test)39 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)19 VaadinSession (com.vaadin.flow.server.VaadinSession)18 Properties (java.util.Properties)15 VaadinContext (com.vaadin.flow.server.VaadinContext)12 Before (org.junit.Before)11 SpringInstantiatorTest (com.vaadin.flow.spring.instantiator.SpringInstantiatorTest)10 UI (com.vaadin.flow.component.UI)9 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)8 Lookup (com.vaadin.flow.di.Lookup)7 VaadinResponse (com.vaadin.flow.server.VaadinResponse)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 ServletContext (javax.servlet.ServletContext)6 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)5 DefaultInstantiator (com.vaadin.flow.di.DefaultInstantiator)4 Instantiator (com.vaadin.flow.di.Instantiator)4 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)4 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)4 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)4