Search in sources :

Example 6 with MapSession

use of org.springframework.session.MapSession in project spring-session by spring-projects.

the class RedisOperationsSessionRepositoryTests method changeRedisNamespace.

@Test
public void changeRedisNamespace() {
    String namespace = "foo:bar";
    this.redisRepository.setRedisKeyNamespace(namespace);
    RedisSession session = this.redisRepository.new RedisSession(new MapSession());
    session.setMaxInactiveInterval(Duration.ZERO);
    given(this.redisOperations.boundHashOps(anyString())).willReturn(this.boundHashOperations);
    given(this.redisOperations.boundSetOps(anyString())).willReturn(this.boundSetOperations);
    this.redisRepository.save(session);
    String id = session.getId();
    verify(this.redisOperations, atLeastOnce()).delete(namespace + ":sessions:expires:" + id);
    verify(this.redisOperations, never()).boundValueOps(namespace + ":sessions:expires:" + id);
}
Also used : RedisSession(org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MapSession(org.springframework.session.MapSession) Test(org.junit.Test)

Example 7 with MapSession

use of org.springframework.session.MapSession in project spring-session by spring-projects.

the class RedisOperationsSessionRepositoryTests method saveRemoveAttribute.

@Test
public void saveRemoveAttribute() {
    String attrName = "attrName";
    RedisSession session = this.redisRepository.new RedisSession(new MapSession());
    session.removeAttribute(attrName);
    given(this.redisOperations.boundHashOps(anyString())).willReturn(this.boundHashOperations);
    given(this.redisOperations.boundSetOps(anyString())).willReturn(this.boundSetOperations);
    given(this.redisOperations.boundValueOps(anyString())).willReturn(this.boundValueOperations);
    this.redisRepository.save(session);
    assertThat(getDelta()).isEqualTo(map(RedisOperationsSessionRepository.getSessionAttrNameKey(attrName), null));
}
Also used : RedisSession(org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MapSession(org.springframework.session.MapSession) Test(org.junit.Test)

Example 8 with MapSession

use of org.springframework.session.MapSession in project spring-session by spring-projects.

the class RedisOperationsSessionRepositoryTests method onMessageCreated.

@Test
public void onMessageCreated() throws Exception {
    MapSession session = this.cached;
    byte[] pattern = "".getBytes("UTF-8");
    String channel = "spring:session:event:created:" + session.getId();
    JdkSerializationRedisSerializer defaultSerailizer = new JdkSerializationRedisSerializer();
    this.redisRepository.setDefaultSerializer(defaultSerailizer);
    byte[] body = defaultSerailizer.serialize(new HashMap());
    DefaultMessage message = new DefaultMessage(channel.getBytes("UTF-8"), body);
    this.redisRepository.setApplicationEventPublisher(this.publisher);
    this.redisRepository.onMessage(message, pattern);
    verify(this.publisher).publishEvent(this.event.capture());
    assertThat(this.event.getValue().getSessionId()).isEqualTo(session.getId());
}
Also used : DefaultMessage(org.springframework.data.redis.connection.DefaultMessage) HashMap(java.util.HashMap) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) MapSession(org.springframework.session.MapSession) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with MapSession

use of org.springframework.session.MapSession in project spring-session by spring-projects.

the class EnableSpringHttpSessionCustomCookieSerializerTests method usesReadSessionIds.

@Test
public void usesReadSessionIds() throws Exception {
    String sessionId = "sessionId";
    given(this.cookieSerializer.readCookieValues(any(HttpServletRequest.class))).willReturn(Collections.singletonList(sessionId));
    given(this.sessionRepository.findById(anyString())).willReturn(new MapSession(sessionId));
    this.sessionRepositoryFilter.doFilter(this.request, this.response, this.chain);
    assertThat(getRequest().getRequestedSessionId()).isEqualTo(sessionId);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MapSession(org.springframework.session.MapSession) Test(org.junit.Test)

Example 10 with MapSession

use of org.springframework.session.MapSession in project spring-session by spring-projects.

the class SessionEventHttpSessionListenerAdapterTests method setup.

@Before
public void setup() {
    this.listener = new SessionEventHttpSessionListenerAdapter(Arrays.asList(this.listener1, this.listener2));
    this.listener.setServletContext(new MockServletContext());
    Session session = new MapSession();
    this.destroyed = new SessionDestroyedEvent(this, session);
    this.created = new SessionCreatedEvent(this, session);
}
Also used : SessionCreatedEvent(org.springframework.session.events.SessionCreatedEvent) MapSession(org.springframework.session.MapSession) SessionDestroyedEvent(org.springframework.session.events.SessionDestroyedEvent) MockServletContext(org.springframework.mock.web.MockServletContext) Session(org.springframework.session.Session) MapSession(org.springframework.session.MapSession) Before(org.junit.Before)

Aggregations

MapSession (org.springframework.session.MapSession)47 Test (org.junit.Test)37 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 RedisSession (org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession)7 HashMap (java.util.HashMap)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 MapSessionRepository (org.springframework.session.MapSessionRepository)6 IOException (java.io.IOException)5 Before (org.junit.Before)5 Session (org.springframework.session.Session)5 HazelcastSession (org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession)5 MapListener (com.hazelcast.map.listener.MapListener)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 Map (java.util.Map)3 BatchPreparedStatementSetter (org.springframework.jdbc.core.BatchPreparedStatementSetter)3 PreparedStatementSetter (org.springframework.jdbc.core.PreparedStatementSetter)3 DefaultMessage (org.springframework.data.redis.connection.DefaultMessage)2