Search in sources :

Example 11 with VaadinContext

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)));
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceProvider(com.vaadin.flow.di.ResourceProvider) Lookup(com.vaadin.flow.di.Lookup)

Example 12 with VaadinContext

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;
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) WebComponentConfigurationRegistry(com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry) VaadinService(com.vaadin.flow.server.VaadinService) VaadinRequest(com.vaadin.flow.server.VaadinRequest)

Example 13 with VaadinContext

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));
}
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 14 with VaadinContext

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));
}
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 VaadinContext

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;
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext)

Aggregations

VaadinContext (com.vaadin.flow.server.VaadinContext)42 Test (org.junit.Test)16 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)15 VaadinService (com.vaadin.flow.server.VaadinService)11 Lookup (com.vaadin.flow.di.Lookup)8 ResourceProvider (com.vaadin.flow.di.ResourceProvider)8 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)5 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)5 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)5 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)5 Properties (java.util.Properties)5 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)4 VaadinConfig (com.vaadin.flow.server.VaadinConfig)4 MockDeploymentConfiguration (com.vaadin.tests.util.MockDeploymentConfiguration)4 File (java.io.File)4 Before (org.junit.Before)4 VaadinSession (com.vaadin.flow.server.VaadinSession)3 WebComponentConfigurationRegistry (com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry)3 AppShellRegistry (com.vaadin.flow.server.AppShellRegistry)2 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)2