From 36ab358d24881afcfa28ecf1d834ee2395364330 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Wed, 6 Sep 2017 14:50:48 -0500 Subject: [PATCH] Remove SpringSessionWebSessionManager Spring's DefaultWebSessionManager now supports all the functionality that is needed for Spring Session, so we only need to implement WebSessionStore --- .../SpringWebSessionConfiguration.java | 11 +- .../SpringSessionWebSessionManager.java | 173 ----------------- .../session/SpringSessionWebSessionStore.java | 66 +++---- .../SpringSessionWebSessionManagerTests.java | 175 ------------------ .../SpringSessionWebSessionStoreTests.java | 41 ++-- 5 files changed, 64 insertions(+), 402 deletions(-) delete mode 100644 spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionManager.java delete mode 100644 spring-session-core/src/test/java/org/springframework/session/web/server/session/SpringSessionWebSessionManagerTests.java diff --git a/spring-session-core/src/main/java/org/springframework/session/SpringWebSessionConfiguration.java b/spring-session-core/src/main/java/org/springframework/session/SpringWebSessionConfiguration.java index a0253521..e8e7210e 100644 --- a/spring-session-core/src/main/java/org/springframework/session/SpringWebSessionConfiguration.java +++ b/spring-session-core/src/main/java/org/springframework/session/SpringWebSessionConfiguration.java @@ -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 repository) { + SpringSessionWebSessionStore sessionStore = new SpringSessionWebSessionStore<>(repository); + DefaultWebSessionManager manager = new DefaultWebSessionManager(); + manager.setSessionStore(sessionStore); + return manager; } } diff --git a/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionManager.java b/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionManager.java deleted file mode 100644 index 2a55905b..00000000 --- a/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionManager.java +++ /dev/null @@ -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 sessionStore; - - private WebSessionIdResolver sessionIdResolver = new CookieWebSessionIdResolver(); - - private Clock clock = Clock.system(ZoneOffset.UTC); - - public SpringSessionWebSessionManager( - ReactorSessionRepository 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. - *

- * 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. - *

- * 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. - *

