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());
}
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;
}
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);
}
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));
}
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));
}
Aggregations