Remove SpringSessionWebSessionManager

Spring's DefaultWebSessionManager now supports all the functionality
that is needed for Spring Session, so we only need to implement
WebSessionStore
This commit is contained in:
Rob Winch
2017-09-06 14:50:48 -05:00
parent 8e3371aed9
commit 36ab358d24
5 changed files with 64 additions and 402 deletions

View File

@@ -17,14 +17,16 @@ package org.springframework.session;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.web.server.session.SpringSessionWebSessionManager;
import org.springframework.session.web.server.session.SpringSessionWebSessionStore;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import org.springframework.web.server.session.DefaultWebSessionManager;
import org.springframework.web.server.session.WebSessionManager;
/**
* Wire up a {@link WebSessionManager} using a Reactive {@link ReactorSessionRepository} from the application context.
*
* @author Greg Turnquist
* @author Rob Winch
* @since 2.0
*
* @see EnableSpringWebSession
@@ -39,7 +41,10 @@ public class SpringWebSessionConfiguration {
* @return a configured {@link WebSessionManager} registered with a preconfigured name.
*/
@Bean(WebHttpHandlerBuilder.WEB_SESSION_MANAGER_BEAN_NAME)
public WebSessionManager webSessionManager(ReactorSessionRepository<?> repository) {
return new SpringSessionWebSessionManager(repository);
public WebSessionManager webSessionManager(ReactorSessionRepository<? extends Session> repository) {
SpringSessionWebSessionStore<? extends Session> sessionStore = new SpringSessionWebSessionStore<>(repository);
DefaultWebSessionManager manager = new DefaultWebSessionManager();
manager.setSessionStore(sessionStore);
return manager;
}
}

View File

