Search in sources :

Example 1 with SessionMetaData

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

the class DistributableSessionTestCase method getMaxInactiveInterval.

@Test
public void getMaxInactiveInterval() {
    this.validate(session -> session.getMaxInactiveInterval());
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionMetaData metaData = mock(SessionMetaData.class);
    long expected = 3600L;
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    when(this.session.getMetaData()).thenReturn(metaData);
    when(metaData.getMaxInactiveInterval()).thenReturn(Duration.ofSeconds(expected));
    long result = this.adapter.getMaxInactiveInterval();
    assertEquals(expected, result);
    verify(context).close();
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 2 with SessionMetaData

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

the class DistributableSessionTestCase method setMaxInactiveInterval.

@Test
public void setMaxInactiveInterval() {
    int interval = 3600;
    this.validate(session -> session.setMaxInactiveInterval(interval));
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionMetaData metaData = mock(SessionMetaData.class);
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    when(this.session.getMetaData()).thenReturn(metaData);
    this.adapter.setMaxInactiveInterval(interval);
    verify(metaData).setMaxInactiveInterval(Duration.ofSeconds(interval));
    verify(context).close();
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 3 with SessionMetaData

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

the class DistributableSessionTestCase method getLastAccessedTime.

@Test
public void getLastAccessedTime() {
    this.validate(session -> session.getLastAccessedTime());
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionMetaData metaData = mock(SessionMetaData.class);
    Instant now = Instant.now();
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    when(this.session.getMetaData()).thenReturn(metaData);
    when(metaData.getLastAccessedTime()).thenReturn(now);
    long result = this.adapter.getLastAccessedTime();
    assertEquals(now.toEpochMilli(), result);
    verify(context).close();
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) Instant(java.time.Instant) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 4 with SessionMetaData

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

the class DistributableSessionTestCase method getCreationTime.

@Test
public void getCreationTime() {
    this.validate(session -> session.getCreationTime());
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionMetaData metaData = mock(SessionMetaData.class);
    Instant now = Instant.now();
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    when(this.session.getMetaData()).thenReturn(metaData);
    when(metaData.getCreationTime()).thenReturn(now);
    long result = this.adapter.getCreationTime();
    assertEquals(now.toEpochMilli(), result);
    verify(context).close();
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) Instant(java.time.Instant) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 5 with SessionMetaData

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

the class DistributableSessionTestCase method changeSessionId.

@Test
public void changeSessionId() {
    HttpServerExchange exchange = new HttpServerExchange(null);
    SessionConfig config = mock(SessionConfig.class);
    this.validate(session -> session.changeSessionId(exchange, config));
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    Session<LocalSessionContext> session = mock(Session.class);
    SessionAttributes oldAttributes = mock(SessionAttributes.class);
    SessionAttributes newAttributes = mock(SessionAttributes.class);
    SessionMetaData oldMetaData = mock(SessionMetaData.class);
    SessionMetaData newMetaData = mock(SessionMetaData.class);
    LocalSessionContext oldContext = mock(LocalSessionContext.class);
    LocalSessionContext newContext = mock(LocalSessionContext.class);
    SessionListener listener = mock(SessionListener.class);
    SessionListeners listeners = new SessionListeners();
    listeners.addSessionListener(listener);
    String oldSessionId = "old";
    String newSessionId = "new";
    String name = "name";
    Object value = new Object();
    Instant now = Instant.now();
    Duration interval = Duration.ofSeconds(10L);
    AuthenticatedSession authenticatedSession = new AuthenticatedSession(null, null);
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    when(manager.createIdentifier()).thenReturn(newSessionId);
    when(manager.createSession(newSessionId)).thenReturn(session);
    when(this.session.getAttributes()).thenReturn(oldAttributes);
    when(this.session.getMetaData()).thenReturn(oldMetaData);
    when(session.getAttributes()).thenReturn(newAttributes);
    when(session.getMetaData()).thenReturn(newMetaData);
    when(oldAttributes.getAttributeNames()).thenReturn(Collections.singleton(name));
    when(oldAttributes.getAttribute(name)).thenReturn(value);
    when(newAttributes.setAttribute(name, value)).thenReturn(null);
    when(oldMetaData.getLastAccessedTime()).thenReturn(now);
    when(oldMetaData.getMaxInactiveInterval()).thenReturn(interval);
    when(this.session.getId()).thenReturn(oldSessionId);
    when(session.getId()).thenReturn(newSessionId);
    when(this.session.getLocalContext()).thenReturn(oldContext);
    when(session.getLocalContext()).thenReturn(newContext);
    when(oldContext.getAuthenticatedSession()).thenReturn(authenticatedSession);
    when(this.manager.getSessionListeners()).thenReturn(listeners);
    String result = this.adapter.changeSessionId(exchange, config);
    assertSame(newSessionId, result);
    verify(newMetaData).setLastAccessedTime(now);
    verify(newMetaData).setMaxInactiveInterval(interval);
    verify(config).setSessionId(exchange, newSessionId);
    verify(newContext).setAuthenticatedSession(same(authenticatedSession));
    verify(listener).sessionIdChanged(this.adapter, oldSessionId);
    verify(context).close();
}
Also used : AuthenticatedSession(io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession) Instant(java.time.Instant) SessionConfig(io.undertow.server.session.SessionConfig) BatchContext(org.wildfly.clustering.ee.BatchContext) Duration(java.time.Duration) HttpServerExchange(io.undertow.server.HttpServerExchange) Batch(org.wildfly.clustering.ee.Batch) SessionListeners(io.undertow.server.session.SessionListeners) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) SessionAttributes(org.wildfly.clustering.web.session.SessionAttributes) SessionListener(io.undertow.server.session.SessionListener) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 Batch (org.wildfly.clustering.ee.Batch)5 BatchContext (org.wildfly.clustering.ee.BatchContext)5 SessionMetaData (org.wildfly.clustering.web.session.SessionMetaData)5 Instant (java.time.Instant)3 AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 SessionConfig (io.undertow.server.session.SessionConfig)1 SessionListener (io.undertow.server.session.SessionListener)1 SessionListeners (io.undertow.server.session.SessionListeners)1 Duration (java.time.Duration)1 SessionAttributes (org.wildfly.clustering.web.session.SessionAttributes)1