Search in sources :

Example 1 with WebSession

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

the class DefaultWebSessionManagerTests method existingSessionIsExpired.

@Test
public void existingSessionIsExpired() throws Exception {
    Clock clock = Clock.systemDefaultZone();
    DefaultWebSession existing = new DefaultWebSession("1", clock);
    existing.start();
    existing.setLastAccessTime(Instant.now(clock).minus(Duration.ofMinutes(31)));
    this.manager.getSessionStore().storeSession(existing);
    this.idResolver.setIdsToResolve(Collections.singletonList("1"));
    WebSession actual = this.manager.getSession(this.exchange).block();
    assertNotSame(existing, actual);
}
Also used : WebSession(org.springframework.web.server.WebSession) Clock(java.time.Clock) Test(org.junit.Test)

Example 2 with WebSession

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

the class DefaultWebSessionManagerTests method getSessionWithoutStarting.

@Test
public void getSessionWithoutStarting() throws Exception {
    this.idResolver.setIdsToResolve(Collections.emptyList());
    WebSession session = this.manager.getSession(this.exchange).block();
    session.save();
    assertFalse(session.isStarted());
    assertFalse(session.isExpired());
    assertNull(this.idResolver.getSavedId());
    assertNull(this.manager.getSessionStore().retrieveSession(session.getId()).block());
}
Also used : WebSession(org.springframework.web.server.WebSession) Test(org.junit.Test)

Example 3 with WebSession

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

the class DefaultWebSessionManagerTests method startSessionExplicitly.

@Test
public void startSessionExplicitly() throws Exception {
    this.idResolver.setIdsToResolve(Collections.emptyList());
    WebSession session = this.manager.getSession(this.exchange).block();
    session.start();
    session.save();
    String id = session.getId();
    assertNotNull(this.idResolver.getSavedId());
    assertEquals(id, this.idResolver.getSavedId());
    assertSame(session, this.manager.getSessionStore().retrieveSession(id).block());
}
Also used : WebSession(org.springframework.web.server.WebSession) Test(org.junit.Test)

Example 4 with WebSession

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

the class DefaultServerRequestTests method session.

@Test
public void session() throws Exception {
    WebSession session = mock(WebSession.class);
    when(mockExchange.getSession()).thenReturn(Mono.just(session));
    assertEquals(session, defaultRequest.session().block());
}
Also used : WebSession(org.springframework.web.server.WebSession) Test(org.junit.Test)

Example 5 with WebSession

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

the class SpringSessionWebSessionStoreTests method createSessionWhenNoAttributesThenNotStarted.

@Test
public void createSessionWhenNoAttributesThenNotStarted() {
    WebSession createdWebSession = this.webSessionStore.createWebSession().block();
    assertThat(createdWebSession.isStarted()).isFalse();
}
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