@@ -1,173 +0,0 @@
/*
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.session.web.server.session;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.List;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.session.ReactorSessionRepository;
import org.springframework.session.Session;
import org.springframework.util.Assert;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
import org.springframework.web.server.session.CookieWebSessionIdResolver;
import org.springframework.web.server.session.WebSessionIdResolver;
import org.springframework.web.server.session.WebSessionManager;
import org.springframework.web.server.session.WebSessionStore;
/**
* The {@link WebSessionManager} implementation backed by
* {@link ReactorSessionRepository}.
*
* @author Rob Winch
* @since 2.0
*/
public class SpringSessionWebSessionManager implements WebSessionManager {
private final SpringSessionWebSessionStore<? extends Session> sessionStore;
private WebSessionIdResolver sessionIdResolver = new CookieWebSessionIdResolver();
private Clock clock = Clock.system(ZoneOffset.UTC);
public SpringSessionWebSessionManager(
ReactorSessionRepository<? extends Session> sessionRepository) {
this.sessionStore = new SpringSessionWebSessionStore<>(sessionRepository);
}
/**
* Return the configured {@link WebSessionIdResolver}.
* @return the configured {@link WebSessionIdResolver}
*/
private WebSessionIdResolver getSessionIdResolver() {
return this.sessionIdResolver;
}
/**
* Configure the id resolution strategy.
* <p>
* By default an instance of {@link CookieWebSessionIdResolver}.
* @param sessionIdResolver the resolver to use
*/
public void setSessionIdResolver(WebSessionIdResolver sessionIdResolver) {
Assert.notNull(sessionIdResolver, "WebSessionIdResolver is required.");
this.sessionIdResolver = sessionIdResolver;
}
/**
* Return the configured {@link WebSessionStore}.
* @return the configured {@link WebSessionStore}
*/
private WebSessionStore getSessionStore() {
return this.sessionStore;
}
/**
* Return the configured clock for session {@code lastAccessTime} calculations.
* @return the configured clock for session {@code lastAccessTime} calculations
*/
private Clock getClock() {
return this.clock;
}
/**
* Configure the {@link Clock} to use to set lastAccessTime on every created session
* and to calculate if it is expired.
* <p>
* This may be useful to align to different timezone or to set the clock back in a
* test, e.g. {@code Clock.offset(clock, Duration.ofMinutes(-31))} in order to
* simulate session expiration.
* <p>
* By default this is {@code Clock.system(ZoneOffset.UTC)}.
* @param clock the clock to use
*/
public void setClock(Clock clock) {
Assert.notNull(clock, "'clock' is required.");
this.clock = clock;
}
@Override
public Mono<WebSession> getSession(ServerWebExchange exchange) {
// @formatter:off
return Mono.defer(() ->
retrieveSession(exchange))
.flatMap(session -> removeSessionIfExpired(exchange, session))
.flatMap(session -> {
Instant lastAccessTime = Instant.now(getClock());
return this.sessionStore.setLastAccessedTime(session, lastAccessTime);
})
.switchIfEmpty(createSession(exchange))
.doOnNext(session -> exchange.getResponse().beforeCommit(session::save));
// @formatter:on
}
private Mono<WebSession> retrieveSession(ServerWebExchange exchange) {
// @formatter:off
return Flux.fromIterable(getSessionIdResolver().resolveSessionIds(exchange))
.concatMap(sessionId -> this.sessionStore.retrieveSession(sessionId, session -> saveSession(exchange, session)))
.cast(WebSession.class)
.next();
// @formatter:on
}
private Mono<WebSession> removeSessionIfExpired(ServerWebExchange exchange,
WebSession session) {
if (session.isExpired()) {
this.sessionIdResolver.expireSession(exchange);
return this.sessionStore.removeSession(session.getId()).then(Mono.empty());
}
return Mono.just(session);
}
private Mono<Void> saveSession(ServerWebExchange exchange, WebSession session) {
if (session.isExpired()) {
return Mono.error(new IllegalStateException(
"Sessions are checked for expiration and have their "
+ "lastAccessTime updated when first accessed during request processing. "
+ "However this session is expired meaning that maxIdleTime elapsed "
+ "before the call to session.save()."));
}
if (!session.isStarted()) {
return Mono.empty();
}
// Force explicit start
session.start();
if (hasNewSessionId(exchange, session)) {
this.sessionIdResolver.setSessionId(exchange, session.getId());
}
return this.sessionStore.storeSession(session);
}
private boolean hasNewSessionId(ServerWebExchange exchange, WebSession session) {
List<String> ids = getSessionIdResolver().resolveSessionIds(exchange);
return ids.isEmpty() || !session.getId().equals(ids.get(0));
}
private Mono<WebSession> createSession(ServerWebExchange exchange) {
return this.sessionStore.createSession(session -> saveSession(exchange, session));
}
}

View File

