use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class VaadinSessionTest method threadLocalsWhenDeserializing.
@Test
@Category(SlowTests.class)
public void threadLocalsWhenDeserializing() throws Exception {
ApplicationConfiguration configuration = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(configuration.isDevModeSessionSerializationEnabled()).thenReturn(true);
mockServlet.getServletContext().setAttribute(ApplicationConfiguration.class.getName(), configuration);
VaadinSession.setCurrent(session);
session.lock();
SerializationPushConnection pc = new SerializationPushConnection(ui);
Assert.assertEquals("Session should be set when instance is created", session, pc.session);
ui.getPushConfiguration().setPushMode(PushMode.MANUAL);
ui.getInternals().setPushConnection(pc);
int uiId = ui.getUIId();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(session);
out.close();
session.unlock();
CurrentInstance.clearAll();
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
VaadinSession deserializedSession = (VaadinSession) in.readObject();
Assert.assertNull("Current session shouldn't leak from deserialisation", VaadinSession.getCurrent());
Assert.assertNotSame("Should get a new session", session, deserializedSession);
// Restore http session and service instance so the session can be
// locked
deserializedSession.refreshTransients(mockWrappedSession, mockService);
deserializedSession.lock();
UI deserializedUi = deserializedSession.getUIById(uiId);
SerializationPushConnection deserializedPc = (SerializationPushConnection) deserializedUi.getInternals().getPushConnection();
Assert.assertEquals("Current session should be available in SerializationTestLabel.readObject", deserializedSession, deserializedPc.session);
deserializedSession.unlock();
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class PushAtmosphereHandlerTest method setup.
@Before
public void setup() throws IOException {
request = Mockito.mock(AtmosphereRequest.class);
response = Mockito.mock(AtmosphereResponse.class);
printWriter = Mockito.mock(PrintWriter.class);
Mockito.when(response.getWriter()).thenReturn(printWriter);
resource = Mockito.mock(AtmosphereResource.class);
Mockito.when(resource.getRequest()).thenReturn(request);
Mockito.when(resource.getResponse()).thenReturn(response);
VaadinContext context = new MockVaadinContext();
ApplicationConfiguration config = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(config.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(config.getContext()).thenReturn(context);
VaadinServletService service = new VaadinServletService(null, new DefaultDeploymentConfiguration(config, getClass(), new Properties()));
PushHandler handler = new PushHandler(service);
atmosphereHandler = new PushAtmosphereHandler();
atmosphereHandler.setPushHandler(handler);
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class DefaultDeploymentConfigurationTest method useV14Bootstrap_v14ModeIsSetViaParentOnly_v14ModeIsTakenFromParent.
@Test
public void useV14Bootstrap_v14ModeIsSetViaParentOnly_v14ModeIsTakenFromParent() {
ApplicationConfiguration appConfig = setupAppConfig();
Mockito.when(appConfig.useV14Bootstrap()).thenReturn(true);
// Note: application configuration doesn't contain production mode
// parameter !
Assert.assertNull(appConfig.getStringProperty(InitParameters.SERVLET_PARAMETER_USE_V14_BOOTSTRAP, null));
DefaultDeploymentConfiguration config = createDeploymentConfig(appConfig, new Properties());
Assert.assertTrue(config.useV14Bootstrap());
Assert.assertTrue(config.getProperties().isEmpty());
}
use of com.vaadin.flow.server.startup.ApplicationConfiguration in project flow by vaadin.
the class DefaultDeploymentConfigurationTest method testGetSystemProperty.
@Test
public void testGetSystemProperty() {
String value = "value";
String prop = "prop";
System.setProperty(DefaultDeploymentConfigurationTest.class.getPackage().getName() + '.' + prop, value);
Properties initParameters = new Properties();
ApplicationConfiguration appConfig = setupAppConfig();
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
DefaultDeploymentConfiguration config = new DefaultDeploymentConfiguration(appConfig, DefaultDeploymentConfigurationTest.class, initParameters);
assertEquals(value, config.getSystemProperty(prop));
}
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());
}
Aggregations