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