Search in sources :

Example 41 with ApplicationConfiguration

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

the class DefaultDeploymentConfigurationTest method isXsrfProtectionEnabled_valueIsSetViaParentOnly_valueIsTakenFromParent.

@Test
public void isXsrfProtectionEnabled_valueIsSetViaParentOnly_valueIsTakenFromParent() {
    ApplicationConfiguration appConfig = setupAppConfig();
    Mockito.when(appConfig.isXsrfProtectionEnabled()).thenReturn(true);
    // Note: application configuration doesn't contain production mode
    // parameter !
    Assert.assertNull(appConfig.getStringProperty(InitParameters.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, null));
    DefaultDeploymentConfiguration config = createDeploymentConfig(appConfig, new Properties());
    Assert.assertTrue(config.isXsrfProtectionEnabled());
    Assert.assertTrue(config.getProperties().isEmpty());
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 42 with ApplicationConfiguration

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

the class DefaultDeploymentConfigurationTest method setupAppConfig.

private ApplicationConfiguration setupAppConfig() {
    ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(appConfig.getContext()).thenReturn(context);
    return appConfig;
}
Also used : ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 43 with ApplicationConfiguration

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

the class DefaultDeploymentConfigurationTest method isProductionMode_productionModeIsSetViaParentOnly_productionModeIsTakenFromParent.

@Test
public void isProductionMode_productionModeIsSetViaParentOnly_productionModeIsTakenFromParent() {
    ApplicationConfiguration appConfig = setupAppConfig();
    Mockito.when(appConfig.isProductionMode()).thenReturn(true);
    // Note: application configuration doesn't contain production mode
    // parameter !
    Assert.assertNull(appConfig.getStringProperty(InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE, null));
    DefaultDeploymentConfiguration config = createDeploymentConfig(appConfig, new Properties());
    Assert.assertTrue(config.isProductionMode());
    Assert.assertTrue(config.getProperties().isEmpty());
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 44 with ApplicationConfiguration

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

the class DeploymentConfigurationFactoryTest method mockTokenFileViaContextParam.

private VaadinConfig mockTokenFileViaContextParam(String content) throws IOException {
    VaadinContext context = Mockito.mock(VaadinContext.class);
    VaadinConfig config = Mockito.mock(VaadinConfig.class);
    ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(config.getConfigParameterNames()).thenReturn(Collections.enumeration(Collections.singleton(FrontendUtils.PARAM_TOKEN_FILE)));
    Mockito.when(context.getContextParameterNames()).thenReturn(Collections.emptyEnumeration());
    Mockito.when(config.getVaadinContext()).thenReturn(context);
    File tmpFile = temporaryFolder.newFile();
    Files.write(tmpFile.toPath(), Collections.singletonList(content));
    Mockito.when(context.getContextParameter(FrontendUtils.PARAM_TOKEN_FILE)).thenReturn(tmpFile.getPath());
    Mockito.when(config.getConfigParameter(FrontendUtils.PARAM_TOKEN_FILE)).thenReturn(tmpFile.toString());
    Mockito.when(context.getAttribute(Mockito.eq(ApplicationConfiguration.class), Mockito.any())).thenReturn(appConfig);
    return config;
}
Also used : ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) File(java.io.File)

Example 45 with ApplicationConfiguration

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

the class BootstrapHandlerTest method enableViteFeature.

private void enableViteFeature(boolean productionMode) throws IOException {
    VaadinContext vaadinContext = Mockito.mock(VaadinContext.class);
    final Lookup lookup = Mockito.mock(Lookup.class);
    ResourceProvider resourceProvider = Mockito.mock(ResourceProvider.class);
    Mockito.when(lookup.lookup(ResourceProvider.class)).thenReturn(resourceProvider);
    Mockito.when(resourceProvider.getClientResourceAsStream("META-INF/resources/" + ApplicationConstants.CLIENT_ENGINE_PATH + "/compile.properties")).thenReturn(getClass().getClassLoader().getResourceAsStream("META-INF/resources/" + ApplicationConstants.CLIENT_ENGINE_PATH + "/compile.properties"));
    Mockito.when(vaadinContext.getAttribute(Lookup.class)).thenReturn(lookup);
    service.setContext(vaadinContext);
    ApplicationConfiguration configuration = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(configuration.isProductionMode()).thenReturn(false);
    Mockito.when(configuration.getJavaResourceFolder()).thenReturn(tmpDir.getRoot());
    Mockito.when(lookup.lookup(ApplicationConfiguration.class)).thenReturn(configuration);
    Mockito.when(vaadinContext.getAttribute(ApplicationConfiguration.class)).thenReturn(configuration);
    Mockito.when(vaadinContext.getAttribute(Mockito.eq(ApplicationConfiguration.class), Mockito.any())).thenReturn(configuration);
    final FeatureFlags featureFlags = FeatureFlags.get(testUI.getSession().getService().getContext());
    Mockito.when(vaadinContext.getAttribute(FeatureFlags.class)).thenReturn(featureFlags);
    featureFlags.setEnabled(FeatureFlags.VITE.getId(), true);
    Mockito.when(configuration.isProductionMode()).thenReturn(productionMode);
}
Also used : ResourceProvider(com.vaadin.flow.di.ResourceProvider) Lookup(com.vaadin.flow.di.Lookup) FeatureFlags(com.vaadin.experimental.FeatureFlags) 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