Search in sources :

Example 21 with DeploymentConfiguration

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

the class LegacyPropertyEnabledTestServlet method testValuesFromAnnotation.

@Test
public void testValuesFromAnnotation() throws ServletException {
    TestServlet servlet = new TestServlet();
    servlet.init(new MockServletConfig());
    DeploymentConfiguration configuration = servlet.getService().getDeploymentConfiguration();
    Assert.assertEquals(true, configuration.isProductionMode());
    Assert.assertEquals(true, configuration.isCloseIdleSessions());
    Assert.assertEquals(1234, configuration.getHeartbeatInterval());
    Class<? extends UI> uiClass = BootstrapHandler.getUIClass(new VaadinServletRequest(EasyMock.createMock(HttpServletRequest.class), servlet.getService()));
    Assert.assertEquals(MockUIContainingServlet.class, uiClass);
}
Also used : VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Test(org.junit.Test)

Example 22 with DeploymentConfiguration

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

the class LegacyPropertyEnabledTestServlet method testValuesOverriddenForServlet.

@Test
public void testValuesOverriddenForServlet() throws ServletException {
    final boolean expectedBoolean = false;
    final int expectedInt = 1111;
    Properties servletInitParams = new Properties();
    servletInitParams.setProperty("sendUrlsAsParameters", Boolean.toString(expectedBoolean));
    servletInitParams.setProperty("heartbeatInterval", Integer.toString(expectedInt));
    TestServlet servlet = new TestServlet();
    servlet.init(new MockServletConfig(servletInitParams));
    DeploymentConfiguration configuration = servlet.getService().getDeploymentConfiguration();
    // Values from servlet init params take precedence
    Assert.assertEquals(expectedBoolean, configuration.isSendUrlsAsParameters());
    Assert.assertEquals(expectedInt, configuration.getHeartbeatInterval());
    // Other params are as defined in the annotation
    Assert.assertEquals(true, configuration.isCloseIdleSessions());
    Class<? extends UI> uiClass = BootstrapHandler.getUIClass(new VaadinServletRequest(EasyMock.createMock(HttpServletRequest.class), servlet.getService()));
    Assert.assertEquals(MockUIContainingServlet.class, uiClass);
}
Also used : VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) Properties(java.util.Properties) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Test(org.junit.Test)

Example 23 with DeploymentConfiguration

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

the class VaadinServletTest method resolveTranslation_for_servlet_with_muliple_path_parts.

@Test
public void resolveTranslation_for_servlet_with_muliple_path_parts() throws MalformedURLException {
    request = Mockito.mock(VaadinServletRequest.class);
    CurrentInstance.set(VaadinRequest.class, request);
    DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(((VaadinServletRequest) request).getServletPath()).thenReturn("/app/sub/");
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
    Mockito.when(configuration.isProductionMode()).thenReturn(false);
    Mockito.when(factory.getUriResolver(request)).thenReturn(vaadinUriResolver);
    String path = "/src/foo";
    String resolved = "./../../src/bar";
    Mockito.when(vaadinUriResolver.resolveVaadinUri(path)).thenReturn(resolved);
    Mockito.when(vaadinUriResolver.resolveVaadinUri("/theme/foo")).thenReturn("./../../theme/foo");
    Mockito.when(context.getResource("/./theme/foo")).thenReturn(new URL("http://theme/foo"));
    String urlTranslation = servlet.getUrlTranslation(new MyTheme(), path);
    Assert.assertEquals("/theme/foo", urlTranslation);
}
Also used : DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) URL(java.net.URL) Test(org.junit.Test)

Example 24 with DeploymentConfiguration

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

the class VaadinServletTest method resolveResource_webJarResource_resolvedAsWebJarsResource.

@Test
public void resolveResource_webJarResource_resolvedAsWebJarsResource() throws ServletException, MalformedURLException {
    String path = "foo";
    String frontendPrefix = "context://baz/";
    String resolved = "/baz/bower_components/";
    Mockito.when(vaadinUriResolver.resolveVaadinUri(path)).thenReturn(resolved);
    service = Mockito.mock(VaadinServletService.class);
    DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(configuration.getDevelopmentFrontendPrefix()).thenReturn(frontendPrefix);
    Mockito.when(configuration.areWebJarsEnabled()).thenReturn(true);
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
    ServletConfig config = Mockito.mock(ServletConfig.class);
    servlet.init(config);
    CurrentInstance.set(VaadinRequest.class, request);
    CurrentInstance.set(VaadinSession.class, session);
    URL url = new URL("http://example.com");
    String webjars = "/webjars/";
    Mockito.when(context.getResource(webjars)).thenReturn(url);
    Assert.assertEquals(webjars, servlet.resolveResource(path));
}
Also used : ServletConfig(javax.servlet.ServletConfig) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) URL(java.net.URL) Test(org.junit.Test)

Example 25 with DeploymentConfiguration

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

the class TemplateInitializerTest method createService.

@Override
protected VaadinService createService() {
    VaadinService service = mock(VaadinService.class);
    DeploymentConfiguration configuration = mock(DeploymentConfiguration.class);
    when(configuration.isProductionMode()).thenReturn(false);
    when(service.getDeploymentConfiguration()).thenReturn(configuration);
    return service;
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Aggregations

DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)25 VaadinService (com.vaadin.flow.server.VaadinService)8 Test (org.junit.Test)7 URL (java.net.URL)6 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)4 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)4 Before (org.junit.Before)4 VaadinServlet (com.vaadin.flow.server.VaadinServlet)3 VaadinServletService (com.vaadin.flow.server.VaadinServletService)3 VaadinSession (com.vaadin.flow.server.VaadinSession)3 Properties (java.util.Properties)3 ServletConfig (javax.servlet.ServletConfig)3 ServletException (javax.servlet.ServletException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 UI (com.vaadin.flow.component.UI)2 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)2 AbstractDeploymentConfiguration (com.vaadin.flow.server.AbstractDeploymentConfiguration)2 ServiceException (com.vaadin.flow.server.ServiceException)2 VaadinUriResolver (com.vaadin.flow.shared.VaadinUriResolver)2 Conf (com.vaadin.flow.uitest.servlet.CustomDeploymentConfiguration.Conf)2