Search in sources :

Example 6 with ImmutableSession

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

the class UndertowHttpSessionFactoryTestCase method getLastAccessedTime.

@Test
public void getLastAccessedTime() {
    ImmutableSession session = mock(ImmutableSession.class);
    ServletContext context = mock(ServletContext.class);
    SessionMetaData metaData = mock(SessionMetaData.class);
    Instant now = Instant.now();
    when(session.getMetaData()).thenReturn(metaData);
    when(metaData.getLastAccessStartTime()).thenReturn(now);
    long result = this.factory.createHttpSession(session, context).getLastAccessedTime();
    assertEquals(now.toEpochMilli(), result);
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) Instant(java.time.Instant) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 7 with ImmutableSession

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

the class UndertowHttpSessionFactoryTestCase method removeAttribute.

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

Example 8 with ImmutableSession

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

the class OOBSessionTestCase method isNew.

@Test
public void isNew() {
    Batcher<Batch> batcher = mock(Batcher.class);
    Batch batch = mock(Batch.class);
    when(this.manager.getBatcher()).thenReturn(batcher);
    when(batcher.createBatch()).thenReturn(batch);
    when(this.manager.readSession(this.id)).thenReturn(null);
    Assert.assertThrows(IllegalStateException.class, this.session.getMetaData()::isNew);
    verify(batch).close();
    reset(batch);
    ImmutableSession session = mock(ImmutableSession.class);
    ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
    boolean expected = true;
    when(this.manager.readSession(this.id)).thenReturn(session);
    when(session.getMetaData()).thenReturn(metaData);
    when(metaData.isNew()).thenReturn(expected);
    boolean result = this.session.getMetaData().isNew();
    Assert.assertEquals(expected, result);
    verify(batch).close();
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Batch(org.wildfly.clustering.ee.Batch) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) Test(org.junit.Test)

Example 9 with ImmutableSession

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

the class OOBSessionTestCase method getCreationTime.

@Test
public void getCreationTime() {
    Batcher<Batch> batcher = mock(Batcher.class);
    Batch batch = mock(Batch.class);
    when(this.manager.getBatcher()).thenReturn(batcher);
    when(batcher.createBatch()).thenReturn(batch);
    when(this.manager.readSession(this.id)).thenReturn(null);
    Assert.assertThrows(IllegalStateException.class, this.session.getMetaData()::getCreationTime);
    verify(batch).close();
    reset(batch);
    ImmutableSession session = mock(ImmutableSession.class);
    ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
    Instant expected = Instant.now();
    when(this.manager.readSession(this.id)).thenReturn(session);
    when(session.getMetaData()).thenReturn(metaData);
    when(metaData.getCreationTime()).thenReturn(expected);
    Instant result = this.session.getMetaData().getCreationTime();
    Assert.assertSame(expected, result);
    verify(batch).close();
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Batch(org.wildfly.clustering.ee.Batch) Instant(java.time.Instant) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) Test(org.junit.Test)

Example 10 with ImmutableSession

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

the class OOBSessionTestCase method getLastAccessStartTime.

@Test
public void getLastAccessStartTime() {
    Batcher<Batch> batcher = mock(Batcher.class);
    Batch batch = mock(Batch.class);
    when(this.manager.getBatcher()).thenReturn(batcher);
    when(batcher.createBatch()).thenReturn(batch);
    when(this.manager.readSession(this.id)).thenReturn(null);
    Assert.assertThrows(IllegalStateException.class, this.session.getMetaData()::getLastAccessStartTime);
    verify(batch).close();
    reset(batch);
    ImmutableSession session = mock(ImmutableSession.class);
    ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
    Instant expected = Instant.now();
    when(this.manager.readSession(this.id)).thenReturn(session);
    when(session.getMetaData()).thenReturn(metaData);
    when(metaData.getLastAccessStartTime()).thenReturn(expected);
    Instant result = this.session.getMetaData().getLastAccessStartTime();
    Assert.assertSame(expected, result);
    verify(batch).close();
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Batch(org.wildfly.clustering.ee.Batch) Instant(java.time.Instant) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) 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