Search in sources :

Example 31 with ImmutableSession

use of org.wildfly.clustering.web.session.ImmutableSession in project wildfly by wildfly.

the class UndertowHttpSessionFactoryTestCase method getServletContext.

@Test
public void getServletContext() {
    ImmutableSession session = mock(ImmutableSession.class);
    ServletContext context = mock(ServletContext.class);
    ServletContext result = this.factory.createHttpSession(session, context).getServletContext();
    assertSame(context, result);
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 32 with ImmutableSession

use of org.wildfly.clustering.web.session.ImmutableSession in project wildfly by wildfly.

the class UndertowHttpSessionFactoryTestCase method getAttributeNames.

@Test
public void getAttributeNames() {
    ImmutableSession session = mock(ImmutableSession.class);
    ServletContext context = mock(ServletContext.class);
    SessionAttributes attributes = mock(SessionAttributes.class);
    Set<String> expected = new TreeSet<>();
    when(session.getAttributes()).thenReturn(attributes);
    when(attributes.getAttributeNames()).thenReturn(expected);
    Enumeration<String> result = this.factory.createHttpSession(session, context).getAttributeNames();
    assertEquals(new ArrayList<>(expected), Collections.list(result));
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) TreeSet(java.util.TreeSet) SessionAttributes(org.wildfly.clustering.web.session.SessionAttributes) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 33 with ImmutableSession

use of org.wildfly.clustering.web.session.ImmutableSession in project wildfly by wildfly.

the class UndertowHttpSessionFactoryTestCase method getMaxInactiveInterval.

@Test
public void getMaxInactiveInterval() {
    ImmutableSession session = mock(ImmutableSession.class);
    ServletContext context = mock(ServletContext.class);
    SessionMetaData metaData = mock(SessionMetaData.class);
    Duration interval = Duration.of(100L, ChronoUnit.SECONDS);
    when(session.getMetaData()).thenReturn(metaData);
    when(metaData.getMaxInactiveInterval()).thenReturn(interval);
    int result = this.factory.createHttpSession(session, context).getMaxInactiveInterval();
    assertEquals(interval.getSeconds(), result);
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) ServletContext(javax.servlet.ServletContext) Duration(java.time.Duration) Test(org.junit.Test)

Example 34 with ImmutableSession

use of org.wildfly.clustering.web.session.ImmutableSession in project wildfly by wildfly.

the class UndertowHttpSessionFactoryTestCase method getAttribute.

@Test
public void getAttribute() {
    ImmutableSession session = mock(ImmutableSession.class);
    ServletContext context = mock(ServletContext.class);
    SessionAttributes attributes = mock(SessionAttributes.class);
    String name = "name";
    Object expected = new Object();
    when(session.getAttributes()).thenReturn(attributes);
    when(attributes.getAttribute(name)).thenReturn(expected);
    Object result = this.factory.createHttpSession(session, context).getAttribute(name);
    assertSame(expected, result);
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) SessionAttributes(org.wildfly.clustering.web.session.SessionAttributes) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 35 with ImmutableSession

use of org.wildfly.clustering.web.session.ImmutableSession in project wildfly by wildfly.

the class UndertowSessionExpirationListenerTestCase method sessionExpired.

@Test
public void sessionExpired() {
    Deployment deployment = mock(Deployment.class);
    UndertowSessionManager manager = mock(UndertowSessionManager.class);
    SessionManager<Map<String, Object>, Batch> delegateManager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    Batch batch = mock(Batch.class);
    SessionListener listener = mock(SessionListener.class);
    ImmutableSession session = mock(ImmutableSession.class);
    ImmutableSessionAttributes attributes = mock(ImmutableSessionAttributes.class);
    ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
    ArgumentCaptor<Session> capturedSession = ArgumentCaptor.forClass(Session.class);
    String expectedSessionId = "session";
    SessionListeners listeners = new SessionListeners();
    listeners.addSessionListener(listener);
    SessionExpirationListener expirationListener = new UndertowSessionExpirationListener(deployment, listeners);
    when(deployment.getSessionManager()).thenReturn(manager);
    when(manager.getSessionManager()).thenReturn(delegateManager);
    when(delegateManager.getBatcher()).thenReturn(batcher);
    when(batcher.suspendBatch()).thenReturn(batch);
    when(session.getId()).thenReturn(expectedSessionId);
    when(session.getAttributes()).thenReturn(attributes);
    when(attributes.getAttributeNames()).thenReturn(Collections.emptySet());
    when(session.getMetaData()).thenReturn(metaData);
    when(metaData.getCreationTime()).thenReturn(Instant.now());
    when(metaData.getLastAccessStartTime()).thenReturn(Instant.now());
    when(metaData.getMaxInactiveInterval()).thenReturn(Duration.ZERO);
    expirationListener.sessionExpired(session);
    verify(batcher).suspendBatch();
    verify(listener).sessionDestroyed(capturedSession.capture(), isNull(), same(SessionListener.SessionDestroyedReason.TIMEOUT));
    verify(batcher).resumeBatch(batch);
    assertSame(expectedSessionId, capturedSession.getValue().getId());
    assertSame(manager, capturedSession.getValue().getSessionManager());
}
Also used : ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Deployment(io.undertow.servlet.api.Deployment) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) SessionExpirationListener(org.wildfly.clustering.web.session.SessionExpirationListener) Batch(org.wildfly.clustering.ee.Batch) SessionListeners(io.undertow.server.session.SessionListeners) SessionListener(io.undertow.server.session.SessionListener) Map(java.util.Map) Session(io.undertow.server.session.Session) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Test(org.junit.Test)

Aggregations

ImmutableSession (org.wildfly.clustering.web.session.ImmutableSession)35 Test (org.junit.Test)27 Batch (org.wildfly.clustering.ee.Batch)13 ImmutableSessionMetaData (org.wildfly.clustering.web.session.ImmutableSessionMetaData)13 ServletContext (javax.servlet.ServletContext)12 ImmutableSessionAttributes (org.wildfly.clustering.web.session.ImmutableSessionAttributes)9 Map (java.util.Map)7 Instant (java.time.Instant)5 SessionExpirationListener (org.wildfly.clustering.web.session.SessionExpirationListener)4 SessionMetaData (org.wildfly.clustering.web.session.SessionMetaData)4 Session (io.undertow.server.session.Session)2 Duration (java.time.Duration)2 SimpleImmutableSession (org.wildfly.clustering.web.cache.session.SimpleImmutableSession)2 ValidSession (org.wildfly.clustering.web.cache.session.ValidSession)2 SessionAttributes (org.wildfly.clustering.web.session.SessionAttributes)2 SessionListener (io.undertow.server.session.SessionListener)1 SessionListeners (io.undertow.server.session.SessionListeners)1 Deployment (io.undertow.servlet.api.Deployment)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1