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