Search in sources :

Example 36 with WebSession

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

the class DefaultWebSessionManagerTests method existingSession.

@Test
void existingSession() {
    String sessionId = this.updateSession.getId();
    given(this.sessionIdResolver.resolveSessionIds(this.exchange)).willReturn(Collections.singletonList(sessionId));
    WebSession actual = this.sessionManager.getSession(this.exchange).block();
    assertThat(actual).isNotNull();
    assertThat(actual.getId()).isEqualTo(sessionId);
}
Also used : WebSession(org.springframework.web.server.WebSession) Test(org.junit.jupiter.api.Test)

Example 37 with WebSession

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

the class DefaultWebSessionManagerTests method getSessionSaveWhenCreatedAndStartedThenSavesAndSetsId.

@Test
void getSessionSaveWhenCreatedAndStartedThenSavesAndSetsId() {
    given(this.sessionIdResolver.resolveSessionIds(this.exchange)).willReturn(Collections.emptyList());
    WebSession session = this.sessionManager.getSession(this.exchange).block();
    assertThat(session).isSameAs(this.createSession);
    String sessionId = this.createSession.getId();
    given(this.createSession.isStarted()).willReturn(true);
    this.exchange.getResponse().setComplete().block();
    verify(this.sessionStore).createWebSession();
    verify(this.sessionIdResolver).setSessionId(any(), eq(sessionId));
    verify(this.createSession).save();
}
Also used : WebSession(org.springframework.web.server.WebSession) Test(org.junit.jupiter.api.Test)

Example 38 with WebSession

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

the class DefaultWebSessionManagerTests method multipleSessionIds.

@Test
void multipleSessionIds() {
    List<String> ids = Arrays.asList("not-this", "not-that", this.updateSession.getId());
    given(this.sessionStore.retrieveSession("not-this")).willReturn(Mono.empty());
    given(this.sessionStore.retrieveSession("not-that")).willReturn(Mono.empty());
    given(this.sessionIdResolver.resolveSessionIds(this.exchange)).willReturn(ids);
    WebSession actual = this.sessionManager.getSession(this.exchange).block();
    assertThat(actual).isNotNull();
    assertThat(actual.getId()).isEqualTo(this.updateSession.getId());
}
Also used : WebSession(org.springframework.web.server.WebSession) Test(org.junit.jupiter.api.Test)

Example 39 with WebSession

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

the class InMemoryWebSessionStoreTests method sessionInvalidatedBeforeSave.

// SPR-17051
@Test
public void sessionInvalidatedBeforeSave() {
    // Request 1 creates session
    WebSession session1 = this.store.createWebSession().block();
    assertThat(session1).isNotNull();
    String id = session1.getId();
    session1.start();
    session1.save().block();
    // Request 2 retrieves session
    WebSession session2 = this.store.retrieveSession(id).block();
    assertThat(session2).isNotNull();
    assertThat(session2).isSameAs(session1);
    // Request 3 retrieves and invalidates
    WebSession session3 = this.store.retrieveSession(id).block();
    assertThat(session3).isNotNull();
    assertThat(session3).isSameAs(session1);
    session3.invalidate().block();
    // Request 2 saves session after invalidated
    session2.save().block();
    // Session should not be present
    WebSession session4 = this.store.retrieveSession(id).block();
    assertThat(session4).isNull();
}
Also used : WebSession(org.springframework.web.server.WebSession) Test(org.junit.jupiter.api.Test)

Example 40 with WebSession

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

the class InMemoryWebSessionStoreTests method startsSessionImplicitly.

@Test
public void startsSessionImplicitly() {
    WebSession session = this.store.createWebSession().block();
    assertThat(session).isNotNull();
    session.start();
    session.getAttributes().put("foo", "bar");
    assertThat(session.isStarted()).isTrue();
}
Also used : WebSession(org.springframework.web.server.WebSession) Test(org.junit.jupiter.api.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