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