Search in sources :

Example 26 with MapSession

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

the class RedisOperationsSessionRepositoryTests method onMessageCreatedCustomSerializer.

// gh-309
@Test
public void onMessageCreatedCustomSerializer() throws Exception {
    MapSession session = this.cached;
    byte[] pattern = "".getBytes("UTF-8");
    byte[] body = new byte[0];
    String channel = "spring:session:event:created:" + session.getId();
    given(this.defaultSerializer.deserialize(body)).willReturn(new HashMap<String, Object>());
    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());
    verify(this.defaultSerializer).deserialize(body);
}
Also used : DefaultMessage(org.springframework.data.redis.connection.DefaultMessage) MapSession(org.springframework.session.MapSession) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 27 with MapSession

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

the class RedisOperationsSessionRepositoryTests method setup.

@Before
public void setup() {
    this.redisRepository = new RedisOperationsSessionRepository(this.redisOperations);
    this.redisRepository.setDefaultSerializer(this.defaultSerializer);
    this.cached = new MapSession();
    this.cached.setId("session-id");
    this.cached.setCreationTime(Instant.ofEpochMilli(1404360000000L));
    this.cached.setLastAccessedTime(Instant.ofEpochMilli(1404360000000L));
}
Also used : MapSession(org.springframework.session.MapSession) Before(org.junit.Before)

Example 28 with MapSession

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

the class AbstractHazelcastRepositoryITests method createAndDestroySession.

@Test
public void createAndDestroySession() {
    HazelcastSession sessionToSave = this.repository.createSession();
    String sessionId = sessionToSave.getId();
    IMap<String, MapSession> hazelcastMap = this.hazelcast.getMap(HazelcastSessionRepository.DEFAULT_SESSION_MAP_NAME);
    assertThat(hazelcastMap.size()).isEqualTo(0);
    this.repository.save(sessionToSave);
    assertThat(hazelcastMap.size()).isEqualTo(1);
    assertThat(hazelcastMap.get(sessionId)).isEqualTo(sessionToSave);
    this.repository.deleteById(sessionId);
    assertThat(hazelcastMap.size()).isEqualTo(0);
}
Also used : MapSession(org.springframework.session.MapSession) HazelcastSession(org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession) Test(org.junit.Test)

Example 29 with MapSession

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

the class EnableSpringHttpSessionCustomCookieSerializerTests method usesWrite.

@Test
public void usesWrite() throws Exception {
    given(this.sessionRepository.findById(anyString())).willReturn(new MapSession());
    this.sessionRepositoryFilter.doFilter(this.request, this.response, new MockFilterChain() {

        @Override
        public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
            ((HttpServletRequest) request).getSession();
            super.doFilter(request, response);
        }
    });
    verify(this.cookieSerializer).writeCookieValue(any(CookieValue.class));
}
Also used : ServletException(javax.servlet.ServletException) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ServletResponse(javax.servlet.ServletResponse) CookieValue(org.springframework.session.web.http.CookieSerializer.CookieValue) MapSession(org.springframework.session.MapSession) IOException(java.io.IOException) MockFilterChain(org.springframework.mock.web.MockFilterChain) Test(org.junit.Test)

Example 30 with MapSession

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

the class JdbcOperationsSessionRepositoryTests method getSessionFound.

@Test
@SuppressWarnings("unchecked")
public void getSessionFound() {
    Session saved = this.repository.new JdbcSession("primaryKey", new MapSession());
    saved.setAttribute("savedName", "savedValue");
    given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class), isA(ResultSetExtractor.class))).willReturn(Collections.singletonList(saved));
    JdbcOperationsSessionRepository.JdbcSession session = this.repository.findById(saved.getId());
    assertThat(session.getId()).isEqualTo(saved.getId());
    assertThat(session.isNew()).isFalse();
    assertThat(session.<String>getAttribute("savedName")).isEqualTo("savedValue");
    assertPropagationRequiresNew();
    verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class), isA(ResultSetExtractor.class));
}
Also used : ResultSetExtractor(org.springframework.jdbc.core.ResultSetExtractor) BatchPreparedStatementSetter(org.springframework.jdbc.core.BatchPreparedStatementSetter) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) MapSession(org.springframework.session.MapSession) Session(org.springframework.session.Session) MapSession(org.springframework.session.MapSession) Test(org.junit.Test)

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