Search in sources :

Example 46 with ApplicationConfiguration

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

the class PropertyDeploymentConfigurationTest method isProductionMode_modeIsProvidedViaParentOnly_propertyIsSetToAnotherValue_valueFromParentIsReturnedViaAPI.

@Test
public void isProductionMode_modeIsProvidedViaParentOnly_propertyIsSetToAnotherValue_valueFromParentIsReturnedViaAPI() {
    ApplicationConfiguration appConfig = mockAppConfig();
    // The property value is provided via API
    Mockito.when(appConfig.isProductionMode()).thenReturn(true);
    // The property whose value is overridden above via API is different
    Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.enumeration(Collections.singleton(InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE)));
    Mockito.when(appConfig.getStringProperty(InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE, null)).thenReturn(Boolean.FALSE.toString());
    PropertyDeploymentConfiguration config = createConfiguration(appConfig, new Properties());
    // Several things are checked: the value from parent is used via API and
    // deployment configuration doesn't read the property directly even
    // though its "getInitParameters" method returns the property. Also
    // "getApplicationProperty" method checks the parent properties which
    // should not be taken into account here
    Assert.assertTrue(config.isProductionMode());
    Assert.assertTrue(config.getInitParameters().containsKey(InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE));
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 47 with ApplicationConfiguration

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

the class PropertyDeploymentConfigurationTest method enableDevServer_valueIsProvidedViaParentOnly_propertyIsSetToAnotherValue_valueFromParentIsReturnedViaAPI.

@Test
public void enableDevServer_valueIsProvidedViaParentOnly_propertyIsSetToAnotherValue_valueFromParentIsReturnedViaAPI() {
    ApplicationConfiguration appConfig = mockAppConfig();
    // The property value is provided via API
    Mockito.when(appConfig.enableDevServer()).thenReturn(true);
    // The property whose value is overridden above via API is different
    Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.enumeration(Collections.singleton(InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER)));
    Mockito.when(appConfig.getStringProperty(InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER, null)).thenReturn(Boolean.FALSE.toString());
    PropertyDeploymentConfiguration config = createConfiguration(appConfig, new Properties());
    // Several things are checked: the value from parent is used via API and
    // deployment configuration doesn't read the property directly even
    // though its "getInitParameters" method returns the property. Also
    // "getApplicationProperty" method checks the parent properties which
    // should not be taken into account here
    Assert.assertTrue(config.enableDevServer());
    Assert.assertTrue(config.getInitParameters().containsKey(InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER));
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 48 with ApplicationConfiguration

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

the class PropertyDeploymentConfigurationTest method getApplicationProperty_propertyIsDefinedInParentOnly_valueFromParentIsReturned.

@Test
public void getApplicationProperty_propertyIsDefinedInParentOnly_valueFromParentIsReturned() {
    ApplicationConfiguration appConfig = mockAppConfig();
    Mockito.when(appConfig.getStringProperty("foo", null)).thenReturn("bar");
    PropertyDeploymentConfiguration configuration = createConfiguration(appConfig, new Properties());
    Assert.assertEquals("bar", configuration.getApplicationProperty("foo"));
    // there is no any property
    Assert.assertTrue(configuration.getInitParameters().isEmpty());
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 49 with ApplicationConfiguration

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

the class PropertyDeploymentConfigurationTest method isPnpmEnabled_valueIsProvidedViaParentOnly_valueFromParentIsReturned.

@Test
public void isPnpmEnabled_valueIsProvidedViaParentOnly_valueFromParentIsReturned() {
    ApplicationConfiguration appConfig = mockAppConfig();
    Mockito.when(appConfig.isPnpmEnabled()).thenReturn(true);
    PropertyDeploymentConfiguration config = createConfiguration(appConfig, new Properties());
    Assert.assertTrue(config.isPnpmEnabled());
    // there is no any property
    Assert.assertTrue(config.getInitParameters().isEmpty());
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 50 with ApplicationConfiguration

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

the class PropertyDeploymentConfigurationTest method useV14Bootstrap_valueIsProvidedViaParentOnly_valueFromParentIsReturned.

@Test
public void useV14Bootstrap_valueIsProvidedViaParentOnly_valueFromParentIsReturned() {
    ApplicationConfiguration appConfig = mockAppConfig();
    Mockito.when(appConfig.useV14Bootstrap()).thenReturn(true);
    PropertyDeploymentConfiguration config = createConfiguration(appConfig, new Properties());
    Assert.assertTrue(config.useV14Bootstrap());
    // there is no any property
    Assert.assertTrue(config.getInitParameters().isEmpty());
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

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