use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class WebComponentBootstrapHandlerTest method initLookup.
private void initLookup(VaadinServletService service) throws IOException {
VaadinContext context = service.getContext();
Lookup lookup = Mockito.mock(Lookup.class);
context.setAttribute(Lookup.class, lookup);
ResourceProvider provider = Mockito.mock(ResourceProvider.class);
Mockito.when(lookup.lookup(ResourceProvider.class)).thenReturn(provider);
Class<? extends VaadinServlet> servletClass = service.getServlet().getClass();
Mockito.when(provider.getApplicationResource(Mockito.anyString())).thenAnswer(answer -> WebComponentBootstrapHandlerTest.class.getClassLoader().getResource(answer.getArgument(0)));
Mockito.when(provider.getClientResourceAsStream("META-INF/resources/" + ApplicationConstants.CLIENT_ENGINE_PATH + "/compile.properties")).thenAnswer(invocation -> new ByteArrayInputStream("jsFile=foo".getBytes(StandardCharsets.UTF_8)));
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class WebComponentBootstrapHandlerTest method mockRequest.
private VaadinRequest mockRequest(boolean hasConfig) {
VaadinContext context = Mockito.mock(VaadinContext.class);
VaadinService service = Mockito.mock(VaadinService.class);
VaadinRequest request = Mockito.mock(VaadinRequest.class);
Mockito.when(request.getService()).thenReturn(service);
Mockito.when(service.getContext()).thenReturn(context);
WebComponentConfigurationRegistry registry = Mockito.mock(WebComponentConfigurationRegistry.class);
Mockito.when(context.getAttribute(Mockito.eq(WebComponentConfigurationRegistry.class), Mockito.any())).thenReturn(registry);
Mockito.when(registry.hasConfigurations()).thenReturn(hasConfig);
Mockito.when(request.getPathInfo()).thenReturn("/web-component/web-component-ui.js");
return request;
}
use of com.vaadin.flow.server.VaadinContext 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.VaadinContext 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));
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class DefaultInstantiatorTest method mockLookup.
private Lookup mockLookup(VaadinService service) {
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(service.getContext()).thenReturn(context);
Lookup lookup = Mockito.mock(Lookup.class);
Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
return lookup;
}
Aggregations