use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class PropertyDeploymentConfigurationTest method reuseDevServer_valueIsProvidedViaParentOnly_propertyIsSetToAnotherValue_valueFromParentIsReturnedViaAPI.
@Test
public void reuseDevServer_valueIsProvidedViaParentOnly_propertyIsSetToAnotherValue_valueFromParentIsReturnedViaAPI() {
ApplicationConfiguration appConfig = mockAppConfig();
// The property value is provided via API
Mockito.when(appConfig.reuseDevServer()).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_REUSE_DEV_SERVER)));
Mockito.when(appConfig.getStringProperty(InitParameters.SERVLET_PARAMETER_REUSE_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.reuseDevServer());
Assert.assertTrue(config.getInitParameters().containsKey(InitParameters.SERVLET_PARAMETER_REUSE_DEV_SERVER));
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class PropertyDeploymentConfigurationTest method isProductionMode_modeIsProvidedViaParentOnly_valueFromParentIsReturned.
@Test
public void isProductionMode_modeIsProvidedViaParentOnly_valueFromParentIsReturned() {
ApplicationConfiguration appConfig = mockAppConfig();
Mockito.when(appConfig.isProductionMode()).thenReturn(true);
PropertyDeploymentConfiguration config = createConfiguration(appConfig, new Properties());
Assert.assertTrue(config.isProductionMode());
// there is no any property
Assert.assertTrue(config.getInitParameters().isEmpty());
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class PropertyDeploymentConfigurationTest method getApplicationProperty_propertyIsDefinedInPropertiesAndParent_valueFromPropertiesIsReturned.
@Test
public void getApplicationProperty_propertyIsDefinedInPropertiesAndParent_valueFromPropertiesIsReturned() {
ApplicationConfiguration appConfig = mockAppConfig();
Mockito.when(appConfig.getStringProperty("foo", null)).thenReturn("bar");
Properties properties = new Properties();
properties.put("foo", "baz");
PropertyDeploymentConfiguration configuration = createConfiguration(appConfig, properties);
Assert.assertEquals("baz", configuration.getApplicationProperty("foo"));
Assert.assertEquals(properties, configuration.getInitParameters());
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class PropertyDeploymentConfigurationTest method isXsrfProtectionEnabled_valueIsProvidedViaParentOnly_propertyIsSetToAnotherValue_valueFromParentIsReturnedViaAPI.
@Test
public void isXsrfProtectionEnabled_valueIsProvidedViaParentOnly_propertyIsSetToAnotherValue_valueFromParentIsReturnedViaAPI() {
ApplicationConfiguration appConfig = mockAppConfig();
// The property value is provided via API
Mockito.when(appConfig.isXsrfProtectionEnabled()).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_DISABLE_XSRF_PROTECTION)));
Mockito.when(appConfig.getStringProperty(InitParameters.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, null)).thenReturn(Boolean.TRUE.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.isXsrfProtectionEnabled());
Assert.assertTrue(config.getInitParameters().containsKey(InitParameters.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION));
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class UidlRequestHandlerTest method writeSessionExpired.
@Test
public void writeSessionExpired() throws Exception {
ApplicationConfiguration config = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(config.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(config.getBuildFolder()).thenReturn(".");
VaadinContext context = new MockVaadinContext();
Mockito.when(config.getContext()).thenReturn(context);
VaadinService service = new VaadinServletService(null, new DefaultDeploymentConfiguration(config, getClass(), new Properties()));
when(request.getService()).thenReturn(service);
when(request.getParameter(ApplicationConstants.REQUEST_TYPE_PARAMETER)).thenReturn(RequestType.UIDL.getIdentifier());
boolean result = handler.handleSessionExpired(request, response);
Assert.assertTrue("Result should be true", result);
String responseContent = CommunicationUtil.getStringWhenWriteBytesOffsetLength(outputStream);
// response shouldn't contain async
Assert.assertEquals("Invalid response", "for(;;);[{\"meta\":{\"sessionExpired\":true}}]", responseContent);
}
Aggregations