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