Search in sources :

Example 1 with ApplicationConfiguration

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();
}
Also used : UI(com.vaadin.flow.component.UI) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) ObjectInputStream(java.io.ObjectInputStream) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 2 with ApplicationConfiguration

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);
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) AtmosphereResponse(org.atmosphere.cpr.AtmosphereResponse) MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) VaadinContext(com.vaadin.flow.server.VaadinContext) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) VaadinServletService(com.vaadin.flow.server.VaadinServletService) DefaultDeploymentConfiguration(com.vaadin.flow.server.DefaultDeploymentConfiguration) Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 3 with ApplicationConfiguration

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());
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 4 with ApplicationConfiguration

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));
}
Also used : Properties(java.util.Properties) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration) Test(org.junit.Test)

Example 5 with ApplicationConfiguration

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