@@ -16,8 +16,10 @@
package org.springframework.session.web.server.session;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.AbstractCollection;
import java.util.AbstractMap;
import java.util.Collection;
@@ -27,7 +29,6 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import reactor.core.publisher.Mono;
@@ -47,28 +48,42 @@ import org.springframework.web.server.session.WebSessionStore;
* @author Rob Winch
* @since 2.0
*/
class SpringSessionWebSessionStore<S extends Session> implements WebSessionStore {
public class SpringSessionWebSessionStore<S extends Session> implements WebSessionStore {
private final ReactorSessionRepository<S> sessions;
SpringSessionWebSessionStore(ReactorSessionRepository<S> sessions) {
Assert.notNull(sessions, "sessions cannot be null");
this.sessions = sessions;
private Clock clock = Clock.system(ZoneOffset.UTC);
public SpringSessionWebSessionStore(ReactorSessionRepository<S> reactorSessionRepository) {
Assert.notNull(reactorSessionRepository, "reactorSessionRepository cannot be null");
this.sessions = reactorSessionRepository;
}
public Mono<WebSession> createSession(Function<WebSession, Mono<Void>> saveOperation) {
return this.sessions.createSession().map(session -> this.createSession(session, saveOperation));
/**
* Configure the {@link Clock} to use to set lastAccessTime on every created
* session and to calculate if it is expired.
* <p>This may be useful to align to different timezone or to set the clock
* back in a test, e.g. {@code Clock.offset(clock, Duration.ofMinutes(-31))}
* in order to simulate session expiration.
* <p>By default this is {@code Clock.system(ZoneId.of("GMT"))}.
* @param clock the clock to use
*/
public void setClock(Clock clock) {
Assert.notNull(clock, "clock cannot be null");
this.clock = clock;
}
public Mono<WebSession> setLastAccessedTime(WebSession session,
Instant lastAccessedTime) {
public Mono<WebSession> createWebSession() {
return this.sessions.createSession().map(this::createSession);
}
public Mono<WebSession> updateLastAccessTime(WebSession session) {
@SuppressWarnings("unchecked")
SpringSessionWebSession springSessionWebSession = (SpringSessionWebSession) session;
springSessionWebSession.session.setLastAccessedTime(lastAccessedTime);
springSessionWebSession.session.setLastAccessedTime(this.clock.instant());
return Mono.just(session);
}
@Override
public Mono<Void> storeSession(WebSession session) {
@SuppressWarnings("unchecked")
SpringSessionWebSession springWebSession = (SpringSessionWebSession) session;
@@ -77,24 +92,15 @@ class SpringSessionWebSessionStore<S extends Session> implements WebSessionStore
@Override
public Mono<WebSession> retrieveSession(String sessionId) {
return Mono.error(new UnsupportedOperationException("This method is not supported. Use retrieveSession(String,Function<WebSession, Mono<Void>>)"));
return this.sessions.findById(sessionId).map(this::existingSession);
}
public Mono<WebSession> retrieveSession(String sessionId, Function<WebSession, Mono<Void>> saveOperation) {
return this.sessions.findById(sessionId).map(session -> this.existingSession(session, saveOperation));
private SpringSessionWebSession createSession(S session) {
return new SpringSessionWebSession(session, State.NEW);
}
@Override
public Mono<Void> changeSessionId(String s, WebSession webSession) {
return storeSession(webSession);
}
private SpringSessionWebSession createSession(S session, Function<WebSession, Mono<Void>> saveOperation) {
return new SpringSessionWebSession(session, State.NEW, saveOperation);
}
private SpringSessionWebSession existingSession(S session, Function<WebSession, Mono<Void>> saveOperation) {
return new SpringSessionWebSession(session, State.STARTED, saveOperation);
private SpringSessionWebSession existingSession(S session) {
return new SpringSessionWebSession(session, State.STARTED);
}
@Override
@@ -254,14 +260,11 @@ class SpringSessionWebSessionStore<S extends Session> implements WebSessionStore
private AtomicReference<State> state = new AtomicReference<>();
private final Function<WebSession, Mono<Void>> saveOperation;
SpringSessionWebSession(S session, State state, Function<WebSession, Mono<Void>> saveOperation) {
SpringSessionWebSession(S session, State state) {
Assert.notNull(session, "session cannot be null");
this.session = session;
this.attributes = new SpringSessionMap(session);
this.state.set(state);
this.saveOperation = saveOperation;
}
@Override
@@ -272,7 +275,8 @@ class SpringSessionWebSessionStore<S extends Session> implements WebSessionStore
@Override
public Mono<Void> changeSessionId() {
return Mono.defer(() -> {
this.session.changeSessionId();
this.session
.changeSessionId();
return save();
});
}
@@ -296,7 +300,7 @@ class SpringSessionWebSessionStore<S extends Session> implements WebSessionStore
@Override
public Mono<Void> save() {
return this.saveOperation.apply(this);
return SpringSessionWebSessionStore.this.sessions.save(this.session);
}
@Override

View File

@@ -1,175 +0,0 @@
/*
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.session.web.server.session;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import org.springframework.http.HttpCookie;
import org.springframework.http.ResponseCookie;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.session.MapReactorSessionRepository;
import org.springframework.session.ReactorSessionRepository;
import org.springframework.session.Session;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
import org.springframework.web.server.i18n.LocaleContextResolver;
import org.springframework.web.server.session.WebSessionIdResolver;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link SpringSessionWebSessionManager}.
*
* @author Rob Winch
* @since 5.0
*/
@RunWith(MockitoJUnitRunner.class)
public class SpringSessionWebSessionManagerTests<S extends Session> {
@Mock
private ReactorSessionRepository<S> sessions;
@Mock
private WebSessionIdResolver resolver;
@Mock
private ServerCodecConfigurer serverCodecConfigurer;
@Mock
private LocaleContextResolver localeContextResolver;
@Mock
private S createSession;
@Mock
private S findByIdSession;
private Mono<S> createSessionMono;
private ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
private SpringSessionWebSessionManager manager;
@Before
public void setup() {
given(this.createSession.getId()).willReturn("createSession-id");
given(this.findByIdSession.getId()).willReturn("findByIdSession-id");
this.createSessionMono = Mono.just(this.createSession);
given(this.sessions.createSession()).willReturn(this.createSessionMono);
this.manager = new SpringSessionWebSessionManager(this.sessions);
this.manager.setSessionIdResolver(this.resolver);
}
@Test
public void getSessionWhenDefaultSessionIdResolverFoundSessionUsed() {
String findByIdSessionId = this.findByIdSession.getId();
this.exchange = MockServerHttpRequest.get("/")
.cookie(new HttpCookie("SESSION", findByIdSessionId)).toExchange();
this.manager = new SpringSessionWebSessionManager(this.sessions);
given(this.sessions.findById(findByIdSessionId))
.willReturn(Mono.just(this.findByIdSession));
WebSession webSession = this.manager.getSession(this.exchange).block();
assertThat(webSession.getId()).isEqualTo(findByIdSessionId);
verify(this.sessions).findById(findByIdSessionId);
}
@Test
public void getSessionWhenNewThenCreateSessionInvoked() {
WebSession webSession = this.manager.getSession(this.exchange).block();
assertThat(webSession.getId()).isEqualTo(this.createSession.getId());
verify(this.sessions).createSession();
}
@Test
public void getSessionWhenNewAndPutThenSetAttributeInvoked() {
String attrName = "attrName";
String attrValue = "attrValue";
WebSession webSession = this.manager.getSession(this.exchange).block();
webSession.getAttributes().put(attrName, attrValue);
verify(this.createSession).setAttribute(attrName, attrValue);
}
@Test
public void getSessionWhenInvalidIdThenCreateSessionInvoked() {
String invalidId = "invalid";
String createSessionId = this.createSession.getId();
given(this.sessions.findById(any())).willReturn(Mono.empty());
given(this.resolver.resolveSessionIds(this.exchange))
.willReturn(Collections.singletonList(invalidId));
WebSession webSession = this.manager.getSession(this.exchange).block();
assertThat(webSession.getId()).isEqualTo(createSessionId);
verify(this.sessions).findById(invalidId);
Mono<String> mono = Mono.just("toTest");
StepVerifier.create(mono).expectNoEvent(Duration.ZERO);
}
@Test
public void getSessionWhenValidIdThenFoundSessionUsed() {
String findByIdSessionId = this.findByIdSession.getId();
given(this.sessions.findById(findByIdSessionId))
.willReturn(Mono.just(this.findByIdSession));
given(this.resolver.resolveSessionIds(this.exchange))
.willReturn(Arrays.asList(findByIdSessionId));
WebSession webSession = this.manager.getSession(this.exchange).block();
assertThat(webSession.getId()).isEqualTo(findByIdSessionId);
verify(this.sessions).findById(findByIdSessionId);
}
@Test
public void commitWrites() {
MapReactorSessionRepository repository = new MapReactorSessionRepository();
this.manager = new SpringSessionWebSessionManager(repository);
Mono<Void> getSession = this.manager.getSession(this.exchange)
.doOnSuccess(session -> session.getAttributes().put("foo", "bar"))
.flatMap(webSession -> this.exchange.getResponse().setComplete());
StepVerifier.create(getSession)
.expectComplete()
.verify();
ResponseCookie sessionCookie = this.exchange.getResponse().getCookies()
.getFirst("SESSION");
assertThat(sessionCookie).isNotNull();
Session session = repository.findById(sessionCookie.getValue()).block();
assertThat(session).isNotNull();
assertThat(session.<String>getAttribute("foo")).isEqualTo("bar");
}
}

View File

@@ -20,7 +20,6 @@ import java.util.AbstractMap;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import org.junit.Before;
import org.junit.Test;
@@ -56,8 +55,6 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
@Mock
private S findByIdSession;
private Function<WebSession, Mono<Void>> saveOperation;
private SpringSessionWebSessionStore<S> webSessionStore;
@Before
@@ -76,7 +73,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
@Test
public void createSessionWhenNoAttributesThenNotStarted() {
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
assertThat(createdWebSession.isStarted()).isFalse();
@@ -86,7 +83,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
public void createSessionWhenAddAttributeThenStarted() {
given(this.createSession.getAttributeNames())
.willReturn(Collections.singleton("a"));
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
assertThat(createdWebSession.isStarted()).isTrue();
@@ -94,7 +91,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
@Test
public void createSessionWhenGetAttributesAndSizeThenDelegatesToCreateSession() {
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -109,7 +106,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
@Test
public void createSessionWhenGetAttributesAndIsEmptyThenDelegatesToCreateSession() {
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -124,7 +121,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
@Test
public void createSessionWhenGetAttributesAndContainsKeyAndNotStringThenFalse() {
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -134,7 +131,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
@Test
public void createSessionWhenGetAttributesAndContainsKeyAndNotFoundThenFalse() {
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -146,7 +143,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
public void createSessionWhenGetAttributesAndContainsKeyAndFoundThenTrue() {
given(this.createSession.getAttributeNames())
.willReturn(Collections.singleton("a"));
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -156,7 +153,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
@Test
public void createSessionWhenGetAttributesAndPutThenDelegatesToCreateSession() {
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -167,7 +164,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
@Test
public void createSessionWhenGetAttributesAndPutNullThenDelegatesToCreateSession() {
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -178,7 +175,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
@Test
public void createSessionWhenGetAttributesAndRemoveThenDelegatesToCreateSession() {
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -189,7 +186,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
@Test
public void createSessionWhenGetAttributesAndPutAllThenDelegatesToCreateSession() {
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -202,7 +199,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
public void createSessionWhenGetAttributesAndClearThenDelegatesToCreateSession() {
given(this.createSession.getAttributeNames())
.willReturn(Collections.singleton("a"));
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -215,7 +212,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
public void createSessionWhenGetAttributesAndKeySetThenDelegatesToCreateSession() {
given(this.createSession.getAttributeNames())
.willReturn(Collections.singleton("a"));
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -228,7 +225,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
given(this.createSession.getAttributeNames())
.willReturn(Collections.singleton("a"));
given(this.createSession.getAttribute("a")).willReturn("b");
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -243,7 +240,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
.willReturn(Collections.singleton(attrName));
String attrValue = "attrValue";
given(this.createSession.getAttribute(attrName)).willReturn(attrValue);
WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdWebSession = this.webSessionStore.createWebSession()
.block();
Map<String, Object> attributes = createdWebSession.getAttributes();
@@ -256,7 +253,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
@Test
public void storeSessionWhenInvokedThenSessionSaved() {
given(this.sessionRepository.save(this.createSession)).willReturn(Mono.empty());
WebSession createdSession = this.webSessionStore.createSession(this.saveOperation)
WebSession createdSession = this.webSessionStore.createWebSession()
.block();
this.webSessionStore.storeSession(createdSession).block();
@@ -268,7 +265,7 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
public void retrieveSessionThenStarted() {
String id = "id";
WebSession retrievedWebSession = this.webSessionStore
.retrieveSession(id, this.saveOperation).block();
.retrieveSession(id).block();
assertThat(retrievedWebSession.isStarted()).isTrue();
}
@@ -283,4 +280,8 @@ public class SpringSessionWebSessionStoreTests<S extends Session> {
verify(this.sessionRepository).delete(sessionId);
}
@Test(expected = IllegalArgumentException.class)
public void setClockWhenNullThenException() {
this.webSessionStore.setClock(null);
}
}