Search in sources :

Example 31 with MapSession

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

the class JdbcOperationsSessionRepositoryTests method saveUpdatedLastAccessedTime.

@Test
public void saveUpdatedLastAccessedTime() {
    JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", new MapSession());
    session.setLastAccessedTime(Instant.now());
    this.repository.save(session);
    assertThat(session.isNew()).isFalse();
    assertPropagationRequiresNew();
    verify(this.jdbcOperations, times(1)).update(and(startsWith("UPDATE"), contains("LAST_ACCESS_TIME")), isA(PreparedStatementSetter.class));
}
Also used : BatchPreparedStatementSetter(org.springframework.jdbc.core.BatchPreparedStatementSetter) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) MapSession(org.springframework.session.MapSession) Test(org.junit.Test)

Example 32 with MapSession

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

the class JdbcOperationsSessionRepositoryTests method saveUnchanged.

@Test
public void saveUnchanged() {
    JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", new MapSession());
    this.repository.save(session);
    assertThat(session.isNew()).isFalse();
    verifyZeroInteractions(this.jdbcOperations);
}
Also used : MapSession(org.springframework.session.MapSession) Test(org.junit.Test)

Example 33 with MapSession

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

the class JdbcOperationsSessionRepositoryTests method saveUpdatedAttributes.

@Test
public void saveUpdatedAttributes() {
    JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", new MapSession());
    session.setAttribute("testName", "testValue");
    this.repository.save(session);
    assertThat(session.isNew()).isFalse();
    assertPropagationRequiresNew();
    verify(this.jdbcOperations, times(1)).update(and(startsWith("UPDATE"), contains("ATTRIBUTE_BYTES")), isA(PreparedStatementSetter.class));
}
Also used : BatchPreparedStatementSetter(org.springframework.jdbc.core.BatchPreparedStatementSetter) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) MapSession(org.springframework.session.MapSession) Test(org.junit.Test)

Example 34 with MapSession

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

the class ReactiveRedisOperationsSessionRepositoryTests method saveSetAttribute.

@Test
public void saveSetAttribute() {
    given(this.redisOperations.opsForHash()).willReturn(this.hashOperations);
    given(this.hashOperations.putAll(anyString(), this.delta.capture())).willReturn(Mono.just(true));
    given(this.redisOperations.expire(anyString(), any())).willReturn(Mono.just(true));
    String attrName = "attrName";
    ReactiveRedisOperationsSessionRepository.RedisSession session = this.repository.new RedisSession(new MapSession());
    session.setAttribute(attrName, "attrValue");
    Mono<Void> result = this.repository.save(session);
    StepVerifier.create(result).expectNextMatches(predicate -> {
        assertThat(this.delta.getAllValues().get(0)).isEqualTo(map(RedisOperationsSessionRepository.getSessionAttrNameKey(attrName), session.getAttribute(attrName)));
        return true;
    });
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MapSession(org.springframework.session.MapSession) Test(org.junit.Test)

Example 35 with MapSession

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

the class ReactiveRedisOperationsSessionRepositoryTests method delete.

@Test
public void delete() {
    given(this.redisOperations.delete(anyString())).willReturn(Mono.just(1L));
    ReactiveRedisOperationsSessionRepository.RedisSession session = this.repository.new RedisSession(new MapSession());
    Mono<Void> result = this.repository.deleteById(session.getId());
    StepVerifier.create(result).expectNextMatches(predicate -> {
        assertThat(result).isEqualTo(1);
        return true;
    });
}
Also used : 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