Search in sources :

Example 11 with SessionListeners

use of io.undertow.server.session.SessionListeners in project wildfly by wildfly.

the class DistributableSessionTestCase method setAttribute.

@Test
public void setAttribute() {
    when(this.session.getMetaData()).thenReturn(this.metaData);
    when(this.metaData.isNew()).thenReturn(false);
    io.undertow.server.session.Session session = new DistributableSession(this.manager, this.session, this.config, this.batch, this.closeTask);
    String name = "name";
    Integer value = 1;
    SessionManager<Map<String, Object>, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionAttributes attributes = mock(SessionAttributes.class);
    SessionListener listener = mock(SessionListener.class);
    SessionListeners listeners = new SessionListeners();
    listeners.addSessionListener(listener);
    Object expected = new Object();
    when(this.session.getAttributes()).thenReturn(attributes);
    when(attributes.setAttribute(name, value)).thenReturn(expected);
    when(this.manager.getSessionListeners()).thenReturn(listeners);
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    Object result = session.setAttribute(name, value);
    assertSame(expected, result);
    verify(listener, never()).attributeAdded(session, name, value);
    verify(listener).attributeUpdated(session, name, value, expected);
    verify(listener, never()).attributeRemoved(same(session), same(name), any());
    verify(context).close();
    verify(this.session, never()).close();
    verify(this.closeTask, never()).accept(null);
    reset(context);
    doThrow(IllegalStateException.class).when(this.session).getAttributes();
    assertThrows(IllegalStateException.class, () -> session.setAttribute(name, value));
    verify(context).close();
    verify(this.session).close();
    verify(this.closeTask).accept(null);
}
Also used : BatchContext(org.wildfly.clustering.ee.BatchContext) Batch(org.wildfly.clustering.ee.Batch) SessionListeners(io.undertow.server.session.SessionListeners) SessionAttributes(org.wildfly.clustering.web.session.SessionAttributes) SessionListener(io.undertow.server.session.SessionListener) OptionMap(org.xnio.OptionMap) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

SessionListeners (io.undertow.server.session.SessionListeners)11 Map (java.util.Map)11 Batch (org.wildfly.clustering.ee.Batch)11 SessionListener (io.undertow.server.session.SessionListener)10 Test (org.junit.Test)10 BatchContext (org.wildfly.clustering.ee.BatchContext)10 HashMap (java.util.HashMap)9 SessionAttributes (org.wildfly.clustering.web.session.SessionAttributes)9 OptionMap (org.xnio.OptionMap)9 HttpServerExchange (io.undertow.server.HttpServerExchange)4 SessionConfig (io.undertow.server.session.SessionConfig)2 Duration (java.time.Duration)2 Instant (java.time.Instant)2 ImmutableSessionMetaData (org.wildfly.clustering.web.session.ImmutableSessionMetaData)2 SessionExpirationListener (org.wildfly.clustering.web.session.SessionExpirationListener)2 SessionMetaData (org.wildfly.clustering.web.session.SessionMetaData)2 Session (io.undertow.server.session.Session)1 Deployment (io.undertow.servlet.api.Deployment)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 ThreadSetupHandler (io.undertow.servlet.api.ThreadSetupHandler)1