Search in sources :

Example 21 with ApplicationConfiguration

use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.

the class DefaultDeploymentConfigurationTest method isXsrfProtectionEnabled_valueIsSetViaParentOnlyAndViaParent_valueIsTakenFromParent.

@Test
public void isXsrfProtectionEnabled_valueIsSetViaParentOnlyAndViaParent_valueIsTakenFromParent() {
    ApplicationConfiguration appConfig = setupAppConfig();
    Mockito.when(appConfig.isXsrfProtectionEnabled()).thenReturn(false);
    Properties initParameters = new Properties();
    initParameters.setProperty(InitParameters.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, Boolean.FALSE.toString());
    DefaultDeploymentConfiguration config = createDeploymentConfig(appConfig, initParameters);
    // the deployment configuration parameter takes precedence over parent
    // config
    Assert.assertTrue(config.isXsrfProtectionEnabled());
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 22 with ApplicationConfiguration

use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.

the class DefaultDeploymentConfigurationTest method useV14Bootstrap_v14ModeIsSetViaParentOnlyAndViaParent_v14ModeIsTakenFromParent.

@Test
public void useV14Bootstrap_v14ModeIsSetViaParentOnlyAndViaParent_v14ModeIsTakenFromParent() {
    ApplicationConfiguration appConfig = setupAppConfig();
    Mockito.when(appConfig.useV14Bootstrap()).thenReturn(true);
    Properties initParameters = new Properties();
    initParameters.setProperty(InitParameters.SERVLET_PARAMETER_USE_V14_BOOTSTRAP, Boolean.TRUE.toString());
    DefaultDeploymentConfiguration config = createDeploymentConfig(appConfig, initParameters);
    // the deployment configuration parameter takes precedence over parent
    // config
    Assert.assertTrue(config.useV14Bootstrap());
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 23 with ApplicationConfiguration

use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.

the class CustomUIClassLoaderTest method createConfigurationMock.

private static DeploymentConfiguration createConfigurationMock() {
    Properties properties = new Properties();
    properties.put(InitParameters.UI_PARAMETER, MyUI.class.getName());
    VaadinContext context = new MockVaadinContext();
    ApplicationConfiguration config = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(config.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
    Mockito.when(config.getBuildFolder()).thenReturn(".");
    Mockito.when(config.getContext()).thenReturn(context);
    return new DefaultDeploymentConfiguration(config, CustomUIClassLoaderTest.class, properties);
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 24 with ApplicationConfiguration

use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.

the class DeploymentConfigurationFactoryTest method createInitParameters_fallbackChunkIsCreatedViaAppConfig_fallbackChunkObjectIsInInitParams.

@Test
public void createInitParameters_fallbackChunkIsCreatedViaAppConfig_fallbackChunkObjectIsInInitParams() throws IOException {
    ServletContext context = Mockito.mock(ServletContext.class);
    ServletConfig config = Mockito.mock(ServletConfig.class);
    ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(config.getServletContext()).thenReturn(context);
    Mockito.when(config.getInitParameterNames()).thenReturn(Collections.emptyEnumeration());
    Mockito.when(context.getAttribute(ApplicationConfiguration.class.getName())).thenReturn(appConfig);
    Mockito.when(appConfig.getFallbackChunk()).thenReturn(fallbackChunk);
    Properties properties = new DeploymentConfigurationFactory().createInitParameters(Object.class, new VaadinServletConfig(config));
    Object object = properties.get(DeploymentConfigurationFactory.FALLBACK_CHUNK);
    Assert.assertSame(fallbackChunk, object);
}
Also used : ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 25 with ApplicationConfiguration

use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.

the class DeploymentConfigurationFactoryTest method mockApplicationConfiguration.

private ApplicationConfiguration mockApplicationConfiguration() {
    VaadinContext context = new MockVaadinContext();
    ApplicationConfiguration configuration = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(configuration.enableDevServer()).thenReturn(true);
    Mockito.when(configuration.isProductionMode()).thenReturn(true);
    Mockito.when(configuration.useV14Bootstrap()).thenReturn(false);
    Mockito.when(configuration.getContext()).thenReturn(context);
    Mockito.when(configuration.getStringProperty(Mockito.anyString(), Mockito.anyString())).thenReturn(null);
    Mockito.when(configuration.isXsrfProtectionEnabled()).thenReturn(false);
    Mockito.when(configuration.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
    fallbackChunk = Mockito.mock(FallbackChunk.class);
    Mockito.when(configuration.getFallbackChunk()).thenReturn(fallbackChunk);
    return configuration;
}
Also used : FallbackChunk(com.vaadin.flow.server.frontend.FallbackChunk) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Aggregations

ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)61 Properties (java.util.Properties)39 Test (org.junit.Test)39 VaadinContext (com.vaadin.flow.server.VaadinContext)14 Lookup (com.vaadin.flow.di.Lookup)9 VaadinService (com.vaadin.flow.server.VaadinService)7 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)6 ServletContext (javax.servlet.ServletContext)5 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)4 VaadinServletService (com.vaadin.flow.server.VaadinServletService)4 VaadinSession (com.vaadin.flow.server.VaadinSession)4 File (java.io.File)4 Before (org.junit.Before)4 UI (com.vaadin.flow.component.UI)3 ResourceProvider (com.vaadin.flow.di.ResourceProvider)3 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)3 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2