use of org.wildfly.clustering.web.session.SessionAttributes in project wildfly by wildfly.
the class DistributableSessionTestCase method setNullAttribute.
@Test
public void setNullAttribute() {
String name = "name";
Object value = null;
this.validate(session -> session.setAttribute(name, value));
SessionManager<LocalSessionContext, 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.removeAttribute(name)).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 = this.adapter.setAttribute(name, value);
assertSame(expected, result);
verify(listener, never()).attributeAdded(this.adapter, name, value);
verify(listener, never()).attributeUpdated(same(this.adapter), same(name), same(value), any());
verify(listener).attributeRemoved(this.adapter, name, expected);
verify(context).close();
}
use of org.wildfly.clustering.web.session.SessionAttributes in project wildfly by wildfly.
the class DistributableSessionTestCase method setNewAttribute.
@Test
public void setNewAttribute() {
String name = "name";
Integer value = Integer.valueOf(1);
this.validate(session -> session.setAttribute(name, value));
SessionManager<LocalSessionContext, 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 = null;
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 = this.adapter.setAttribute(name, value);
assertSame(expected, result);
verify(listener).attributeAdded(this.adapter, name, value);
verify(listener, never()).attributeUpdated(same(this.adapter), same(name), same(value), any());
verify(listener, never()).attributeRemoved(same(this.adapter), same(name), any());
verify(context).close();
}
use of org.wildfly.clustering.web.session.SessionAttributes in project wildfly by wildfly.
the class DistributableSessionTestCase method getAuthenticatedSessionAttribute.
@Test
public void getAuthenticatedSessionAttribute() {
String name = CachedAuthenticatedSessionHandler.class.getName() + ".AuthenticatedSession";
this.validate(session -> session.getAttribute(name));
SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
Batcher<Batch> batcher = mock(Batcher.class);
BatchContext context = mock(BatchContext.class);
SessionAttributes attributes = mock(SessionAttributes.class);
Account account = mock(Account.class);
AuthenticatedSession auth = new AuthenticatedSession(account, HttpServletRequest.FORM_AUTH);
when(this.manager.getSessionManager()).thenReturn(manager);
when(manager.getBatcher()).thenReturn(batcher);
when(batcher.resumeBatch(this.batch)).thenReturn(context);
when(this.session.getAttributes()).thenReturn(attributes);
when(attributes.getAttribute(name)).thenReturn(auth);
AuthenticatedSession result = (AuthenticatedSession) this.adapter.getAttribute(name);
assertSame(account, result.getAccount());
assertSame(HttpServletRequest.FORM_AUTH, result.getMechanism());
verify(context).close();
reset(context);
LocalSessionContext localContext = mock(LocalSessionContext.class);
AuthenticatedSession expected = new AuthenticatedSession(account, HttpServletRequest.BASIC_AUTH);
when(attributes.getAttribute(name)).thenReturn(null);
when(this.session.getLocalContext()).thenReturn(localContext);
when(localContext.getAuthenticatedSession()).thenReturn(expected);
result = (AuthenticatedSession) this.adapter.getAttribute(name);
assertSame(expected, result);
verify(context).close();
}
use of org.wildfly.clustering.web.session.SessionAttributes in project wildfly by wildfly.
the class DistributableSessionTestCase method setSameAttribute.
@Test
public void setSameAttribute() {
String name = "name";
Integer value = Integer.valueOf(1);
this.validate(session -> session.setAttribute(name, value));
SessionManager<LocalSessionContext, 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 = value;
when(this.manager.getSessionManager()).thenReturn(manager);
when(manager.getBatcher()).thenReturn(batcher);
when(batcher.resumeBatch(this.batch)).thenReturn(context);
when(this.session.getAttributes()).thenReturn(attributes);
when(attributes.setAttribute(name, value)).thenReturn(expected);
when(this.manager.getSessionListeners()).thenReturn(listeners);
Object result = this.adapter.setAttribute(name, value);
assertSame(expected, result);
verify(listener, never()).attributeAdded(this.adapter, name, value);
verify(listener, never()).attributeUpdated(same(this.adapter), same(name), same(value), any());
verify(listener, never()).attributeRemoved(same(this.adapter), same(name), any());
verify(context).close();
}
use of org.wildfly.clustering.web.session.SessionAttributes in project wildfly by wildfly.
the class DistributableSessionTestCase method getAttribute.
@Test
public void getAttribute() {
String name = "name";
this.validate(session -> session.getAttribute(name));
SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
Batcher<Batch> batcher = mock(Batcher.class);
BatchContext context = mock(BatchContext.class);
SessionAttributes attributes = mock(SessionAttributes.class);
Object expected = new Object();
when(this.session.getAttributes()).thenReturn(attributes);
when(attributes.getAttribute(name)).thenReturn(expected);
when(this.manager.getSessionManager()).thenReturn(manager);
when(manager.getBatcher()).thenReturn(batcher);
when(batcher.resumeBatch(this.batch)).thenReturn(context);
Object result = this.adapter.getAttribute(name);
assertSame(expected, result);
verify(context).close();
}
Aggregations