Search in sources :

Example 26 with WebSession

use of org.springframework.web.server.WebSession in project spring-framework by spring-projects.

the class InMemoryWebSessionStoreTests method retrieveExpiredSession.

@Test
public void retrieveExpiredSession() {
    WebSession session = this.store.createWebSession().block();
    assertThat(session).isNotNull();
    session.getAttributes().put("foo", "bar");
    session.save().block();
    String id = session.getId();
    WebSession retrieved = this.store.retrieveSession(id).block();
    assertThat(retrieved).isNotNull();
    assertThat(retrieved).isSameAs(session);
    // Fast-forward 31 minutes
    this.store.setClock(Clock.offset(this.store.getClock(), Duration.ofMinutes(31)));
    WebSession retrievedAgain = this.store.retrieveSession(id).block();
    assertThat(retrievedAgain).isNull();
}
Also used : WebSession(org.springframework.web.server.WebSession) Test(org.junit.jupiter.api.Test)

Example 27 with WebSession

use of org.springframework.web.server.WebSession in project spring-framework by spring-projects.

the class InMemoryWebSessionStoreTests method insertSession.

private WebSession insertSession() {
    WebSession session = this.store.createWebSession().block();
    assertThat(session).isNotNull();
    session.start();
    session.save().block();
    return session;
}
Also used : WebSession(org.springframework.web.server.WebSession)

Example 28 with WebSession

use of org.springframework.web.server.WebSession in project spring-framework by spring-projects.

the class DefaultWebSessionManager method createSession.

protected Mono<WebSession> createSession(ServerWebExchange exchange) {
    String sessionId = UUID.randomUUID().toString();
    WebSession session = new DefaultWebSession(sessionId, getClock());
    return Mono.just(session);
}
Also used : WebSession(org.springframework.web.server.WebSession)

Example 29 with WebSession

use of org.springframework.web.server.WebSession in project spring-framework by spring-projects.

the class DefaultWebSessionManagerTests method startSessionImplicitly.

@Test
public void startSessionImplicitly() throws Exception {
    this.idResolver.setIdsToResolve(Collections.emptyList());
    WebSession session = this.manager.getSession(this.exchange).block();
    session.getAttributes().put("foo", "bar");
    session.save();
    assertNotNull(this.idResolver.getSavedId());
}
Also used : WebSession(org.springframework.web.server.WebSession) Test(org.junit.Test)

Example 30 with WebSession

use of org.springframework.web.server.WebSession in project spring-framework by spring-projects.

the class DefaultWebSessionManagerTests method multipleSessions.

@Test
public void multipleSessions() throws Exception {
    DefaultWebSession existing = new DefaultWebSession("3", Clock.systemDefaultZone());
    this.manager.getSessionStore().storeSession(existing);
    this.idResolver.setIdsToResolve(Arrays.asList("1", "2", "3"));
    WebSession actual = this.manager.getSession(this.exchange).block();
    assertSame(existing, actual);
}
Also used : WebSession(org.springframework.web.server.WebSession) Test(org.junit.Test)

Aggregations

WebSession (org.springframework.web.server.WebSession)53 Test (org.junit.Test)24 Test (org.junit.jupiter.api.Test)24 Method (java.lang.reflect.Method)3 TestBean (org.springframework.beans.testfixture.beans.TestBean)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 HandlerMethod (org.springframework.web.method.HandlerMethod)3 SyncInvocableHandlerMethod (org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod)3 ServerWebExchange (org.springframework.web.server.ServerWebExchange)3 Mono (reactor.core.publisher.Mono)3 Instant (java.time.Instant)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 BDDMockito.given (org.mockito.BDDMockito.given)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.spy (org.mockito.Mockito.spy)2 Mockito.times (org.mockito.Mockito.times)2 Mockito.verify (org.mockito.Mockito.verify)2