- * 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 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 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 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 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 ids = getSessionIdResolver().resolveSessionIds(exchange); - return ids.isEmpty() || !session.getId().equals(ids.get(0)); - } - - private Mono createSession(ServerWebExchange exchange) { - return this.sessionStore.createSession(session -> saveSession(exchange, session)); - } - -} diff --git a/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionStore.java b/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionStore.java index 73aad93b..b037a03d 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionStore.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionStore.java @@ -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 implements WebSessionStore { +public class SpringSessionWebSessionStore implements WebSessionStore { private final ReactorSessionRepository sessions; - SpringSessionWebSessionStore(ReactorSessionRepository sessions) { - Assert.notNull(sessions, "sessions cannot be null"); - this.sessions = sessions; + private Clock clock = Clock.system(ZoneOffset.UTC); + + public SpringSessionWebSessionStore(ReactorSessionRepository reactorSessionRepository) { + Assert.notNull(reactorSessionRepository, "reactorSessionRepository cannot be null"); + this.sessions = reactorSessionRepository; } - public Mono createSession(Function> 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. + *

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. + *

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 setLastAccessedTime(WebSession session, - Instant lastAccessedTime) { + public Mono createWebSession() { + return this.sessions.createSession().map(this::createSession); + } + + public Mono 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 storeSession(WebSession session) { @SuppressWarnings("unchecked") SpringSessionWebSession springWebSession = (SpringSessionWebSession) session; @@ -77,24 +92,15 @@ class SpringSessionWebSessionStore implements WebSessionStore @Override public Mono retrieveSession(String sessionId) { - return Mono.error(new UnsupportedOperationException("This method is not supported. Use retrieveSession(String,Function>)")); + return this.sessions.findById(sessionId).map(this::existingSession); } - public Mono retrieveSession(String sessionId, Function> 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 changeSessionId(String s, WebSession webSession) { - return storeSession(webSession); - } - - private SpringSessionWebSession createSession(S session, Function> saveOperation) { - return new SpringSessionWebSession(session, State.NEW, saveOperation); - } - - private SpringSessionWebSession existingSession(S session, Function> 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 implements WebSessionStore private AtomicReference state = new AtomicReference<>(); - private final Function> saveOperation; - - SpringSessionWebSession(S session, State state, Function> 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 implements WebSessionStore @Override public Mono changeSessionId() { return Mono.defer(() -> { - this.session.changeSessionId(); + this.session + .changeSessionId(); return save(); }); } @@ -296,7 +300,7 @@ class SpringSessionWebSessionStore implements WebSessionStore @Override public Mono save() { - return this.saveOperation.apply(this); + return SpringSessionWebSessionStore.this.sessions.save(this.session); } @Override diff --git a/spring-session-core/src/test/java/org/springframework/session/web/server/session/SpringSessionWebSessionManagerTests.java b/spring-session-core/src/test/java/org/springframework/session/web/server/session/SpringSessionWebSessionManagerTests.java deleted file mode 100644 index 5a4ae082..00000000 --- a/spring-session-core/src/test/java/org/springframework/session/web/server/session/SpringSessionWebSessionManagerTests.java +++ /dev/null @@ -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 { - - @Mock - private ReactorSessionRepository sessions; - - @Mock - private WebSessionIdResolver resolver; - - @Mock - private ServerCodecConfigurer serverCodecConfigurer; - - @Mock - private LocaleContextResolver localeContextResolver; - - @Mock - private S createSession; - - @Mock - private S findByIdSession; - - private Mono 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 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 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.getAttribute("foo")).isEqualTo("bar"); - } -} diff --git a/spring-session-core/src/test/java/org/springframework/session/web/server/session/SpringSessionWebSessionStoreTests.java b/spring-session-core/src/test/java/org/springframework/session/web/server/session/SpringSessionWebSessionStoreTests.java index 858227e1..8341a25d 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/server/session/SpringSessionWebSessionStoreTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/server/session/SpringSessionWebSessionStoreTests.java @@ -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 { @Mock private S findByIdSession; - private Function> saveOperation; - private SpringSessionWebSessionStore webSessionStore; @Before @@ -76,7 +73,7 @@ public class SpringSessionWebSessionStoreTests { @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 { 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 { @Test public void createSessionWhenGetAttributesAndSizeThenDelegatesToCreateSession() { - WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation) + WebSession createdWebSession = this.webSessionStore.createWebSession() .block(); Map attributes = createdWebSession.getAttributes(); @@ -109,7 +106,7 @@ public class SpringSessionWebSessionStoreTests { @Test public void createSessionWhenGetAttributesAndIsEmptyThenDelegatesToCreateSession() { - WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation) + WebSession createdWebSession = this.webSessionStore.createWebSession() .block(); Map attributes = createdWebSession.getAttributes(); @@ -124,7 +121,7 @@ public class SpringSessionWebSessionStoreTests { @Test public void createSessionWhenGetAttributesAndContainsKeyAndNotStringThenFalse() { - WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation) + WebSession createdWebSession = this.webSessionStore.createWebSession() .block(); Map attributes = createdWebSession.getAttributes(); @@ -134,7 +131,7 @@ public class SpringSessionWebSessionStoreTests { @Test public void createSessionWhenGetAttributesAndContainsKeyAndNotFoundThenFalse() { - WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation) + WebSession createdWebSession = this.webSessionStore.createWebSession() .block(); Map attributes = createdWebSession.getAttributes(); @@ -146,7 +143,7 @@ public class SpringSessionWebSessionStoreTests { 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 attributes = createdWebSession.getAttributes(); @@ -156,7 +153,7 @@ public class SpringSessionWebSessionStoreTests { @Test public void createSessionWhenGetAttributesAndPutThenDelegatesToCreateSession() { - WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation) + WebSession createdWebSession = this.webSessionStore.createWebSession() .block(); Map attributes = createdWebSession.getAttributes(); @@ -167,7 +164,7 @@ public class SpringSessionWebSessionStoreTests { @Test public void createSessionWhenGetAttributesAndPutNullThenDelegatesToCreateSession() { - WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation) + WebSession createdWebSession = this.webSessionStore.createWebSession() .block(); Map attributes = createdWebSession.getAttributes(); @@ -178,7 +175,7 @@ public class SpringSessionWebSessionStoreTests { @Test public void createSessionWhenGetAttributesAndRemoveThenDelegatesToCreateSession() { - WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation) + WebSession createdWebSession = this.webSessionStore.createWebSession() .block(); Map attributes = createdWebSession.getAttributes(); @@ -189,7 +186,7 @@ public class SpringSessionWebSessionStoreTests { @Test public void createSessionWhenGetAttributesAndPutAllThenDelegatesToCreateSession() { - WebSession createdWebSession = this.webSessionStore.createSession(this.saveOperation) + WebSession createdWebSession = this.webSessionStore.createWebSession() .block(); Map attributes = createdWebSession.getAttributes(); @@ -202,7 +199,7 @@ public class SpringSessionWebSessionStoreTests { 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 attributes = createdWebSession.getAttributes(); @@ -215,7 +212,7 @@ public class SpringSessionWebSessionStoreTests { 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 attributes = createdWebSession.getAttributes(); @@ -228,7 +225,7 @@ public class SpringSessionWebSessionStoreTests { 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 attributes = createdWebSession.getAttributes(); @@ -243,7 +240,7 @@ public class SpringSessionWebSessionStoreTests { .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 attributes = createdWebSession.getAttributes(); @@ -256,7 +253,7 @@ public class SpringSessionWebSessionStoreTests { @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 { 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 { verify(this.sessionRepository).delete(sessionId); } + @Test(expected = IllegalArgumentException.class) + public void setClockWhenNullThenException() { + this.webSessionStore.setClock(null); + } }