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