Search in sources :

Example 61 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class CustomUIClassLoaderTest method createRequestMock.

private static VaadinRequest createRequestMock(ClassLoader classloader) {
    // Mock a VaadinService to give the passed classloader
    VaadinService configurationMock = Mockito.mock(VaadinService.class);
    DeploymentConfiguration deploymentConfiguration = createConfigurationMock();
    Mockito.when(configurationMock.getDeploymentConfiguration()).thenReturn(deploymentConfiguration);
    Mockito.when(configurationMock.getClassLoader()).thenReturn(classloader);
    // Mock a VaadinRequest to give the mocked vaadin service
    VaadinRequest requestMock = Mockito.mock(VaadinRequest.class);
    Mockito.when(requestMock.getService()).thenReturn(configurationMock);
    Mockito.when(requestMock.getService()).thenReturn(configurationMock);
    Mockito.when(requestMock.getService()).thenReturn(configurationMock);
    return requestMock;
}
Also used : DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 62 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class RouteNotFoundErrorTest method setErrorParameter_productionMode_pathContainRoutesTemplate_renderedElementHasNoRoutes.

@Test
public void setErrorParameter_productionMode_pathContainRoutesTemplate_renderedElementHasNoRoutes() {
    RouteNotFoundError page = new RouteNotFoundError();
    BeforeEnterEvent event = Mockito.mock(BeforeEnterEvent.class);
    Location location = Mockito.mock(Location.class);
    Mockito.when(location.getPath()).thenReturn("{{routes}}");
    Mockito.when(event.getLocation()).thenReturn(location);
    UI ui = Mockito.mock(UI.class);
    VaadinSession session = Mockito.mock(VaadinSession.class);
    Mockito.when(ui.getSession()).thenReturn(session);
    DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(session.getConfiguration()).thenReturn(config);
    Mockito.when(config.isProductionMode()).thenReturn(true);
    Mockito.when(event.getUI()).thenReturn(ui);
    ErrorParameter<NotFoundException> param = new ErrorParameter<NotFoundException>(NotFoundException.class, new NotFoundException());
    Router router = Mockito.mock(Router.class);
    Mockito.when(event.getSource()).thenReturn(router);
    RouteRegistry registry = Mockito.mock(RouteRegistry.class);
    Mockito.when(router.getRegistry()).thenReturn(registry);
    RouteData data = new RouteData(Collections.emptyList(), "bar", Collections.emptyList(), RouteTarget.class, Collections.emptyList());
    Mockito.when(registry.getRegisteredRoutes()).thenReturn(Collections.singletonList(data));
    event.getSource().getRegistry().getRegisteredRoutes();
    page.setErrorParameter(event, param);
    MatcherAssert.assertThat(page.getElement().toString(), CoreMatchers.not(CoreMatchers.containsString("bar")));
}
Also used : UI(com.vaadin.flow.component.UI) VaadinSession(com.vaadin.flow.server.VaadinSession) RouteRegistry(com.vaadin.flow.server.RouteRegistry) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Test(org.junit.Test)

Example 63 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class FrontendUtilsTest method mockResourceProvider.

private ResourceProvider mockResourceProvider(VaadinService service) {
    DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
    VaadinContext context = Mockito.mock(VaadinContext.class);
    Lookup lookup = Mockito.mock(Lookup.class);
    Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
    ResourceProvider provider = Mockito.mock(ResourceProvider.class);
    Mockito.when(lookup.lookup(ResourceProvider.class)).thenReturn(provider);
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(config);
    Mockito.when(service.getContext()).thenReturn(context);
    Mockito.when(config.isProductionMode()).thenReturn(true);
    Mockito.when(config.getStringProperty(SERVLET_PARAMETER_STATISTICS_JSON, VAADIN_SERVLET_RESOURCES + STATISTICS_JSON_DEFAULT)).thenReturn("foo");
    return provider;
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) ResourceProvider(com.vaadin.flow.di.ResourceProvider) Lookup(com.vaadin.flow.di.Lookup) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Aggregations

DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)63 Test (org.junit.Test)24 VaadinService (com.vaadin.flow.server.VaadinService)23 VaadinSession (com.vaadin.flow.server.VaadinSession)9 UI (com.vaadin.flow.component.UI)8 Before (org.junit.Before)8 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)6 URL (java.net.URL)6 Properties (java.util.Properties)6 VaadinContext (com.vaadin.flow.server.VaadinContext)5 PushConfiguration (com.vaadin.flow.component.PushConfiguration)4 HashMap (java.util.HashMap)4 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)3 Location (com.vaadin.flow.router.Location)3 VaadinServletService (com.vaadin.flow.server.VaadinServletService)3 Method (java.lang.reflect.Method)3 Set (java.util.Set)3 ServletConfig (javax.servlet.ServletConfig)3 ServletException (javax.servlet.ServletException)3 Div (com.vaadin.flow.component.html.Div)2