Search in sources :

Example 16 with IServerSession

use of org.eclipse.scout.rt.server.IServerSession in project scout.rt by eclipse.

the class ServerSessionCacheTest method testMultipleHttpSessionsMultipleSessionIds.

/**
 * If there are multiple HTTP sessions, and multiple sessionIds, the sessions should be different.
 */
@Test
public void testMultipleHttpSessionsMultipleSessionIds() {
    TestHttpSession httpSession1 = new TestHttpSession();
    TestHttpSession httpSession2 = new TestHttpSession();
    IServerSessionLifecycleHandler handler1 = new TestServerSessionLifecycleHandler("id1");
    IServerSessionLifecycleHandler handler2 = new TestServerSessionLifecycleHandler("id2");
    IServerSession session1 = BEANS.get(ServerSessionCache.class).getOrCreate(handler1, httpSession1);
    IServerSession session2 = BEANS.get(ServerSessionCache.class).getOrCreate(handler2, httpSession2);
    assertNotSame(session1, session2);
}
Also used : IServerSession(org.eclipse.scout.rt.server.IServerSession) TestHttpSession(org.eclipse.scout.rt.testing.server.TestHttpSession) Test(org.junit.Test)

Example 17 with IServerSession

use of org.eclipse.scout.rt.server.IServerSession in project scout.rt by eclipse.

the class ServerSessionCacheTest method testMultipleHttpSessions.

/**
 * If there are multiple HTTP sessions (can happen, if many requests are created in parallel for the same sessionId),
 * but a single sessionId, a new server session should only be created once.
 */
@Test
public void testMultipleHttpSessions() {
    TestHttpSession httpSession1 = new TestHttpSession();
    TestHttpSession httpSession2 = new TestHttpSession();
    IServerSessionLifecycleHandler handler = new TestServerSessionLifecycleHandler();
    IServerSession session1 = BEANS.get(ServerSessionCache.class).getOrCreate(handler, httpSession1);
    IServerSession session2 = BEANS.get(ServerSessionCache.class).getOrCreate(handler, httpSession2);
    assertSame(session1, session2);
}
Also used : IServerSession(org.eclipse.scout.rt.server.IServerSession) TestHttpSession(org.eclipse.scout.rt.testing.server.TestHttpSession) Test(org.junit.Test)

Example 18 with IServerSession

use of org.eclipse.scout.rt.server.IServerSession in project scout.rt by eclipse.

the class SessionFutureFilterTest method test.

@Test
public void test() {
    IServerSession session1 = mock(IServerSession.class);
    IServerSession session2 = mock(IServerSession.class);
    SessionFutureFilter filter = new SessionFutureFilter(session1);
    // Tests a Future of a job  without RunContext
    assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput())));
    // Tests a Future of a job  with RunContext
    assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(RunContexts.empty()))));
    // Tests a Future of a job  with ClientRunContext without session
    assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ServerRunContexts.empty()))));
    // Tests a Future of a job  with ClientRunContext with correct session
    assertTrue(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ServerRunContexts.empty().withSession(session1)))));
    // Tests a Future of a job  with ClientRunContext with wrong session
    assertFalse(filter.accept(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ServerRunContexts.empty().withSession(session2)))));
    // Test adaptable to the session
    assertSame(session1, filter.getAdapter(ISession.class));
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) SessionFutureFilter(org.eclipse.scout.rt.shared.job.filter.future.SessionFutureFilter) IServerSession(org.eclipse.scout.rt.server.IServerSession) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Test(org.junit.Test)

Aggregations

IServerSession (org.eclipse.scout.rt.server.IServerSession)18 Test (org.junit.Test)12 TestHttpSession (org.eclipse.scout.rt.testing.server.TestHttpSession)6 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)4 Subject (javax.security.auth.Subject)3 HttpSession (javax.servlet.http.HttpSession)3 ISession (org.eclipse.scout.rt.shared.ISession)3 InvocationHandler (java.lang.reflect.InvocationHandler)2 Method (java.lang.reflect.Method)2 WebMethod (javax.jws.WebMethod)2 BooleanHolder (org.eclipse.scout.rt.platform.holders.BooleanHolder)2 Holder (org.eclipse.scout.rt.platform.holders.Holder)2 ITransaction (org.eclipse.scout.rt.platform.transaction.ITransaction)2 IClientNotificationService (org.eclipse.scout.rt.shared.clientnotification.IClientNotificationService)2 UserAgent (org.eclipse.scout.rt.shared.ui.UserAgent)2 Principal (java.security.Principal)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 Locale (java.util.Locale)1 ClientNotificationDispatcher (org.eclipse.scout.rt.client.clientnotification.ClientNotificationDispatcher)1