diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index d263eb3ba..c2ec25f66 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -72,7 +72,7 @@ dependencies { implementation 'com.apollographql.apollo:apollo-runtime:2.4.5' implementation 'com.github.ben-manes:gradle-versions-plugin:0.38.0' implementation 'com.github.spullara.mustache.java:compiler:0.9.11' - implementation 'io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.34' + implementation 'io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.39' implementation 'io.spring.nohttp:nohttp-gradle:0.0.11' implementation 'net.sourceforge.htmlunit:htmlunit:2.37.0' implementation 'org.hidetake:gradle-ssh-plugin:2.10.1' diff --git a/buildSrc/src/main/groovy/io/spring/gradle/convention/CheckstylePlugin.groovy b/buildSrc/src/main/groovy/io/spring/gradle/convention/CheckstylePlugin.groovy index 0c9fdec04..cc9900922 100644 --- a/buildSrc/src/main/groovy/io/spring/gradle/convention/CheckstylePlugin.groovy +++ b/buildSrc/src/main/groovy/io/spring/gradle/convention/CheckstylePlugin.groovy @@ -18,6 +18,7 @@ package io.spring.gradle.convention import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.artifacts.VersionCatalogsExtension import org.gradle.api.plugins.JavaPlugin /** @@ -31,12 +32,14 @@ class CheckstylePlugin implements Plugin { @Override void apply(Project project) { + def versionCatalog = project.rootProject.extensions.getByType(VersionCatalogsExtension.class) + .named("libs") project.plugins.withType(JavaPlugin) { def checkstyleDir = project.rootProject.file(CHECKSTYLE_DIR) if (checkstyleDir.exists() && checkstyleDir.directory) { project.getPluginManager().apply('checkstyle') - project.dependencies.add('checkstyle', 'io.spring.javaformat:spring-javaformat-checkstyle:0.0.29') - project.dependencies.add('checkstyle', 'io.spring.nohttp:nohttp-checkstyle:0.0.3.RELEASE') + project.dependencies.add('checkstyle', versionCatalog.findLibrary('io-spring-javaformat-spring-javaformat-checkstyle').get()) + project.dependencies.add('checkstyle', versionCatalog.findLibrary('io-spring-nohttp-nohttp-checkstyle').get()) project.checkstyle { configDirectory = checkstyleDir diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3ae40309e..14379de4e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -30,7 +30,7 @@ com-zaxxer-HikariCP = "com.zaxxer:HikariCP:5.0.1" edu-umd-cs-mtc-multithreadedtc = "edu.umd.cs.mtc:multithreadedtc:1.01" io-lettuce-lettuce-core = "io.lettuce:lettuce-core:6.2.6.RELEASE" io-projectreactor-reactor-bom = { module = "io.projectreactor:reactor-bom", version = "2022.0.12" } -io-spring-javaformat-spring-javaformat-checkstyle = "io.spring.javaformat:spring-javaformat-checkstyle:0.0.29" +io-spring-javaformat-spring-javaformat-checkstyle = "io.spring.javaformat:spring-javaformat-checkstyle:0.0.39" io-spring-nohttp-nohttp-checkstyle = "io.spring.nohttp:nohttp-checkstyle:0.0.11" jakarta-servlet-jakarta-servlet-api = "jakarta.servlet:jakarta.servlet-api:6.0.0" jakarta-servlet-jsp-jstl-jakarta-servlet-jsp-jstl-api = "jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0" diff --git a/spring-session-core/src/main/java/org/springframework/session/FindByIndexNameSessionRepository.java b/spring-session-core/src/main/java/org/springframework/session/FindByIndexNameSessionRepository.java index 4c917325b..cf41e78aa 100644 --- a/spring-session-core/src/main/java/org/springframework/session/FindByIndexNameSessionRepository.java +++ b/spring-session-core/src/main/java/org/springframework/session/FindByIndexNameSessionRepository.java @@ -38,7 +38,7 @@ public interface FindByIndexNameSessionRepository extends Ses * @since 1.1 */ String PRINCIPAL_NAME_INDEX_NAME = FindByIndexNameSessionRepository.class.getName() - .concat(".PRINCIPAL_NAME_INDEX_NAME"); + .concat(".PRINCIPAL_NAME_INDEX_NAME"); /** * Find a {@link Map} of the session id to the {@link Session} of all sessions that diff --git a/spring-session-core/src/main/java/org/springframework/session/MapSession.java b/spring-session-core/src/main/java/org/springframework/session/MapSession.java index bd2413575..f7ffafcce 100644 --- a/spring-session-core/src/main/java/org/springframework/session/MapSession.java +++ b/spring-session-core/src/main/java/org/springframework/session/MapSession.java @@ -57,7 +57,7 @@ public final class MapSession implements Session, Serializable { * Default {@link #setMaxInactiveInterval(Duration)} (30 minutes). */ public static final Duration DEFAULT_MAX_INACTIVE_INTERVAL = Duration - .ofSeconds(DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS); + .ofSeconds(DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS); private String id; diff --git a/spring-session-core/src/main/java/org/springframework/session/aot/hint/CommonSessionRuntimeHints.java b/spring-session-core/src/main/java/org/springframework/session/aot/hint/CommonSessionRuntimeHints.java index 53508443c..12f7a3e5a 100644 --- a/spring-session-core/src/main/java/org/springframework/session/aot/hint/CommonSessionRuntimeHints.java +++ b/spring-session-core/src/main/java/org/springframework/session/aot/hint/CommonSessionRuntimeHints.java @@ -33,16 +33,17 @@ class CommonSessionRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - Arrays.asList(TypeReference.of(String.class), TypeReference.of(ArrayList.class), - TypeReference.of(TreeSet.class), TypeReference.of(Number.class), TypeReference.of(Long.class), - TypeReference.of(Integer.class), TypeReference.of(StackTraceElement.class), - TypeReference.of(Throwable.class), TypeReference.of(Exception.class), - TypeReference.of(RuntimeException.class), - TypeReference.of("java.util.Collections$UnmodifiableCollection"), - TypeReference.of("java.util.Collections$UnmodifiableList"), - TypeReference.of("java.util.Collections$EmptyList"), - TypeReference.of("java.util.Collections$UnmodifiableRandomAccessList"), - TypeReference.of("java.util.Collections$UnmodifiableSet")).forEach(hints.serialization()::registerType); + Arrays + .asList(TypeReference.of(String.class), TypeReference.of(ArrayList.class), TypeReference.of(TreeSet.class), + TypeReference.of(Number.class), TypeReference.of(Long.class), TypeReference.of(Integer.class), + TypeReference.of(StackTraceElement.class), TypeReference.of(Throwable.class), + TypeReference.of(Exception.class), TypeReference.of(RuntimeException.class), + TypeReference.of("java.util.Collections$UnmodifiableCollection"), + TypeReference.of("java.util.Collections$UnmodifiableList"), + TypeReference.of("java.util.Collections$EmptyList"), + TypeReference.of("java.util.Collections$UnmodifiableRandomAccessList"), + TypeReference.of("java.util.Collections$UnmodifiableSet")) + .forEach(hints.serialization()::registerType); } } diff --git a/spring-session-core/src/main/java/org/springframework/session/aot/hint/CommonSessionSecurityRuntimeHints.java b/spring-session-core/src/main/java/org/springframework/session/aot/hint/CommonSessionSecurityRuntimeHints.java index 8d6340e5c..6b584d6e2 100644 --- a/spring-session-core/src/main/java/org/springframework/session/aot/hint/CommonSessionSecurityRuntimeHints.java +++ b/spring-session-core/src/main/java/org/springframework/session/aot/hint/CommonSessionSecurityRuntimeHints.java @@ -53,34 +53,37 @@ private void registerSecurityHintsIfNeeded(RuntimeHints hints) { TypeReference.of("org.springframework.security.authentication.CredentialsExpiredException"), TypeReference.of("org.springframework.security.authentication.InsufficientAuthenticationException"), TypeReference - .of("org.springframework.security.web.authentication.session.SessionAuthenticationException"), - TypeReference.of( - "org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException"), + .of("org.springframework.security.web.authentication.session.SessionAuthenticationException"), + TypeReference + .of("org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException"), TypeReference.of("org.springframework.security.core.userdetails.User$AuthorityComparator")) - .forEach((type) -> hints.serialization().registerType(type, (hint) -> hint.onReachableType( + .forEach((type) -> hints.serialization() + .registerType(type, (hint) -> hint.onReachableType( TypeReference.of("org.springframework.security.core.context.SecurityContextImpl")))); } private void registerOAuth2ResourceServerHintsIfNeeded(RuntimeHints hints) { Arrays.asList( TypeReference.of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"), - TypeReference.of( - "org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken"), + TypeReference + .of("org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken"), TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException")) - .forEach((type) -> hints.serialization().registerType(type, (hint) -> hint.onReachableType(TypeReference - .of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken")))); + .forEach((type) -> hints.serialization() + .registerType(type, (hint) -> hint.onReachableType(TypeReference + .of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken")))); } private void registerOAuth2ClientHintsIfNeeded(RuntimeHints hints) { Arrays.asList( TypeReference.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"), TypeReference - .of("org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken"), - TypeReference.of( - "org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken"), + .of("org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken"), + TypeReference + .of("org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken"), TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException")) - .forEach((type) -> hints.serialization().registerType(type, (hint) -> hint.onReachableType(TypeReference - .of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken")))); + .forEach((type) -> hints.serialization() + .registerType(type, (hint) -> hint.onReachableType(TypeReference + .of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken")))); } } diff --git a/spring-session-core/src/main/java/org/springframework/session/aot/hint/server/WebSessionSecurityRuntimeHints.java b/spring-session-core/src/main/java/org/springframework/session/aot/hint/server/WebSessionSecurityRuntimeHints.java index 4f2707802..7448fa00a 100644 --- a/spring-session-core/src/main/java/org/springframework/session/aot/hint/server/WebSessionSecurityRuntimeHints.java +++ b/spring-session-core/src/main/java/org/springframework/session/aot/hint/server/WebSessionSecurityRuntimeHints.java @@ -31,7 +31,7 @@ class WebSessionSecurityRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { if (!ClassUtils.isPresent("org.springframework.web.server.WebSession", classLoader) || !ClassUtils - .isPresent("org.springframework.security.web.server.csrf.DefaultCsrfToken", classLoader)) { + .isPresent("org.springframework.security.web.server.csrf.DefaultCsrfToken", classLoader)) { return; } hints.serialization().registerType(DefaultCsrfToken.class); diff --git a/spring-session-core/src/main/java/org/springframework/session/aot/hint/servlet/HttpSessionSecurityRuntimeHints.java b/spring-session-core/src/main/java/org/springframework/session/aot/hint/servlet/HttpSessionSecurityRuntimeHints.java index 92c30ed33..3c11d291e 100644 --- a/spring-session-core/src/main/java/org/springframework/session/aot/hint/servlet/HttpSessionSecurityRuntimeHints.java +++ b/spring-session-core/src/main/java/org/springframework/session/aot/hint/servlet/HttpSessionSecurityRuntimeHints.java @@ -42,11 +42,12 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { || !ClassUtils.isPresent("org.springframework.security.web.csrf.DefaultCsrfToken", classLoader)) { return; } - Arrays.asList(TypeReference.of(TreeMap.class), TypeReference.of(Locale.class), - TypeReference.of(DefaultSavedRequest.class), TypeReference.of(DefaultCsrfToken.class), - TypeReference.of(WebAuthenticationDetails.class), TypeReference.of(SavedCookie.class), - TypeReference.of("java.lang.String$CaseInsensitiveComparator")) - .forEach(hints.serialization()::registerType); + Arrays + .asList(TypeReference.of(TreeMap.class), TypeReference.of(Locale.class), + TypeReference.of(DefaultSavedRequest.class), TypeReference.of(DefaultCsrfToken.class), + TypeReference.of(WebAuthenticationDetails.class), TypeReference.of(SavedCookie.class), + TypeReference.of("java.lang.String$CaseInsensitiveComparator")) + .forEach(hints.serialization()::registerType); } } diff --git a/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java b/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java index 74456681a..a7adf7acc 100644 --- a/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java +++ b/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java @@ -131,7 +131,7 @@ public SessionRepositoryFilter springSess public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { if (ClassUtils.isPresent("org.springframework.security.web.authentication.RememberMeServices", null)) { this.usesSpringSessionRememberMeServices = !ObjectUtils - .isEmpty(applicationContext.getBeanNamesForType(SpringSessionRememberMeServices.class)); + .isEmpty(applicationContext.getBeanNamesForType(SpringSessionRememberMeServices.class)); } } diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/CookieHttpSessionIdResolver.java b/spring-session-core/src/main/java/org/springframework/session/web/http/CookieHttpSessionIdResolver.java index 5b491270c..3fac4d1d9 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/CookieHttpSessionIdResolver.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/CookieHttpSessionIdResolver.java @@ -64,7 +64,7 @@ public final class CookieHttpSessionIdResolver implements HttpSessionIdResolver { private static final String WRITTEN_SESSION_ID_ATTR = CookieHttpSessionIdResolver.class.getName() - .concat(".WRITTEN_SESSION_ID_ATTR"); + .concat(".WRITTEN_SESSION_ID_ATTR"); private CookieSerializer cookieSerializer = new DefaultCookieSerializer(); diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/HttpSessionAdapter.java b/spring-session-core/src/main/java/org/springframework/session/web/http/HttpSessionAdapter.java index 9dd35a2dd..f6ab4d7ad 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/HttpSessionAdapter.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/HttpSessionAdapter.java @@ -118,7 +118,7 @@ public void setAttribute(String name, Object value) { if (oldValue instanceof HttpSessionBindingListener) { try { ((HttpSessionBindingListener) oldValue) - .valueUnbound(new HttpSessionBindingEvent(this, name, oldValue)); + .valueUnbound(new HttpSessionBindingEvent(this, name, oldValue)); } catch (Throwable th) { logger.error("Error invoking session binding event listener", th); 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 97e0d9103..d4b7e37f8 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 @@ -92,7 +92,8 @@ public Mono updateLastAccessTime(WebSession session) { @Override public Mono retrieveSession(String sessionId) { return this.sessions.findById(sessionId) - .doOnNext((session) -> session.setLastAccessedTime(this.clock.instant())).map(this::existingSession); + .doOnNext((session) -> session.setLastAccessedTime(this.clock.instant())) + .map(this::existingSession); } @Override @@ -233,8 +234,9 @@ public boolean containsKey(Object key) { @Override public boolean containsValue(Object value) { - return this.session.getAttributeNames().stream() - .anyMatch((attrName) -> this.session.getAttribute(attrName) != null); + return this.session.getAttributeNames() + .stream() + .anyMatch((attrName) -> this.session.getAttribute(attrName) != null); } @Override diff --git a/spring-session-core/src/main/java/org/springframework/session/web/socket/handler/WebSocketRegistryListener.java b/spring-session-core/src/main/java/org/springframework/session/web/socket/handler/WebSocketRegistryListener.java index 57c226b80..2cf8407d4 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/socket/handler/WebSocketRegistryListener.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/socket/handler/WebSocketRegistryListener.java @@ -67,7 +67,7 @@ else if (event instanceof SessionConnectEvent) { else if (event instanceof SessionDisconnectEvent) { SessionDisconnectEvent e = (SessionDisconnectEvent) event; Map sessionAttributes = SimpMessageHeaderAccessor - .getSessionAttributes(e.getMessage().getHeaders()); + .getSessionAttributes(e.getMessage().getHeaders()); String httpSessionId = (sessionAttributes != null) ? SessionRepositoryMessageInterceptor.getSessionId(sessionAttributes) : null; afterConnectionClosed(httpSessionId, e.getSessionId()); diff --git a/spring-session-core/src/test/java/org/springframework/session/MapSessionTests.java b/spring-session-core/src/test/java/org/springframework/session/MapSessionTests.java index 36221f5e9..aa5fece4b 100644 --- a/spring-session-core/src/test/java/org/springframework/session/MapSessionTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/MapSessionTests.java @@ -39,7 +39,7 @@ void setup() { @Test void constructorNullSession() { assertThatIllegalArgumentException().isThrownBy(() -> new MapSession((Session) null)) - .withMessage("session cannot be null"); + .withMessage("session cannot be null"); } @Test @@ -70,7 +70,7 @@ void getAttributeOrDefaultWhenNotNullThenDefaultValue() { @Test void getRequiredAttributeWhenNullThenException() { assertThatIllegalArgumentException().isThrownBy(() -> this.session.getRequiredAttribute("attrName")) - .withMessage("Required attribute 'attrName' is missing."); + .withMessage("Required attribute 'attrName' is missing."); } @Test diff --git a/spring-session-core/src/test/java/org/springframework/session/ReactiveMapSessionRepositoryTests.java b/spring-session-core/src/test/java/org/springframework/session/ReactiveMapSessionRepositoryTests.java index ee1478f22..9e4e11e6f 100644 --- a/spring-session-core/src/test/java/org/springframework/session/ReactiveMapSessionRepositoryTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/ReactiveMapSessionRepositoryTests.java @@ -61,7 +61,7 @@ void constructorMapThenFound() { @Test void constructorMapWhenNullThenThrowsIllegalArgumentException() { assertThatIllegalArgumentException().isThrownBy(() -> new ReactiveMapSessionRepository(null)) - .withMessage("sessions cannot be null"); + .withMessage("sessions cannot be null"); } @Test diff --git a/spring-session-core/src/test/java/org/springframework/session/aot/hint/CommonSessionRuntimeHintsTests.java b/spring-session-core/src/test/java/org/springframework/session/aot/hint/CommonSessionRuntimeHintsTests.java index b800cefa1..60a190772 100644 --- a/spring-session-core/src/test/java/org/springframework/session/aot/hint/CommonSessionRuntimeHintsTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/aot/hint/CommonSessionRuntimeHintsTests.java @@ -53,8 +53,9 @@ void commonSessionTypesHasHints(TypeReference typeReference) { @Test void aotFactoriesContainsRegistrar() { boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories") - .load(RuntimeHintsRegistrar.class).stream() - .anyMatch((registrar) -> registrar instanceof CommonSessionRuntimeHints); + .load(RuntimeHintsRegistrar.class) + .stream() + .anyMatch((registrar) -> registrar instanceof CommonSessionRuntimeHints); assertThat(match).isTrue(); } diff --git a/spring-session-core/src/test/java/org/springframework/session/aot/hint/CommonSessionSecurityRuntimeHintsTests.java b/spring-session-core/src/test/java/org/springframework/session/aot/hint/CommonSessionSecurityRuntimeHintsTests.java index f168e80fe..9c1d609c1 100644 --- a/spring-session-core/src/test/java/org/springframework/session/aot/hint/CommonSessionSecurityRuntimeHintsTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/aot/hint/CommonSessionSecurityRuntimeHintsTests.java @@ -51,8 +51,9 @@ void commonSecurityTypesHasHints(TypeReference typeReference) { @Test void aotFactoriesContainsRegistrar() { boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories") - .load(RuntimeHintsRegistrar.class).stream() - .anyMatch((registrar) -> registrar instanceof CommonSessionSecurityRuntimeHints); + .load(RuntimeHintsRegistrar.class) + .stream() + .anyMatch((registrar) -> registrar instanceof CommonSessionSecurityRuntimeHints); assertThat(match).isTrue(); } @@ -73,19 +74,19 @@ private static Stream getSerializationHintTypes() { TypeReference.of("org.springframework.security.authentication.CredentialsExpiredException"), TypeReference.of("org.springframework.security.authentication.InsufficientAuthenticationException"), TypeReference - .of("org.springframework.security.web.authentication.session.SessionAuthenticationException"), - TypeReference.of( - "org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException"), + .of("org.springframework.security.web.authentication.session.SessionAuthenticationException"), + TypeReference + .of("org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException"), TypeReference.of("org.springframework.security.core.userdetails.User$AuthorityComparator"), TypeReference.of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"), - TypeReference.of( - "org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken"), + TypeReference + .of("org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken"), TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"), TypeReference.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"), TypeReference - .of("org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken"), - TypeReference.of( - "org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken"), + .of("org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken"), + TypeReference + .of("org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken"), TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException")); } diff --git a/spring-session-core/src/test/java/org/springframework/session/aot/hint/server/WebSessionSecurityRuntimeHintsTests.java b/spring-session-core/src/test/java/org/springframework/session/aot/hint/server/WebSessionSecurityRuntimeHintsTests.java index dc0d4370a..2197fe648 100644 --- a/spring-session-core/src/test/java/org/springframework/session/aot/hint/server/WebSessionSecurityRuntimeHintsTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/aot/hint/server/WebSessionSecurityRuntimeHintsTests.java @@ -52,7 +52,7 @@ void defaultCsrfTokenHasHints() { void registerHintsWhenWebSessionMissingThenDoNotRegisterHints() { try (MockedStatic classUtilsMock = mockStatic(ClassUtils.class)) { classUtilsMock.when(() -> ClassUtils.isPresent(eq("org.springframework.web.server.WebSession"), any())) - .thenReturn(false); + .thenReturn(false); this.webSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader()); assertThat(this.hints.serialization().javaSerializationHints()).isEmpty(); } @@ -62,9 +62,9 @@ void registerHintsWhenWebSessionMissingThenDoNotRegisterHints() { void registerHintsWhenDefaultCsrfTokenMissingThenDoNotRegisterHints() { try (MockedStatic classUtilsMock = mockStatic(ClassUtils.class)) { classUtilsMock - .when(() -> ClassUtils - .isPresent(eq("org.springframework.security.web.server.csrf.DefaultCsrfToken"), any())) - .thenReturn(false); + .when(() -> ClassUtils.isPresent(eq("org.springframework.security.web.server.csrf.DefaultCsrfToken"), + any())) + .thenReturn(false); this.webSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader()); assertThat(this.hints.serialization().javaSerializationHints()).isEmpty(); } @@ -73,8 +73,9 @@ void registerHintsWhenDefaultCsrfTokenMissingThenDoNotRegisterHints() { @Test void aotFactoriesContainsRegistrar() { boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories") - .load(RuntimeHintsRegistrar.class).stream() - .anyMatch((registrar) -> registrar instanceof WebSessionSecurityRuntimeHints); + .load(RuntimeHintsRegistrar.class) + .stream() + .anyMatch((registrar) -> registrar instanceof WebSessionSecurityRuntimeHints); assertThat(match).isTrue(); } diff --git a/spring-session-core/src/test/java/org/springframework/session/aot/hint/servlet/HttpSessionSecurityRuntimeHintsTests.java b/spring-session-core/src/test/java/org/springframework/session/aot/hint/servlet/HttpSessionSecurityRuntimeHintsTests.java index baeda95c4..4f75fe609 100644 --- a/spring-session-core/src/test/java/org/springframework/session/aot/hint/servlet/HttpSessionSecurityRuntimeHintsTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/aot/hint/servlet/HttpSessionSecurityRuntimeHintsTests.java @@ -63,7 +63,7 @@ void httpSessionHasHints(TypeReference typeReference) { void registerHintsWhenHttpSessionMissingThenDoNotRegisterHints() { try (MockedStatic classUtilsMock = mockStatic(ClassUtils.class)) { classUtilsMock.when(() -> ClassUtils.isPresent(eq("jakarta.servlet.http.HttpSession"), any())) - .thenReturn(false); + .thenReturn(false); this.httpSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader()); assertThat(this.hints.serialization().javaSerializationHints()).isEmpty(); } @@ -72,9 +72,9 @@ void registerHintsWhenHttpSessionMissingThenDoNotRegisterHints() { @Test void registerHintsWhenDefaultCsrfTokenMissingThenDoNotRegisterHints() { try (MockedStatic classUtilsMock = mockStatic(ClassUtils.class)) { - classUtilsMock.when( - () -> ClassUtils.isPresent(eq("org.springframework.security.web.csrf.DefaultCsrfToken"), any())) - .thenReturn(false); + classUtilsMock + .when(() -> ClassUtils.isPresent(eq("org.springframework.security.web.csrf.DefaultCsrfToken"), any())) + .thenReturn(false); this.httpSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader()); assertThat(this.hints.serialization().javaSerializationHints()).isEmpty(); } @@ -83,8 +83,9 @@ void registerHintsWhenDefaultCsrfTokenMissingThenDoNotRegisterHints() { @Test void aotFactoriesContainsRegistrar() { boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories") - .load(RuntimeHintsRegistrar.class).stream() - .anyMatch((registrar) -> registrar instanceof HttpSessionSecurityRuntimeHints); + .load(RuntimeHintsRegistrar.class) + .stream() + .anyMatch((registrar) -> registrar instanceof HttpSessionSecurityRuntimeHints); assertThat(match).isTrue(); } diff --git a/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java b/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java index 42a3a379c..8178f101c 100644 --- a/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java @@ -92,7 +92,7 @@ void setup() { void usesReadSessionIds() throws Exception { String sessionId = "sessionId"; given(this.cookieSerializer.readCookieValues(any(HttpServletRequest.class))) - .willReturn(Collections.singletonList(sessionId)); + .willReturn(Collections.singletonList(sessionId)); given(this.sessionRepository.findById(anyString())).willReturn(new MapSession(sessionId)); this.sessionRepositoryFilter.doFilter(this.request, this.response, this.chain); diff --git a/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfigurationTests.java b/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfigurationTests.java index 269da4f64..b4f3865fc 100644 --- a/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfigurationTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfigurationTests.java @@ -64,8 +64,8 @@ private void registerAndRefresh(Class... annotatedClasses) { @Test void noSessionRepositoryConfiguration() { assertThatExceptionOfType(UnsatisfiedDependencyException.class) - .isThrownBy(() -> registerAndRefresh(EmptyConfiguration.class)) - .withMessageContaining("org.springframework.session.SessionRepository"); + .isThrownBy(() -> registerAndRefresh(EmptyConfiguration.class)) + .withMessageContaining("org.springframework.session.SessionRepository"); } @Test @@ -84,10 +84,10 @@ void sessionCookieConfigConfiguration() { SessionRepositoryFilter sessionRepositoryFilter = this.context.getBean(SessionRepositoryFilter.class); assertThat(sessionRepositoryFilter).isNotNull(); CookieHttpSessionIdResolver httpSessionIdResolver = (CookieHttpSessionIdResolver) ReflectionTestUtils - .getField(sessionRepositoryFilter, "httpSessionIdResolver"); + .getField(sessionRepositoryFilter, "httpSessionIdResolver"); assertThat(httpSessionIdResolver).isNotNull(); DefaultCookieSerializer cookieSerializer = (DefaultCookieSerializer) ReflectionTestUtils - .getField(httpSessionIdResolver, "cookieSerializer"); + .getField(httpSessionIdResolver, "cookieSerializer"); assertThat(cookieSerializer).isNotNull(); assertThat(ReflectionTestUtils.getField(cookieSerializer, "cookieName")).isEqualTo("test-name"); assertThat(ReflectionTestUtils.getField(cookieSerializer, "cookiePath")).isEqualTo("test-path"); @@ -102,13 +102,13 @@ void rememberMeServicesConfiguration() { SessionRepositoryFilter sessionRepositoryFilter = this.context.getBean(SessionRepositoryFilter.class); assertThat(sessionRepositoryFilter).isNotNull(); CookieHttpSessionIdResolver httpSessionIdResolver = (CookieHttpSessionIdResolver) ReflectionTestUtils - .getField(sessionRepositoryFilter, "httpSessionIdResolver"); + .getField(sessionRepositoryFilter, "httpSessionIdResolver"); assertThat(httpSessionIdResolver).isNotNull(); DefaultCookieSerializer cookieSerializer = (DefaultCookieSerializer) ReflectionTestUtils - .getField(httpSessionIdResolver, "cookieSerializer"); + .getField(httpSessionIdResolver, "cookieSerializer"); assertThat(cookieSerializer).isNotNull(); assertThat(ReflectionTestUtils.getField(cookieSerializer, "rememberMeRequestAttribute")) - .isEqualTo(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR); + .isEqualTo(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR); } @Configuration diff --git a/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/server/SpringWebSessionConfigurationTests.java b/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/server/SpringWebSessionConfigurationTests.java index 0d9b91447..54dc98dfb 100644 --- a/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/server/SpringWebSessionConfigurationTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/server/SpringWebSessionConfigurationTests.java @@ -77,8 +77,8 @@ void missingReactiveSessionRepositoryBreaksAppContext() { this.context.register(BadConfig.class); assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(this.context::refresh) - .withMessageContaining("Error creating bean with name 'webSessionManager'").withMessageContaining( - "No qualifying bean of type '" + ReactiveSessionRepository.class.getCanonicalName()); + .withMessageContaining("Error creating bean with name 'webSessionManager'") + .withMessageContaining("No qualifying bean of type '" + ReactiveSessionRepository.class.getCanonicalName()); } @Test diff --git a/spring-session-core/src/test/java/org/springframework/session/security/SpringSessionBackedSessionRegistryTest.java b/spring-session-core/src/test/java/org/springframework/session/security/SpringSessionBackedSessionRegistryTest.java index 35ef46c50..427746ccf 100644 --- a/spring-session-core/src/test/java/org/springframework/session/security/SpringSessionBackedSessionRegistryTest.java +++ b/spring-session-core/src/test/java/org/springframework/session/security/SpringSessionBackedSessionRegistryTest.java @@ -77,7 +77,7 @@ void sessionInformationForExistingSession() { assertThat(sessionInfo.getSessionId()).isEqualTo(SESSION_ID); assertThat(sessionInfo.getLastRequest().toInstant().truncatedTo(ChronoUnit.MILLIS)) - .isEqualTo(NOW.truncatedTo(ChronoUnit.MILLIS)); + .isEqualTo(NOW.truncatedTo(ChronoUnit.MILLIS)); assertThat(sessionInfo.getPrincipal()).isEqualTo(USER_NAME); assertThat(sessionInfo.isExpired()).isFalse(); } @@ -92,7 +92,7 @@ void sessionInformationForExpiredSession() { assertThat(sessionInfo.getSessionId()).isEqualTo(SESSION_ID); assertThat(sessionInfo.getLastRequest().toInstant().truncatedTo(ChronoUnit.MILLIS)) - .isEqualTo(NOW.truncatedTo(ChronoUnit.MILLIS)); + .isEqualTo(NOW.truncatedTo(ChronoUnit.MILLIS)); assertThat(sessionInfo.getPrincipal()).isEqualTo(USER_NAME); assertThat(sessionInfo.isExpired()).isTrue(); } @@ -113,7 +113,7 @@ void getAllSessionsForUserDetails() { void getAllSessionsForAuthenticatedPrincipal() { setUpSessions(); List allSessionInfos = this.sessionRegistry - .getAllSessions((AuthenticatedPrincipal) () -> USER_NAME, true); + .getAllSessions((AuthenticatedPrincipal) () -> USER_NAME, true); assertThat(allSessionInfos).extracting("sessionId").containsExactly(SESSION_ID, SESSION_ID2); } @@ -148,7 +148,7 @@ void expireNow() { ArgumentCaptor captor = ArgumentCaptor.forClass(Session.class); verify(this.sessionRepository).save(captor.capture()); assertThat(captor.getValue().getAttribute(SpringSessionBackedSessionInformation.EXPIRED_ATTR)) - .isEqualTo(Boolean.TRUE); + .isEqualTo(Boolean.TRUE); } private Session createSession(String sessionId, String userName, Instant lastAccessed) { diff --git a/spring-session-core/src/test/java/org/springframework/session/security/web/authentication/SpringSessionRememberMeServicesTests.java b/spring-session-core/src/test/java/org/springframework/session/security/web/authentication/SpringSessionRememberMeServicesTests.java index adcded9a5..a0f20252c 100644 --- a/spring-session-core/src/test/java/org/springframework/session/security/web/authentication/SpringSessionRememberMeServicesTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/security/web/authentication/SpringSessionRememberMeServicesTests.java @@ -48,7 +48,7 @@ class SpringSessionRememberMeServicesTests { void create() { this.rememberMeServices = new SpringSessionRememberMeServices(); assertThat(ReflectionTestUtils.getField(this.rememberMeServices, "rememberMeParameterName")) - .isEqualTo("remember-me"); + .isEqualTo("remember-me"); assertThat(ReflectionTestUtils.getField(this.rememberMeServices, "alwaysRemember")).isEqualTo(false); assertThat(ReflectionTestUtils.getField(this.rememberMeServices, "validitySeconds")).isEqualTo(2592000); } @@ -58,14 +58,14 @@ void createWithCustomParameter() { this.rememberMeServices = new SpringSessionRememberMeServices(); this.rememberMeServices.setRememberMeParameterName("test-param"); assertThat(ReflectionTestUtils.getField(this.rememberMeServices, "rememberMeParameterName")) - .isEqualTo("test-param"); + .isEqualTo("test-param"); } @Test void createWithNullParameter() { this.rememberMeServices = new SpringSessionRememberMeServices(); assertThatIllegalArgumentException().isThrownBy(() -> this.rememberMeServices.setRememberMeParameterName(null)) - .withMessage("rememberMeParameterName cannot be empty or null"); + .withMessage("rememberMeParameterName cannot be empty or null"); } @Test diff --git a/spring-session-core/src/test/java/org/springframework/session/web/http/CookieHttpSessionIdResolverTests.java b/spring-session-core/src/test/java/org/springframework/session/web/http/CookieHttpSessionIdResolverTests.java index 02f921c90..da98e553f 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/http/CookieHttpSessionIdResolverTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/http/CookieHttpSessionIdResolverTests.java @@ -64,7 +64,7 @@ void getRequestedSessionIdNull() { void getRequestedSessionIdNotNull() { setSessionCookie(this.session.getId()); assertThat(this.strategy.resolveSessionIds(this.request)) - .isEqualTo(Collections.singletonList(this.session.getId())); + .isEqualTo(Collections.singletonList(this.session.getId())); } @Test @@ -72,7 +72,7 @@ void getRequestedSessionIdNotNullCustomCookieName() { setCookieName("CUSTOM"); setSessionCookie(this.session.getId()); assertThat(this.strategy.resolveSessionIds(this.request)) - .isEqualTo(Collections.singletonList(this.session.getId())); + .isEqualTo(Collections.singletonList(this.session.getId())); } @Test @@ -144,7 +144,7 @@ void onDeleteSessionCustomCookieName() { @Test void createSessionCookieValue() { assertThat(createSessionCookieValue(17)) - .isEqualToIgnoringCase("0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 a 10 b 11 c 12 d 13 e 14 f 15 10 16"); + .isEqualToIgnoringCase("0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 a 10 b 11 c 12 d 13 e 14 f 15 10 16"); } private String createSessionCookieValue(long size) { diff --git a/spring-session-core/src/test/java/org/springframework/session/web/http/DefaultCookieSerializerTests.java b/spring-session-core/src/test/java/org/springframework/session/web/http/DefaultCookieSerializerTests.java index 9a716fb98..2272db8c9 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/http/DefaultCookieSerializerTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/http/DefaultCookieSerializerTests.java @@ -200,7 +200,7 @@ void writeCookieDomainNameCustom() { void setDomainNameAndDomainNamePatternThrows() { this.serializer.setDomainName("example.com"); assertThatIllegalStateException().isThrownBy(() -> this.serializer.setDomainNamePattern(".*")) - .withMessage("Cannot set both domainName and domainNamePattern"); + .withMessage("Cannot set both domainName and domainNamePattern"); } // --- domainNamePattern --- @@ -229,7 +229,7 @@ void writeCookieDomainNamePattern() { void setDomainNamePatternAndDomainNameThrows() { this.serializer.setDomainNamePattern(".*"); assertThatIllegalStateException().isThrownBy(() -> this.serializer.setDomainName("example.com")) - .withMessage("Cannot set both domainName and domainNamePattern"); + .withMessage("Cannot set both domainName and domainNamePattern"); } // --- cookieName --- @@ -251,7 +251,7 @@ void writeCookieCookieNameCustom() { @Test void setCookieNameNullThrows() { assertThatIllegalArgumentException().isThrownBy(() -> this.serializer.setCookieName(null)) - .withMessage("cookieName cannot be null"); + .withMessage("cookieName cannot be null"); } // --- cookiePath --- diff --git a/spring-session-core/src/test/java/org/springframework/session/web/http/HeaderHttpSessionIdResolverTests.java b/spring-session-core/src/test/java/org/springframework/session/web/http/HeaderHttpSessionIdResolverTests.java index 81b6671ca..6165c4ecd 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/http/HeaderHttpSessionIdResolverTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/http/HeaderHttpSessionIdResolverTests.java @@ -70,7 +70,7 @@ void createResolverWithCustomHeaderName() { @Test void createResolverWithNullHeaderName() { assertThatIllegalArgumentException().isThrownBy(() -> new HeaderHttpSessionIdResolver(null)) - .withMessage("headerName cannot be null"); + .withMessage("headerName cannot be null"); } @Test diff --git a/spring-session-core/src/test/java/org/springframework/session/web/http/OncePerRequestFilterAopTests.java b/spring-session-core/src/test/java/org/springframework/session/web/http/OncePerRequestFilterAopTests.java index 8add74a4f..5a946d6bc 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/http/OncePerRequestFilterAopTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/http/OncePerRequestFilterAopTests.java @@ -40,8 +40,9 @@ class OncePerRequestFilterAopTests { @Test void doFilterOnce(@Autowired final OncePerRequestFilter filter) { assertThatCode(() -> filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), - new MockFilterChain())).as("`doFilter` does not throw NPE with the bean is being proxied by Spring AOP") - .doesNotThrowAnyException(); + new MockFilterChain())) + .as("`doFilter` does not throw NPE with the bean is being proxied by Spring AOP") + .doesNotThrowAnyException(); } @SuppressWarnings({ "rawtypes", "unchecked" }) diff --git a/spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java b/spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java index 523d8ea1b..b29f19781 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java @@ -998,7 +998,7 @@ void doFilterAdapterGetRequestedSessionId() throws Exception { final String expectedId = "HttpSessionIdResolver-requested-id"; given(this.strategy.resolveSessionIds(any(HttpServletRequest.class))) - .willReturn(Collections.singletonList(expectedId)); + .willReturn(Collections.singletonList(expectedId)); given(sessionRepository.findById(anyString())).willReturn(new MapSession(expectedId)); doFilter(new DoInFilter() { @@ -1020,7 +1020,7 @@ void doFilterAdapterGetRequestedSessionIdForInvalidSession() throws Exception { final String otherId = "HttpSessionIdResolver-requested-id2"; given(this.strategy.resolveSessionIds(any(HttpServletRequest.class))) - .willReturn(Arrays.asList(expectedId, otherId)); + .willReturn(Arrays.asList(expectedId, otherId)); doFilter(new DoInFilter() { @Override @@ -1189,7 +1189,7 @@ public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrap void order() { assertThat( AnnotationAwareOrderComparator.INSTANCE.compare(this.filter, new SessionRepositoryFilterDefaultOrder())) - .isZero(); + .isZero(); } // We want the filter to work without any dependencies on Spring @@ -1201,7 +1201,7 @@ void doesNotImplementOrdered() { @Test void setHttpSessionIdResolverNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.filter.setHttpSessionIdResolver(null)) - .withMessage("httpSessionIdResolver cannot be null"); + .withMessage("httpSessionIdResolver cannot be null"); } @Test @@ -1329,16 +1329,18 @@ private void assertNewSession() { assertThat(cookie.getValue()).isNotEqualTo("INVALID"); assertThat(cookie.isHttpOnly()).describedAs("Cookie is expected to be HTTP Only").isTrue(); assertThat(cookie.getSecure()).describedAs("Cookie secured is expected to be " + this.request.isSecure()) - .isEqualTo(this.request.isSecure()); + .isEqualTo(this.request.isSecure()); assertThat(this.request.getSession(false)) - .describedAs("The original HttpServletRequest HttpSession should be null").isNull(); + .describedAs("The original HttpServletRequest HttpSession should be null") + .isNull(); } private void assertNoSession() { Cookie cookie = getSessionCookie(); assertThat(cookie).isNull(); assertThat(this.request.getSession(false)) - .describedAs("The original HttpServletRequest HttpSession should be null").isNull(); + .describedAs("The original HttpServletRequest HttpSession should be null") + .isNull(); } private Cookie getSessionCookie() { 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 6f14e514b..5740848c5 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 @@ -68,7 +68,7 @@ void setup() { @Test void constructorWhenNullRepositoryThenThrowsIllegalArgumentException() { assertThatIllegalArgumentException().isThrownBy(() -> new SpringSessionWebSessionStore(null)) - .withMessage("reactiveSessionRepository cannot be null"); + .withMessage("reactiveSessionRepository cannot be null"); } @Test @@ -248,7 +248,7 @@ void removeSessionWhenInvokedThenSessionSaved() { @Test void setClockWhenNullThenException() { assertThatIllegalArgumentException().isThrownBy(() -> this.webSessionStore.setClock(null)) - .withMessage("clock cannot be null"); + .withMessage("clock cannot be null"); } @Test // gh-1114 diff --git a/spring-session-core/src/test/java/org/springframework/session/web/socket/handler/WebSocketConnectHandlerDecoratorFactoryTests.java b/spring-session-core/src/test/java/org/springframework/session/web/socket/handler/WebSocketConnectHandlerDecoratorFactoryTests.java index efde42538..3667fea15 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/socket/handler/WebSocketConnectHandlerDecoratorFactoryTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/socket/handler/WebSocketConnectHandlerDecoratorFactoryTests.java @@ -61,7 +61,7 @@ void setup() { @Test void constructorNullEventPublisher() { assertThatIllegalArgumentException().isThrownBy(() -> new WebSocketConnectHandlerDecoratorFactory(null)) - .withMessage("eventPublisher cannot be null"); + .withMessage("eventPublisher cannot be null"); } @Test @@ -78,7 +78,7 @@ void decorateAfterConnectionEstablished() throws Exception { void decorateAfterConnectionEstablishedEventError() throws Exception { WebSocketHandler decorated = this.factory.decorate(this.delegate); willThrow(new IllegalStateException("Test throw on publishEvent")).given(this.eventPublisher) - .publishEvent(any(ApplicationEvent.class)); + .publishEvent(any(ApplicationEvent.class)); decorated.afterConnectionEstablished(this.session); diff --git a/spring-session-core/src/test/java/org/springframework/session/web/socket/handler/WebSocketRegistryListenerTests.java b/spring-session-core/src/test/java/org/springframework/session/web/socket/handler/WebSocketRegistryListenerTests.java index ec4ed1947..9460e96a7 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/socket/handler/WebSocketRegistryListenerTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/socket/handler/WebSocketRegistryListenerTests.java @@ -150,7 +150,7 @@ void onApplicationEventConnectDisconnectCleanup() { this.listener.onApplicationEvent(this.disconnect); Map> httpSessionIdToWsSessions = (Map>) ReflectionTestUtils - .getField(this.listener, "httpSessionIdToWsSessions"); + .getField(this.listener, "httpSessionIdToWsSessions"); assertThat(httpSessionIdToWsSessions).isEmpty(); } diff --git a/spring-session-core/src/test/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptorTests.java b/spring-session-core/src/test/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptorTests.java index ae576207a..baf72fc3d 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptorTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptorTests.java @@ -85,7 +85,7 @@ void setup() { @Test void preSendconstructorNullRepository() { assertThatIllegalArgumentException().isThrownBy(() -> new SessionRepositoryMessageInterceptor<>(null)) - .withMessage("sessionRepository cannot be null"); + .withMessage("sessionRepository cannot be null"); } @Test @@ -132,14 +132,14 @@ void preSendOtherDoesNotInvokeSessionRepository() { @Test void setMatchingMessageTypesNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.interceptor.setMatchingMessageTypes(null)) - .withMessage("matchingMessageTypes cannot be null or empty"); + .withMessage("matchingMessageTypes cannot be null or empty"); } @Test void setMatchingMessageTypesEmpty() { assertThatIllegalArgumentException() - .isThrownBy(() -> this.interceptor.setMatchingMessageTypes(Collections.emptySet())) - .withMessage("matchingMessageTypes cannot be null or empty"); + .isThrownBy(() -> this.interceptor.setMatchingMessageTypes(Collections.emptySet())) + .withMessage("matchingMessageTypes cannot be null or empty"); } @Test diff --git a/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/AbstractClassLoaderTest.java b/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/AbstractClassLoaderTest.java index e3138ccc4..4cfacef6b 100644 --- a/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/AbstractClassLoaderTest.java +++ b/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/AbstractClassLoaderTest.java @@ -48,7 +48,7 @@ void verifyContainerClassLoaderLoadedIntoConverter() { "mongoSessionConverter"); ReflectionUtils.makeAccessible(mongoSessionConverterField); AbstractMongoSessionConverter sessionConverter = (AbstractMongoSessionConverter) ReflectionUtils - .getField(mongoSessionConverterField, this.sessionRepository); + .getField(mongoSessionConverterField, this.sessionRepository); AssertionsForClassTypes.assertThat(sessionConverter).isInstanceOf(JdkMongoSessionConverter.class); diff --git a/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/AbstractMongoRepositoryITest.java b/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/AbstractMongoRepositoryITest.java index 46364a265..ba53e9a21 100644 --- a/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/AbstractMongoRepositoryITest.java +++ b/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/AbstractMongoRepositoryITest.java @@ -79,7 +79,7 @@ void saves() { assertThat(session.getId()).isEqualTo(toSave.getId()); assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames()); assertThat(session.getAttribute(expectedAttributeName)) - .isEqualTo(toSave.getAttribute(expectedAttributeName)); + .isEqualTo(toSave.getAttribute(expectedAttributeName)); this.repository.deleteById(toSave.getId()); @@ -400,7 +400,7 @@ public MongoDBContainer mongoDbContainer() { public MongoOperations mongoOperations(MongoDBContainer mongoContainer) { MongoClient mongo = MongoClients - .create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort()); + .create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort()); return new MongoTemplate(mongo, "test"); } diff --git a/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/MongoDbDeleteJacksonSessionVerificationTest.java b/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/MongoDbDeleteJacksonSessionVerificationTest.java index 8e3973405..211320aaa 100644 --- a/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/MongoDbDeleteJacksonSessionVerificationTest.java +++ b/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/MongoDbDeleteJacksonSessionVerificationTest.java @@ -73,13 +73,14 @@ void logoutShouldDeleteOldSessionFromMongoDB() { // 1. Login and capture the SESSION cookie value. - FluxExchangeResult loginResult = this.client.post().uri("/login") - .contentType(MediaType.APPLICATION_FORM_URLENCODED) // - .body(BodyInserters // - .fromFormData("username", "admin") // - .with("password", "password")) // - .exchange() // - .returnResult(String.class); + FluxExchangeResult loginResult = this.client.post() + .uri("/login") + .contentType(MediaType.APPLICATION_FORM_URLENCODED) // + .body(BodyInserters // + .fromFormData("username", "admin") // + .with("password", "password")) // + .exchange() // + .returnResult(String.class); AssertionsForClassTypes.assertThat(loginResult.getResponseHeaders().getLocation()).isEqualTo(URI.create("/")); @@ -87,42 +88,54 @@ void logoutShouldDeleteOldSessionFromMongoDB() { // 2. Fetch a protected resource using the SESSION cookie. - this.client.get().uri("/hello") // - .cookie("SESSION", originalSessionId) // - .exchange() // - .expectStatus().isOk() // - .returnResult(String.class).getResponseBody() // - .as(StepVerifier::create) // - .expectNext("HelloWorld") // - .verifyComplete(); + this.client.get() + .uri("/hello") // + .cookie("SESSION", originalSessionId) // + .exchange() // + .expectStatus() + .isOk() // + .returnResult(String.class) + .getResponseBody() // + .as(StepVerifier::create) // + .expectNext("HelloWorld") // + .verifyComplete(); // 3. Logout using the SESSION cookie, and capture the new SESSION cookie. - String newSessionId = this.client.post().uri("/logout") // - .cookie("SESSION", originalSessionId) // - .exchange() // - .expectStatus().isFound() // - .returnResult(String.class).getResponseCookies().getFirst("SESSION").getValue(); + String newSessionId = this.client.post() + .uri("/logout") // + .cookie("SESSION", originalSessionId) // + .exchange() // + .expectStatus() + .isFound() // + .returnResult(String.class) + .getResponseCookies() + .getFirst("SESSION") + .getValue(); AssertionsForClassTypes.assertThat(newSessionId).isNotEqualTo(originalSessionId); // 4. Verify the new SESSION cookie is not yet authorized. - this.client.get().uri("/hello") // - .cookie("SESSION", newSessionId) // - .exchange() // - .expectStatus().isFound() // - .expectHeader() - .value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login")); + this.client.get() + .uri("/hello") // + .cookie("SESSION", newSessionId) // + .exchange() // + .expectStatus() + .isFound() // + .expectHeader() + .value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login")); // 5. Verify the original SESSION cookie no longer works. - this.client.get().uri("/hello") // - .cookie("SESSION", originalSessionId) // - .exchange() // - .expectStatus().isFound() // - .expectHeader() - .value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login")); + this.client.get() + .uri("/hello") // + .cookie("SESSION", originalSessionId) // + .exchange() // + .expectStatus() + .isFound() // + .expectHeader() + .value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login")); } @RestController @@ -142,23 +155,25 @@ static class SecurityConfig { @Bean SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) { return http // - .logout()// - /**/.and() // - .formLogin() // - /**/.and() // - .csrf().disable() // - .authorizeExchange() // - .anyExchange().authenticated() // - /**/.and() // - .build(); + .logout()// + /**/.and() // + .formLogin() // + /**/.and() // + .csrf() + .disable() // + .authorizeExchange() // + .anyExchange() + .authenticated() // + /**/.and() // + .build(); } @Bean MapReactiveUserDetailsService userDetailsService() { return new MapReactiveUserDetailsService(User.withUsername("admin") // - .password("{noop}password") // - .roles("USER,ADMIN") // - .build()); + .password("{noop}password") // + .roles("USER,ADMIN") // + .build()); } @Bean @@ -186,7 +201,7 @@ MongoDBContainer mongoDbContainer() { ReactiveMongoOperations mongoOperations(MongoDBContainer mongoContainer) { MongoClient mongo = MongoClients - .create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort()); + .create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort()); return new ReactiveMongoTemplate(mongo, "DB_Name_DeleteJacksonSessionVerificationTest"); } diff --git a/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/MongoDbLogoutVerificationTest.java b/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/MongoDbLogoutVerificationTest.java index 17fb4eac9..69c8c3cc0 100644 --- a/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/MongoDbLogoutVerificationTest.java +++ b/spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/MongoDbLogoutVerificationTest.java @@ -73,13 +73,14 @@ void logoutShouldDeleteOldSessionFromMongoDB() { // 1. Login and capture the SESSION cookie value. - FluxExchangeResult loginResult = this.client.post().uri("/login") - .contentType(MediaType.APPLICATION_FORM_URLENCODED) // - .body(BodyInserters // - .fromFormData("username", "admin") // - .with("password", "password")) // - .exchange() // - .returnResult(String.class); + FluxExchangeResult loginResult = this.client.post() + .uri("/login") + .contentType(MediaType.APPLICATION_FORM_URLENCODED) // + .body(BodyInserters // + .fromFormData("username", "admin") // + .with("password", "password")) // + .exchange() // + .returnResult(String.class); AssertionsForClassTypes.assertThat(loginResult.getResponseHeaders().getLocation()).isEqualTo(URI.create("/")); @@ -87,42 +88,54 @@ void logoutShouldDeleteOldSessionFromMongoDB() { // 2. Fetch a protected resource using the SESSION cookie. - this.client.get().uri("/hello") // - .cookie("SESSION", originalSessionId) // - .exchange() // - .expectStatus().isOk() // - .returnResult(String.class).getResponseBody() // - .as(StepVerifier::create) // - .expectNext("HelloWorld") // - .verifyComplete(); + this.client.get() + .uri("/hello") // + .cookie("SESSION", originalSessionId) // + .exchange() // + .expectStatus() + .isOk() // + .returnResult(String.class) + .getResponseBody() // + .as(StepVerifier::create) // + .expectNext("HelloWorld") // + .verifyComplete(); // 3. Logout using the SESSION cookie, and capture the new SESSION cookie. - String newSessionId = this.client.post().uri("/logout") // - .cookie("SESSION", originalSessionId) // - .exchange() // - .expectStatus().isFound() // - .returnResult(String.class).getResponseCookies().getFirst("SESSION").getValue(); + String newSessionId = this.client.post() + .uri("/logout") // + .cookie("SESSION", originalSessionId) // + .exchange() // + .expectStatus() + .isFound() // + .returnResult(String.class) + .getResponseCookies() + .getFirst("SESSION") + .getValue(); AssertionsForClassTypes.assertThat(newSessionId).isNotEqualTo(originalSessionId); // 4. Verify the new SESSION cookie is not yet authorized. - this.client.get().uri("/hello") // - .cookie("SESSION", newSessionId) // - .exchange() // - .expectStatus().isFound() // - .expectHeader() - .value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login")); + this.client.get() + .uri("/hello") // + .cookie("SESSION", newSessionId) // + .exchange() // + .expectStatus() + .isFound() // + .expectHeader() + .value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login")); // 5. Verify the original SESSION cookie no longer works. - this.client.get().uri("/hello") // - .cookie("SESSION", originalSessionId) // - .exchange() // - .expectStatus().isFound() // - .expectHeader() - .value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login")); + this.client.get() + .uri("/hello") // + .cookie("SESSION", originalSessionId) // + .exchange() // + .expectStatus() + .isFound() // + .expectHeader() + .value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login")); } @RestController @@ -143,24 +156,26 @@ static class SecurityConfig { SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) { return http // - .logout()// - /**/.and() // - .formLogin() // - /**/.and() // - .csrf().disable() // - .authorizeExchange() // - .anyExchange().authenticated() // - /**/.and() // - .build(); + .logout()// + /**/.and() // + .formLogin() // + /**/.and() // + .csrf() + .disable() // + .authorizeExchange() // + .anyExchange() + .authenticated() // + /**/.and() // + .build(); } @Bean MapReactiveUserDetailsService userDetailsService() { return new MapReactiveUserDetailsService(User.withUsername("admin") // - .password("{noop}password") // - .roles("USER,ADMIN") // - .build()); + .password("{noop}password") // + .roles("USER,ADMIN") // + .build()); } } @@ -183,7 +198,7 @@ MongoDBContainer mongoDbContainer() { ReactiveMongoOperations mongoOperations(MongoDBContainer mongoContainer) { MongoClient mongo = MongoClients - .create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort()); + .create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort()); return new ReactiveMongoTemplate(mongo, "test"); } diff --git a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java index 0e68f9407..331ed9b85 100644 --- a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java +++ b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java @@ -86,13 +86,13 @@ protected void ensureIndexes(IndexOperations sessionCollectionIndexes) { LOG.info("Creating TTL index on field " + EXPIRE_AT_FIELD_NAME); sessionCollectionIndexes - .ensureIndex(new Index(EXPIRE_AT_FIELD_NAME, Sort.Direction.ASC).named(EXPIRE_AT_FIELD_NAME).expire(0)); + .ensureIndex(new Index(EXPIRE_AT_FIELD_NAME, Sort.Direction.ASC).named(EXPIRE_AT_FIELD_NAME).expire(0)); } protected String extractPrincipal(MongoSession expiringSession) { return this.indexResolver.resolveIndexesFor(expiringSession) - .get(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME); + .get(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME); } public Set getConvertibleTypes() { diff --git a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/MongoIndexedSessionRepository.java b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/MongoIndexedSessionRepository.java index 3c5f5aff4..e2a3d2f7e 100644 --- a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/MongoIndexedSessionRepository.java +++ b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/MongoIndexedSessionRepository.java @@ -137,10 +137,11 @@ public MongoSession findById(String id) { public Map findByIndexNameAndIndexValue(String indexName, String indexValue) { return Optional.ofNullable(this.mongoSessionConverter.getQueryForIndex(indexName, indexValue)) - .map((query) -> this.mongoOperations.find(query, Document.class, this.collectionName)) - .orElse(Collections.emptyList()).stream() - .map((dbSession) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, dbSession)) - .collect(Collectors.toMap(MongoSession::getId, (mapSession) -> mapSession)); + .map((query) -> this.mongoOperations.find(query, Document.class, this.collectionName)) + .orElse(Collections.emptyList()) + .stream() + .map((dbSession) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, dbSession)) + .collect(Collectors.toMap(MongoSession::getId, (mapSession) -> mapSession)); } @Override diff --git a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepository.java b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepository.java index 71c06c351..78b9ebc3c 100644 --- a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepository.java +++ b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepository.java @@ -95,50 +95,50 @@ public ReactiveMongoSessionRepository(ReactiveMongoOperations mongoOperations) { public Mono createSession() { return Mono.justOrEmpty(this.defaultMaxInactiveInterval.toSeconds()) // - .map(MongoSession::new) // - .doOnNext((mongoSession) -> publishEvent(new SessionCreatedEvent(this, mongoSession))) // - .switchIfEmpty(Mono.just(new MongoSession())); + .map(MongoSession::new) // + .doOnNext((mongoSession) -> publishEvent(new SessionCreatedEvent(this, mongoSession))) // + .switchIfEmpty(Mono.just(new MongoSession())); } @Override public Mono save(MongoSession session) { return Mono // - .justOrEmpty(MongoSessionUtils.convertToDBObject(this.mongoSessionConverter, session)) // - .flatMap((dbObject) -> { - if (session.hasChangedSessionId()) { - - return this.mongoOperations - .remove(Query.query(Criteria.where("_id").is(session.getOriginalSessionId())), - this.collectionName) // - .then(this.mongoOperations.save(dbObject, this.collectionName)); - } - else { - - return this.mongoOperations.save(dbObject, this.collectionName); - } - }) // - .then(); + .justOrEmpty(MongoSessionUtils.convertToDBObject(this.mongoSessionConverter, session)) // + .flatMap((dbObject) -> { + if (session.hasChangedSessionId()) { + + return this.mongoOperations + .remove(Query.query(Criteria.where("_id").is(session.getOriginalSessionId())), + this.collectionName) // + .then(this.mongoOperations.save(dbObject, this.collectionName)); + } + else { + + return this.mongoOperations.save(dbObject, this.collectionName); + } + }) // + .then(); } @Override public Mono findById(String id) { return findSession(id) // - .map((document) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, document)) // - .filter((mongoSession) -> !mongoSession.isExpired()) // - .switchIfEmpty(Mono.defer(() -> this.deleteById(id).then(Mono.empty()))); + .map((document) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, document)) // + .filter((mongoSession) -> !mongoSession.isExpired()) // + .switchIfEmpty(Mono.defer(() -> this.deleteById(id).then(Mono.empty()))); } @Override public Mono deleteById(String id) { return findSession(id) // - .flatMap((document) -> this.mongoOperations.remove(document, this.collectionName) // - .then(Mono.just(document))) // - .map((document) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, document)) // - .doOnNext((mongoSession) -> publishEvent(new SessionDeletedEvent(this, mongoSession))) // - .then(); + .flatMap((document) -> this.mongoOperations.remove(document, this.collectionName) // + .then(Mono.just(document))) // + .map((document) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, document)) // + .doOnNext((mongoSession) -> publishEvent(new SessionDeletedEvent(this, mongoSession))) // + .then(); } /** diff --git a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.java b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.java index 3a920d05a..86cc11ea3 100644 --- a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.java +++ b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.java @@ -100,7 +100,7 @@ public MongoIndexedSessionRepository mongoSessionRepository(MongoOperations mong } this.sessionRepositoryCustomizers - .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(repository)); + .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(repository)); return repository; } @@ -121,11 +121,11 @@ public void setMaxInactiveIntervalInSeconds(Integer maxInactiveIntervalInSeconds public void setImportMetadata(AnnotationMetadata importMetadata) { AnnotationAttributes attributes = AnnotationAttributes - .fromMap(importMetadata.getAnnotationAttributes(EnableMongoHttpSession.class.getName())); + .fromMap(importMetadata.getAnnotationAttributes(EnableMongoHttpSession.class.getName())); if (attributes != null) { this.maxInactiveInterval = Duration - .ofSeconds(attributes.getNumber("maxInactiveIntervalInSeconds")); + .ofSeconds(attributes.getNumber("maxInactiveIntervalInSeconds")); } String collectionNameValue = (attributes != null) ? attributes.getString("collectionName") : ""; diff --git a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java index 197d599a8..008cbb035 100644 --- a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java +++ b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java @@ -110,7 +110,7 @@ public ReactiveMongoSessionRepository reactiveMongoSessionRepository(ReactiveMon } this.sessionRepositoryCustomizers - .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(repository)); + .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(repository)); return repository; } @@ -124,11 +124,11 @@ public void setMongoSessionConverter(AbstractMongoSessionConverter mongoSessionC public void setImportMetadata(AnnotationMetadata importMetadata) { AnnotationAttributes attributes = AnnotationAttributes - .fromMap(importMetadata.getAnnotationAttributes(EnableMongoWebSession.class.getName())); + .fromMap(importMetadata.getAnnotationAttributes(EnableMongoWebSession.class.getName())); if (attributes != null) { this.maxInactiveInterval = Duration - .ofSeconds(attributes.getNumber("maxInactiveIntervalInSeconds")); + .ofSeconds(attributes.getNumber("maxInactiveIntervalInSeconds")); } String collectionNameValue = (attributes != null) ? attributes.getString("collectionName") : ""; diff --git a/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/JacksonMongoSessionConverterTest.java b/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/JacksonMongoSessionConverterTest.java index c9a78eea3..bf96b479b 100644 --- a/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/JacksonMongoSessionConverterTest.java +++ b/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/JacksonMongoSessionConverterTest.java @@ -89,7 +89,7 @@ void shouldAllowCustomObjectMapper() { void shouldNotAllowNullObjectMapperToBeInjected() { Assertions.assertThatIllegalArgumentException() - .isThrownBy(() -> new JacksonMongoSessionConverter((ObjectMapper) null)); + .isThrownBy(() -> new JacksonMongoSessionConverter((ObjectMapper) null)); } @Test diff --git a/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/JdkMongoSessionConverterTest.java b/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/JdkMongoSessionConverterTest.java index b06db7374..746adacdc 100644 --- a/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/JdkMongoSessionConverterTest.java +++ b/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/JdkMongoSessionConverterTest.java @@ -43,14 +43,14 @@ AbstractMongoSessionConverter getMongoSessionConverter() { @Test void constructorNullSerializer() { - assertThatIllegalArgumentException().isThrownBy( - () -> new JdkMongoSessionConverter(null, new DeserializingConverter(), this.inactiveInterval)); + assertThatIllegalArgumentException() + .isThrownBy(() -> new JdkMongoSessionConverter(null, new DeserializingConverter(), this.inactiveInterval)); } @Test void constructorNullDeserializer() { - assertThatIllegalArgumentException().isThrownBy( - () -> new JdkMongoSessionConverter(new SerializingConverter(), null, this.inactiveInterval)); + assertThatIllegalArgumentException() + .isThrownBy(() -> new JdkMongoSessionConverter(new SerializingConverter(), null, this.inactiveInterval)); } } diff --git a/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/MongoIndexedSessionRepositoryTest.java b/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/MongoIndexedSessionRepositoryTest.java index c33ce79d9..9c25d47b9 100644 --- a/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/MongoIndexedSessionRepositoryTest.java +++ b/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/MongoIndexedSessionRepositoryTest.java @@ -77,7 +77,7 @@ void shouldCreateSession() { // then assertThat(session.getId()).isNotEmpty(); assertThat(session.getMaxInactiveInterval().getSeconds()) - .isEqualTo(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS); + .isEqualTo(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS); } @Test @@ -88,7 +88,8 @@ void shouldSaveSession() { BasicDBObject dbSession = new BasicDBObject(); given(this.converter.convert(session, TypeDescriptor.valueOf(MongoSession.class), - TypeDescriptor.valueOf(DBObject.class))).willReturn(dbSession); + TypeDescriptor.valueOf(DBObject.class))) + .willReturn(dbSession); // when this.repository.save(session); @@ -104,12 +105,14 @@ void shouldGetSession() { Document sessionDocument = new Document(); given(this.mongoOperations.findById(sessionId, Document.class, - MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(sessionDocument); + MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME)) + .willReturn(sessionDocument); MongoSession session = new MongoSession(); given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class), - TypeDescriptor.valueOf(MongoSession.class))).willReturn(session); + TypeDescriptor.valueOf(MongoSession.class))) + .willReturn(session); // when MongoSession retrievedSession = this.repository.findById(sessionId); @@ -126,13 +129,15 @@ void shouldHandleExpiredSession() { Document sessionDocument = new Document(); given(this.mongoOperations.findById(sessionId, Document.class, - MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(sessionDocument); + MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME)) + .willReturn(sessionDocument); MongoSession session = mock(MongoSession.class); given(session.isExpired()).willReturn(true); given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class), - TypeDescriptor.valueOf(MongoSession.class))).willReturn(session); + TypeDescriptor.valueOf(MongoSession.class))) + .willReturn(session); given(session.getId()).willReturn("sessionId"); // when @@ -155,9 +160,11 @@ void shouldDeleteSession() { MongoSession mongoSession = new MongoSession(sessionId, MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS); given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class), - TypeDescriptor.valueOf(MongoSession.class))).willReturn(mongoSession); + TypeDescriptor.valueOf(MongoSession.class))) + .willReturn(mongoSession); given(this.mongoOperations.findById(eq(sessionId), eq(Document.class), - eq(MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME))).willReturn(sessionDocument); + eq(MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME))) + .willReturn(sessionDocument); // when this.repository.deleteById(sessionId); @@ -178,14 +185,15 @@ void shouldGetSessionsMapByPrincipal() { given(this.converter.getQueryForIndex(anyString(), any(Object.class))).willReturn(mock(Query.class)); given(this.mongoOperations.find(any(Query.class), eq(Document.class), eq(MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME))) - .willReturn(Collections.singletonList(document)); + .willReturn(Collections.singletonList(document)); String sessionId = UUID.randomUUID().toString(); MongoSession session = new MongoSession(sessionId, 1800); given(this.converter.convert(document, TypeDescriptor.valueOf(Document.class), - TypeDescriptor.valueOf(MongoSession.class))).willReturn(session); + TypeDescriptor.valueOf(MongoSession.class))) + .willReturn(session); // when Map sessionsMap = this.repository.findByIndexNameAndIndexValue(principalNameIndexName, diff --git a/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepositoryTest.java b/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepositoryTest.java index ed6966a79..51fce8ce7 100644 --- a/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepositoryTest.java +++ b/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepositoryTest.java @@ -83,14 +83,14 @@ void setUp() { void shouldCreateSession() { this.repository.createSession() // - .as(StepVerifier::create) // - .expectNextMatches((mongoSession) -> { - assertThat(mongoSession.getId()).isNotEmpty(); - assertThat(mongoSession.getMaxInactiveInterval()) - .isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS)); - return true; - }) // - .verifyComplete(); + .as(StepVerifier::create) // + .expectNextMatches((mongoSession) -> { + assertThat(mongoSession.getId()).isNotEmpty(); + assertThat(mongoSession.getMaxInactiveInterval()) + .isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS)); + return true; + }) // + .verifyComplete(); } @Test @@ -101,14 +101,15 @@ void shouldSaveSession() { BasicDBObject dbSession = new BasicDBObject(); given(this.converter.convert(session, TypeDescriptor.valueOf(MongoSession.class), - TypeDescriptor.valueOf(DBObject.class))).willReturn(dbSession); + TypeDescriptor.valueOf(DBObject.class))) + .willReturn(dbSession); given(this.mongoOperations.save(dbSession, "sessions")).willReturn(Mono.just(dbSession)); // when this.repository.save(session) // - .as(StepVerifier::create) // - .verifyComplete(); + .as(StepVerifier::create) // + .verifyComplete(); verify(this.mongoOperations).save(dbSession, ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME); } @@ -121,18 +122,20 @@ void shouldGetSession() { Document sessionDocument = new Document(); given(this.mongoOperations.findById(sessionId, Document.class, - ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument)); + ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME)) + .willReturn(Mono.just(sessionDocument)); MongoSession session = new MongoSession(); given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class), - TypeDescriptor.valueOf(MongoSession.class))).willReturn(session); + TypeDescriptor.valueOf(MongoSession.class))) + .willReturn(session); // when this.repository.findById(sessionId) // - .as(StepVerifier::create) // - .expectNext(session) // - .verifyComplete(); + .as(StepVerifier::create) // + .expectNext(session) // + .verifyComplete(); } @Test @@ -143,21 +146,23 @@ void shouldHandleExpiredSession() { Document sessionDocument = new Document(); given(this.mongoOperations.findById(sessionId, Document.class, - ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument)); + ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME)) + .willReturn(Mono.just(sessionDocument)); given(this.mongoOperations.remove(sessionDocument, ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME)) - .willReturn(Mono.just(DeleteResult.acknowledged(1))); + .willReturn(Mono.just(DeleteResult.acknowledged(1))); MongoSession session = mock(MongoSession.class); given(session.isExpired()).willReturn(true); given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class), - TypeDescriptor.valueOf(MongoSession.class))).willReturn(session); + TypeDescriptor.valueOf(MongoSession.class))) + .willReturn(session); // when this.repository.findById(sessionId) // - .as(StepVerifier::create) // - .verifyComplete(); + .as(StepVerifier::create) // + .verifyComplete(); // then verify(this.mongoOperations).remove(any(Document.class), @@ -172,20 +177,22 @@ void shouldDeleteSession() { Document sessionDocument = new Document(); given(this.mongoOperations.findById(sessionId, Document.class, - ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument)); + ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME)) + .willReturn(Mono.just(sessionDocument)); given(this.mongoOperations.remove(sessionDocument, "sessions")) - .willReturn(Mono.just(DeleteResult.acknowledged(1))); + .willReturn(Mono.just(DeleteResult.acknowledged(1))); MongoSession session = mock(MongoSession.class); given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class), - TypeDescriptor.valueOf(MongoSession.class))).willReturn(session); + TypeDescriptor.valueOf(MongoSession.class))) + .willReturn(session); // when this.repository.deleteById(sessionId) // - .as(StepVerifier::create) // - .verifyComplete(); + .as(StepVerifier::create) // + .verifyComplete(); verify(this.mongoOperations).remove(any(Document.class), eq(ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME)); diff --git a/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfigurationTest.java b/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfigurationTest.java index 6612628da..a10655ab3 100644 --- a/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfigurationTest.java +++ b/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfigurationTest.java @@ -72,8 +72,8 @@ void after() { void noMongoOperationsConfiguration() { assertThatExceptionOfType(UnsatisfiedDependencyException.class) - .isThrownBy(() -> registerAndRefresh(EmptyConfiguration.class)) - .withMessageContaining("mongoSessionRepository"); + .isThrownBy(() -> registerAndRefresh(EmptyConfiguration.class)) + .withMessageContaining("mongoSessionRepository"); } @Test @@ -114,7 +114,7 @@ void customMaxInactiveIntervalInSeconds() { MongoIndexedSessionRepository repository = this.context.getBean(MongoIndexedSessionRepository.class); assertThat(repository).extracting("defaultMaxInactiveInterval") - .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } @Test @@ -125,7 +125,7 @@ void setCustomMaxInactiveIntervalInSeconds() { MongoIndexedSessionRepository repository = this.context.getBean(MongoIndexedSessionRepository.class); assertThat(repository).extracting("defaultMaxInactiveInterval") - .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } @Test @@ -145,7 +145,7 @@ void setCustomSessionConverterConfiguration() { void resolveCollectionNameByPropertyPlaceholder() { this.context - .setEnvironment(new MockEnvironment().withProperty("session.mongo.collectionName", COLLECTION_NAME)); + .setEnvironment(new MockEnvironment().withProperty("session.mongo.collectionName", COLLECTION_NAME)); registerAndRefresh(CustomMongoJdbcSessionConfiguration.class); MongoHttpSessionConfiguration configuration = this.context.getBean(MongoHttpSessionConfiguration.class); @@ -174,8 +174,8 @@ void customIndexResolverConfigurationWithDefaultMongoSessionConverter() { assertThat(repository).isNotNull(); assertThat(indexResolver).isNotNull(); - assertThat(repository).extracting("mongoSessionConverter").hasFieldOrPropertyWithValue("indexResolver", - indexResolver); + assertThat(repository).extracting("mongoSessionConverter") + .hasFieldOrPropertyWithValue("indexResolver", indexResolver); } @Test @@ -189,8 +189,8 @@ void customIndexResolverConfigurationWithProvidedMongoSessionConverter() { assertThat(repository).isNotNull(); assertThat(indexResolver).isNotNull(); - assertThat(repository).extracting("mongoSessionConverter").hasFieldOrPropertyWithValue("indexResolver", - indexResolver); + assertThat(repository).extracting("mongoSessionConverter") + .hasFieldOrPropertyWithValue("indexResolver", indexResolver); } @Test diff --git a/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java b/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java index 46f2029d5..6ed70d35d 100644 --- a/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java +++ b/spring-session-data-mongodb/src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java @@ -95,9 +95,8 @@ void missingReactorSessionRepositoryBreaksAppContext() { this.context.register(BadConfig.class); assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(this.context::refresh) - .withMessageContaining("Error creating bean with name 'reactiveMongoSessionRepository'") - .withMessageContaining( - "No qualifying bean of type '" + ReactiveMongoOperations.class.getCanonicalName()); + .withMessageContaining("Error creating bean with name 'reactiveMongoSessionRepository'") + .withMessageContaining("No qualifying bean of type '" + ReactiveMongoOperations.class.getCanonicalName()); } @Test @@ -193,8 +192,8 @@ void customIndexResolverConfigurationWithDefaultMongoSessionConverter() { assertThat(repository).isNotNull(); assertThat(indexResolver).isNotNull(); - assertThat(repository).extracting("mongoSessionConverter").hasFieldOrPropertyWithValue("indexResolver", - indexResolver); + assertThat(repository).extracting("mongoSessionConverter") + .hasFieldOrPropertyWithValue("indexResolver", indexResolver); } @Test @@ -209,8 +208,8 @@ void customIndexResolverConfigurationWithProvidedMongoSessionConverter() { assertThat(repository).isNotNull(); assertThat(indexResolver).isNotNull(); - assertThat(repository).extracting("mongoSessionConverter").hasFieldOrPropertyWithValue("indexResolver", - indexResolver); + assertThat(repository).extracting("mongoSessionConverter") + .hasFieldOrPropertyWithValue("indexResolver", indexResolver); } @Test diff --git a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryITests.java b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryITests.java index 086febad0..8de600e76 100644 --- a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryITests.java +++ b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryITests.java @@ -81,7 +81,7 @@ void saves() { assertThat(session.getId()).isEqualTo(toSave.getId()); assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames()); assertThat(session.getAttribute(expectedAttributeName)) - .isEqualTo(toSave.getAttribute(expectedAttributeName)); + .isEqualTo(toSave.getAttribute(expectedAttributeName)); this.repository.deleteById(toSave.getId()).block(); @@ -229,7 +229,7 @@ void changeSessionSaveOldSessionInstance() { toSave.setLastAccessedTime(Instant.now()); assertThatIllegalStateException().isThrownBy(() -> this.repository.save(toSave).block()) - .withMessage("Session was invalidated"); + .withMessage("Session was invalidated"); assertThat(this.repository.findById(sessionId).block()).isNull(); assertThat(this.repository.findById(session.getId()).block()).isNotNull(); @@ -240,7 +240,7 @@ void changeSessionSaveOldSessionInstance() { @SuppressWarnings("unchecked") void saveChangeSessionIdAfterCheckWhenOriginalKeyDoesNotExistsThenIgnoreError() { ReactiveRedisOperations sessionRedisOperations = (ReactiveRedisOperations) ReflectionTestUtils - .getField(this.repository, "sessionRedisOperations"); + .getField(this.repository, "sessionRedisOperations"); ReactiveRedisOperations spyOperations = spy(sessionRedisOperations); ReflectionTestUtils.setField(this.repository, "sessionRedisOperations", spyOperations); @@ -267,7 +267,8 @@ void saveWhenPutAllIsDelayedThenExpireShouldBeSet() { ReactiveHashOperations opsForHash = spy(this.sessionRedisOperations.opsForHash()); given(spy.opsForHash()).willReturn(opsForHash); willAnswer((invocation) -> Mono.delay(Duration.ofSeconds(1)).then((Mono) invocation.callRealMethod())) - .given(opsForHash).putAll(anyString(), any()); + .given(opsForHash) + .putAll(anyString(), any()); RedisSession toSave = this.repository.createSession().block(); String expectedAttributeName = "a"; diff --git a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryDynamicITests.java b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryDynamicITests.java index 893c6d482..7e816dc6d 100644 --- a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryDynamicITests.java +++ b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryDynamicITests.java @@ -81,7 +81,7 @@ private void refreshAndPrepareFields() { this.context.refresh(); this.sessionRepository = this.context.getBean(RedisIndexedSessionRepository.class); RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils - .getField(this.sessionRepository, "sessionRedisOperations"); + .getField(this.sessionRepository, "sessionRedisOperations"); this.spyOperations = spy(redisOperations); ReflectionTestUtils.setField(this.sessionRepository, "sessionRedisOperations", this.spyOperations); } diff --git a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryITests.java b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryITests.java index 5eca65983..9c289d0f9 100644 --- a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryITests.java +++ b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryITests.java @@ -119,7 +119,7 @@ void saves() throws InterruptedException { assertThat(session.getId()).isEqualTo(toSave.getId()); assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames()); assertThat(session.getAttribute(expectedAttributeName)) - .isEqualTo(toSave.getAttribute(expectedAttributeName)); + .isEqualTo(toSave.getAttribute(expectedAttributeName)); this.registry.clear(); @@ -127,11 +127,11 @@ void saves() throws InterruptedException { assertThat(this.repository.findById(toSave.getId())).isNull(); assertThat(this.registry.getEvent(toSave.getId())) - .isInstanceOf(SessionDestroyedEvent.class); + .isInstanceOf(SessionDestroyedEvent.class); assertThat(this.redis.boundSetOps(usernameSessionKey).members()).doesNotContain(toSave.getId()); assertThat(this.registry.getEvent(toSave.getId()).getSession().getAttribute(expectedAttributeName)) - .isEqualTo(expectedAttributeValue); + .isEqualTo(expectedAttributeValue); } @Test diff --git a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisSessionRepositoryITests.java b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisSessionRepositoryITests.java index 6ea5963a2..00cdf526b 100644 --- a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisSessionRepositoryITests.java +++ b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisSessionRepositoryITests.java @@ -54,7 +54,7 @@ class RedisSessionRepositoryITests extends AbstractRedisITests { void save_NewSession_ShouldSaveSession() { RedisSession session = createAndSaveSession(Instant.now()); assertThat(session.getMaxInactiveInterval()) - .isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS)); + .isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS)); assertThat(session.getAttributeNames()).isEqualTo(Collections.singleton("attribute1")); assertThat(session.getAttribute("attribute1")).isEqualTo("value1"); } @@ -69,7 +69,7 @@ void save_DeletedSession_ShouldThrowException() { RedisSession session = createAndSaveSession(Instant.now()); this.sessionRepository.deleteById(session.getId()); assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(session)) - .withMessage("Session was invalidated"); + .withMessage("Session was invalidated"); } @Test @@ -160,7 +160,7 @@ void save_ChangeSessionIdOnDeletedSession_ShouldThrowException() { updateSession(session, Instant.now(), "attribute1", "value1"); String newSessionId = session.changeSessionId(); assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(session)) - .withMessage("Session was invalidated"); + .withMessage("Session was invalidated"); assertThat(this.sessionRepository.findById(newSessionId)).isNull(); assertThat(this.sessionRepository.findById(originalSessionId)).isNull(); } @@ -177,7 +177,7 @@ void save_ChangeSessionIdConcurrent_ShouldThrowException() { updateSession(copy2, now.plusSeconds(2L), "attribute3", "value3"); String newSessionId2 = copy2.changeSessionId(); assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(copy2)) - .withMessage("Session was invalidated"); + .withMessage("Session was invalidated"); assertThat(this.sessionRepository.findById(newSessionId1)).isNotNull(); assertThat(this.sessionRepository.findById(newSessionId2)).isNull(); assertThat(this.sessionRepository.findById(originalSessionId)).isNull(); diff --git a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/taskexecutor/RedisListenerContainerTaskExecutorITests.java b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/taskexecutor/RedisListenerContainerTaskExecutorITests.java index 0345e123f..15dc00ec2 100644 --- a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/taskexecutor/RedisListenerContainerTaskExecutorITests.java +++ b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/taskexecutor/RedisListenerContainerTaskExecutorITests.java @@ -56,7 +56,7 @@ class RedisListenerContainerTaskExecutorITests extends AbstractRedisITests { @Test void testRedisDelEventsAreDispatchedInSessionTaskExecutor() throws InterruptedException { BoundSetOperations ops = this.redis - .boundSetOps("spring:session:RedisListenerContainerTaskExecutorITests:expirations:dummy"); + .boundSetOps("spring:session:RedisListenerContainerTaskExecutorITests:expirations:dummy"); ops.add("value"); ops.remove("value"); assertThat(this.executor.taskDispatched()).isTrue(); diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisSessionRepository.java index b0897939a..932ec4909 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisSessionRepository.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisSessionRepository.java @@ -133,8 +133,9 @@ public Mono save(RedisSession session) { return session.save(); } String sessionKey = getSessionKey(session.hasChangedSessionId() ? session.originalSessionId : session.getId()); - return this.sessionRedisOperations.hasKey(sessionKey).flatMap( - (exists) -> exists ? session.save() : Mono.error(new IllegalStateException("Session was invalidated"))); + return this.sessionRedisOperations.hasKey(sessionKey) + .flatMap((exists) -> exists ? session.save() + : Mono.error(new IllegalStateException("Session was invalidated"))); } @Override @@ -283,7 +284,7 @@ private Mono saveDelta() { String sessionKey = getSessionKey(getId()); Mono update = ReactiveRedisSessionRepository.this.sessionRedisOperations.opsForHash() - .putAll(sessionKey, new HashMap<>(this.delta)); + .putAll(sessionKey, new HashMap<>(this.delta)); Mono setTtl; if (getMaxInactiveInterval().getSeconds() >= 0) { setTtl = ReactiveRedisSessionRepository.this.sessionRedisOperations.expire(sessionKey, @@ -320,10 +321,11 @@ private Mono saveChangeSessionId() { String sessionKey = getSessionKey(sessionId); return ReactiveRedisSessionRepository.this.sessionRedisOperations.rename(originalSessionKey, sessionKey) - .flatMap((unused) -> Mono.fromDirect(replaceSessionId)).onErrorResume((ex) -> { - String message = NestedExceptionUtils.getMostSpecificCause(ex).getMessage(); - return StringUtils.startsWithIgnoreCase(message, "ERR no such key"); - }, (ex) -> Mono.empty()); + .flatMap((unused) -> Mono.fromDirect(replaceSessionId)) + .onErrorResume((ex) -> { + String message = NestedExceptionUtils.getMostSpecificCause(ex).getMessage(); + return StringUtils.startsWithIgnoreCase(message, "ERR no such key"); + }, (ex) -> Mono.empty()); } } diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java index 48ef4f919..96a62e575 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java @@ -857,7 +857,7 @@ private void saveDelta() { if (this.originalPrincipalName != null) { String originalPrincipalRedisKey = getPrincipalKey(this.originalPrincipalName); RedisIndexedSessionRepository.this.sessionRedisOperations.boundSetOps(originalPrincipalRedisKey) - .remove(sessionId); + .remove(sessionId); } Map indexes = RedisIndexedSessionRepository.this.indexResolver.resolveIndexesFor(this); String principal = indexes.get(PRINCIPAL_NAME_INDEX_NAME); @@ -865,7 +865,7 @@ private void saveDelta() { if (principal != null) { String principalRedisKey = getPrincipalKey(principal); RedisIndexedSessionRepository.this.sessionRedisOperations.boundSetOps(principalRedisKey) - .add(sessionId); + .add(sessionId); } } if (this.isNew) { @@ -905,9 +905,9 @@ private void saveChangeSessionId() { if (this.originalPrincipalName != null) { String originalPrincipalRedisKey = getPrincipalKey(this.originalPrincipalName); RedisIndexedSessionRepository.this.sessionRedisOperations.boundSetOps(originalPrincipalRedisKey) - .remove(this.originalSessionId); + .remove(this.originalSessionId); RedisIndexedSessionRepository.this.sessionRedisOperations.boundSetOps(originalPrincipalRedisKey) - .add(sessionId); + .add(sessionId); } } this.originalSessionId = sessionId; diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionRepository.java index d2408a701..e317dfb63 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionRepository.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionRepository.java @@ -298,7 +298,7 @@ private void saveDelta() { RedisSessionRepository.this.sessionRedisOperations.opsForHash().putAll(key, new HashMap<>(this.delta)); RedisSessionRepository.this.sessionRedisOperations.expireAt(key, Instant.ofEpochMilli(getLastAccessedTime().toEpochMilli()) - .plusSeconds(getMaxInactiveInterval().getSeconds())); + .plusSeconds(getMaxInactiveInterval().getSeconds())); this.delta.clear(); } diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/AbstractRedisHttpSessionConfiguration.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/AbstractRedisHttpSessionConfiguration.java index 4bef3626d..8b8de1e65 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/AbstractRedisHttpSessionConfiguration.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/AbstractRedisHttpSessionConfiguration.java @@ -119,7 +119,7 @@ public void setRedisConnectionFactory( @SpringSessionRedisConnectionFactory ObjectProvider springSessionRedisConnectionFactory, ObjectProvider redisConnectionFactory) { this.redisConnectionFactory = springSessionRedisConnectionFactory - .getIfAvailable(redisConnectionFactory::getObject); + .getIfAvailable(redisConnectionFactory::getObject); } protected RedisConnectionFactory getRedisConnectionFactory() { diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.java index c3e7a5e51..bf9465fa8 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.java @@ -61,7 +61,7 @@ public RedisSessionRepository sessionRepository() { sessionRepository.setFlushMode(getFlushMode()); sessionRepository.setSaveMode(getSaveMode()); getSessionRepositoryCustomizers() - .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository)); + .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository)); return sessionRepository; } @@ -73,7 +73,7 @@ public void setEmbeddedValueResolver(StringValueResolver resolver) { @Override public void setImportMetadata(AnnotationMetadata importMetadata) { Map attributeMap = importMetadata - .getAnnotationAttributes(EnableRedisHttpSession.class.getName()); + .getAnnotationAttributes(EnableRedisHttpSession.class.getName()); AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap); if (attributes == null) { return; diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisIndexedHttpSessionConfiguration.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisIndexedHttpSessionConfiguration.java index c6c4243d5..f7a34d46f 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisIndexedHttpSessionConfiguration.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisIndexedHttpSessionConfiguration.java @@ -102,7 +102,7 @@ public RedisIndexedSessionRepository sessionRepository() { int database = resolveDatabase(); sessionRepository.setDatabase(database); getSessionRepositoryCustomizers() - .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository)); + .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository)); return sessionRepository; } @@ -174,7 +174,7 @@ public void setEmbeddedValueResolver(StringValueResolver resolver) { @Override public void setImportMetadata(AnnotationMetadata importMetadata) { Map attributeMap = importMetadata - .getAnnotationAttributes(EnableRedisIndexedHttpSession.class.getName()); + .getAnnotationAttributes(EnableRedisIndexedHttpSession.class.getName()); AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap); if (attributes == null) { return; diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/server/RedisWebSessionConfiguration.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/server/RedisWebSessionConfiguration.java index d716f6362..132e5bc1f 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/server/RedisWebSessionConfiguration.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/server/RedisWebSessionConfiguration.java @@ -87,7 +87,7 @@ public ReactiveRedisSessionRepository sessionRepository() { } sessionRepository.setSaveMode(this.saveMode); this.sessionRepositoryCustomizers - .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository)); + .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository)); return sessionRepository; } @@ -113,7 +113,7 @@ public void setRedisConnectionFactory( @SpringSessionRedisConnectionFactory ObjectProvider springSessionRedisConnectionFactory, ObjectProvider redisConnectionFactory) { ReactiveRedisConnectionFactory redisConnectionFactoryToUse = springSessionRedisConnectionFactory - .getIfAvailable(); + .getIfAvailable(); if (redisConnectionFactoryToUse == null) { redisConnectionFactoryToUse = redisConnectionFactory.getObject(); } @@ -145,7 +145,7 @@ public void setEmbeddedValueResolver(StringValueResolver resolver) { @Override public void setImportMetadata(AnnotationMetadata importMetadata) { Map attributeMap = importMetadata - .getAnnotationAttributes(EnableRedisWebSession.class.getName()); + .getAnnotationAttributes(EnableRedisWebSession.class.getName()); AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap); if (attributes == null) { return; @@ -163,8 +163,10 @@ private ReactiveRedisTemplate createReactiveRedisTemplate() { RedisSerializer defaultSerializer = (this.defaultRedisSerializer != null) ? this.defaultRedisSerializer : new JdkSerializationRedisSerializer(this.classLoader); RedisSerializationContext serializationContext = RedisSerializationContext - .newSerializationContext(defaultSerializer).key(keySerializer).hashKey(keySerializer) - .build(); + .newSerializationContext(defaultSerializer) + .key(keySerializer) + .hashKey(keySerializer) + .build(); return new ReactiveRedisTemplate<>(this.redisConnectionFactory, serializationContext); } diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryTests.java index a85b9d367..3206f09bc 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryTests.java @@ -79,7 +79,7 @@ void setUp() { @Test void constructorWithNullReactiveRedisOperations() { assertThatIllegalArgumentException().isThrownBy(() -> new ReactiveRedisSessionRepository(null)) - .withMessageContaining("sessionRedisOperations cannot be null"); + .withMessageContaining("sessionRedisOperations cannot be null"); } @Test @@ -92,13 +92,13 @@ void customRedisKeyNamespace() { @Test void nullRedisKeyNamespace() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setRedisKeyNamespace(null)) - .withMessage("namespace cannot be null or empty"); + .withMessage("namespace cannot be null or empty"); } @Test void emptyRedisKeyNamespace() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setRedisKeyNamespace("")) - .withMessage("namespace cannot be null or empty"); + .withMessage("namespace cannot be null or empty"); } @Test @@ -112,9 +112,9 @@ void customMaxInactiveInterval() { @Test void createSessionDefaultMaxInactiveInterval() { StepVerifier.create(this.repository.createSession()) - .consumeNextWith((session) -> assertThat(session.getMaxInactiveInterval()) - .isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS))) - .verifyComplete(); + .consumeNextWith((session) -> assertThat(session.getMaxInactiveInterval()) + .isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS))) + .verifyComplete(); } @Test @@ -123,8 +123,8 @@ void createSessionCustomMaxInactiveInterval() { this.repository.setDefaultMaxInactiveInterval(interval); StepVerifier.create(this.repository.createSession()) - .consumeNextWith((session) -> assertThat(session.getMaxInactiveInterval()).isEqualTo(interval)) - .verifyComplete(); + .consumeNextWith((session) -> assertThat(session.getMaxInactiveInterval()).isEqualTo(interval)) + .verifyComplete(); } @Test @@ -145,11 +145,11 @@ void saveNewSession() { Map delta = this.delta.getAllValues().get(0); assertThat(delta.size()).isEqualTo(3); assertThat(delta.get(RedisSessionMapper.CREATION_TIME_KEY)) - .isEqualTo(newSession.getCreationTime().toEpochMilli()); + .isEqualTo(newSession.getCreationTime().toEpochMilli()); assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY)) - .isEqualTo((int) newSession.getMaxInactiveInterval().getSeconds()); + .isEqualTo((int) newSession.getMaxInactiveInterval().getSeconds()); assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY)) - .isEqualTo(newSession.getLastAccessedTime().toEpochMilli()); + .isEqualTo(newSession.getLastAccessedTime().toEpochMilli()); } @Test @@ -172,11 +172,11 @@ void saveCustomNegativeMaxInactiveIntervalNewSession() { Map delta = this.delta.getAllValues().get(0); assertThat(delta.size()).isEqualTo(3); assertThat(delta.get(RedisSessionMapper.CREATION_TIME_KEY)) - .isEqualTo(newSession.getCreationTime().toEpochMilli()); + .isEqualTo(newSession.getCreationTime().toEpochMilli()); assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY)) - .isEqualTo((int) newSession.getMaxInactiveInterval().getSeconds()); + .isEqualTo((int) newSession.getMaxInactiveInterval().getSeconds()); assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY)) - .isEqualTo(newSession.getLastAccessedTime().toEpochMilli()); + .isEqualTo(newSession.getLastAccessedTime().toEpochMilli()); } @Test @@ -211,8 +211,8 @@ void saveLastAccessChanged() { verifyNoMoreInteractions(this.redisOperations); verifyNoMoreInteractions(this.hashOperations); - assertThat(this.delta.getAllValues().get(0)).isEqualTo( - map(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, session.getLastAccessedTime().toEpochMilli())); + assertThat(this.delta.getAllValues().get(0)) + .isEqualTo(map(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, session.getLastAccessedTime().toEpochMilli())); } @Test @@ -258,7 +258,7 @@ void saveRemoveAttribute() { verifyNoMoreInteractions(this.hashOperations); assertThat(this.delta.getAllValues().get(0)) - .isEqualTo(map(RedisIndexedSessionRepository.getSessionAttrNameKey(attrName), null)); + .isEqualTo(map(RedisIndexedSessionRepository.getSessionAttrNameKey(attrName), null)); } @Test @@ -328,10 +328,10 @@ void getSessionFound() { assertThat(session.getAttribute(attribute1)).isEqualTo(expected.getAttribute(attribute1)); assertThat(session.getAttribute(attribute2)).isEqualTo(expected.getAttribute(attribute2)); assertThat(session.getCreationTime().truncatedTo(ChronoUnit.MILLIS)) - .isEqualTo(expected.getCreationTime().truncatedTo(ChronoUnit.MILLIS)); + .isEqualTo(expected.getCreationTime().truncatedTo(ChronoUnit.MILLIS)); assertThat(session.getMaxInactiveInterval()).isEqualTo(expected.getMaxInactiveInterval()); assertThat(session.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS)) - .isEqualTo(expected.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS)); + .isEqualTo(expected.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS)); }).verifyComplete(); } diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryTests.java index 697749e60..d0c9bafc3 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryTests.java @@ -112,7 +112,7 @@ void setup() { @Test void setApplicationEventPublisherNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setApplicationEventPublisher(null)) - .withMessage("applicationEventPublisher cannot be null"); + .withMessage("applicationEventPublisher cannot be null"); } @Test @@ -178,9 +178,9 @@ void saveNewSession() { Object creationTime = delta.get(RedisSessionMapper.CREATION_TIME_KEY); assertThat(creationTime).isEqualTo(session.getCreationTime().toEpochMilli()); assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY)) - .isEqualTo((int) Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS).getSeconds()); + .isEqualTo((int) Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS).getSeconds()); assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY)) - .isEqualTo(session.getCreationTime().toEpochMilli()); + .isEqualTo(session.getCreationTime().toEpochMilli()); } // gh-467 @@ -199,7 +199,7 @@ void saveJavadocSummary() { String sessionKey = "spring:session:sessions:" + session.getId(); String backgroundExpireKey = "spring:session:expirations:" + RedisSessionExpirationPolicy - .roundUpToNextMinute(RedisSessionExpirationPolicy.expiresInMillis(session)); + .roundUpToNextMinute(RedisSessionExpirationPolicy.expiresInMillis(session)); String destroyedTriggerKey = "spring:session:sessions:expires:" + session.getId(); given(this.redisOperations.boundHashOps(sessionKey)).willReturn(this.boundHashOperations); @@ -226,11 +226,11 @@ void saveJavadoc() { session.setLastAccessedTime(session.getLastAccessedTime()); given(this.redisOperations.boundHashOps("spring:session:sessions:session-id")) - .willReturn(this.boundHashOperations); + .willReturn(this.boundHashOperations); given(this.redisOperations.boundSetOps("spring:session:expirations:1404361860000")) - .willReturn(this.boundSetOperations); + .willReturn(this.boundSetOperations); given(this.redisOperations.boundValueOps("spring:session:sessions:expires:session-id")) - .willReturn(this.boundValueOperations); + .willReturn(this.boundValueOperations); this.redisRepository.save(session); @@ -252,8 +252,8 @@ void saveLastAccessChanged() { this.redisRepository.save(session); - assertThat(getDelta()).isEqualTo( - map(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, session.getLastAccessedTime().toEpochMilli())); + assertThat(getDelta()) + .isEqualTo(map(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, session.getLastAccessedTime().toEpochMilli())); } @Test @@ -362,7 +362,7 @@ void getSessionFound() { expected.setAttribute(attribute1, "test"); expected.setAttribute(attribute2, null); given(this.redisOperations.boundHashOps(getKey(expected.getId()))) - .willReturn(this.boundHashOperations); + .willReturn(this.boundHashOperations); Map map = map(RedisIndexedSessionRepository.getSessionAttrNameKey(attribute1), expected.getAttribute(attribute1), RedisIndexedSessionRepository.getSessionAttrNameKey(attribute2), expected.getAttribute(attribute2), RedisSessionMapper.CREATION_TIME_KEY, @@ -377,17 +377,17 @@ void getSessionFound() { assertThat(session.getAttribute(attribute1)).isEqualTo(expected.getAttribute(attribute1)); assertThat(session.getAttribute(attribute2)).isEqualTo(expected.getAttribute(attribute2)); assertThat(session.getCreationTime().truncatedTo(ChronoUnit.MILLIS)) - .isEqualTo(expected.getCreationTime().truncatedTo(ChronoUnit.MILLIS)); + .isEqualTo(expected.getCreationTime().truncatedTo(ChronoUnit.MILLIS)); assertThat(session.getMaxInactiveInterval()).isEqualTo(expected.getMaxInactiveInterval()); assertThat(session.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS)) - .isEqualTo(expected.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS)); + .isEqualTo(expected.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS)); } @Test void getSessionExpired() { String expiredId = "expired-id"; given(this.redisOperations.boundHashOps(getKey(expiredId))) - .willReturn(this.boundHashOperations); + .willReturn(this.boundHashOperations); Map map = map(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(), RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1, RedisSessionMapper.LAST_ACCESSED_TIME_KEY, Instant.now().minus(5, ChronoUnit.MINUTES).toEpochMilli()); @@ -402,15 +402,15 @@ void findByPrincipalNameExpired() { given(this.redisOperations.boundSetOps(anyString())).willReturn(this.boundSetOperations); given(this.boundSetOperations.members()).willReturn(Collections.singleton(expiredId)); given(this.redisOperations.boundHashOps(getKey(expiredId))) - .willReturn(this.boundHashOperations); + .willReturn(this.boundHashOperations); Map map = map(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(), RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1, RedisSessionMapper.LAST_ACCESSED_TIME_KEY, Instant.now().minus(5, ChronoUnit.MINUTES).toEpochMilli()); given(this.boundHashOperations.entries()).willReturn(map); assertThat(this.redisRepository - .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "principal")) - .isEmpty(); + .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "principal")) + .isEmpty(); } @Test @@ -422,24 +422,24 @@ void findByPrincipalName() { given(this.redisOperations.boundSetOps(anyString())).willReturn(this.boundSetOperations); given(this.boundSetOperations.members()).willReturn(Collections.singleton(sessionId)); given(this.redisOperations.boundHashOps(getKey(sessionId))) - .willReturn(this.boundHashOperations); + .willReturn(this.boundHashOperations); Map map = map(RedisSessionMapper.CREATION_TIME_KEY, createdTime.toEpochMilli(), RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, (int) maxInactive.getSeconds(), RedisSessionMapper.LAST_ACCESSED_TIME_KEY, lastAccessed.toEpochMilli()); given(this.boundHashOperations.entries()).willReturn(map); Map sessionIdToSessions = this.redisRepository - .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "principal"); + .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "principal"); assertThat(sessionIdToSessions).hasSize(1); RedisSession session = sessionIdToSessions.get(sessionId); assertThat(session).isNotNull(); assertThat(session.getId()).isEqualTo(sessionId); assertThat(session.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS)) - .isEqualTo(lastAccessed.truncatedTo(ChronoUnit.MILLIS)); + .isEqualTo(lastAccessed.truncatedTo(ChronoUnit.MILLIS)); assertThat(session.getMaxInactiveInterval()).isEqualTo(maxInactive); assertThat(session.getCreationTime().truncatedTo(ChronoUnit.MILLIS)) - .isEqualTo(createdTime.truncatedTo(ChronoUnit.MILLIS)); + .isEqualTo(createdTime.truncatedTo(ChronoUnit.MILLIS)); } @Test @@ -503,7 +503,7 @@ void onMessageCreatedCustomSerializer() { void onMessageDeletedSessionFound() { String deletedId = "deleted-id"; given(this.redisOperations.boundHashOps(getKey(deletedId))) - .willReturn(this.boundHashOperations); + .willReturn(this.boundHashOperations); Map map = map(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(), RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 0, RedisSessionMapper.LAST_ACCESSED_TIME_KEY, System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5)); @@ -531,7 +531,7 @@ void onMessageDeletedSessionFound() { void onMessageDeletedSessionNotFound() { String deletedId = "deleted-id"; given(this.redisOperations.boundHashOps(getKey(deletedId))) - .willReturn(this.boundHashOperations); + .willReturn(this.boundHashOperations); given(this.boundHashOperations.entries()).willReturn(map()); String channel = "__keyevent@0__:del"; @@ -554,7 +554,7 @@ void onMessageDeletedSessionNotFound() { void onMessageExpiredSessionFound() { String expiredId = "expired-id"; given(this.redisOperations.boundHashOps(getKey(expiredId))) - .willReturn(this.boundHashOperations); + .willReturn(this.boundHashOperations); Map map = map(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(), RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1, RedisSessionMapper.LAST_ACCESSED_TIME_KEY, System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5)); @@ -582,7 +582,7 @@ void onMessageExpiredSessionFound() { void onMessageExpiredSessionNotFound() { String expiredId = "expired-id"; given(this.redisOperations.boundHashOps(getKey(expiredId))) - .willReturn(this.boundHashOperations); + .willReturn(this.boundHashOperations); given(this.boundHashOperations.entries()).willReturn(map()); String channel = "__keyevent@0__:expired"; @@ -654,9 +654,9 @@ void flushModeImmediateCreate() { Object creationTime = delta.get(RedisSessionMapper.CREATION_TIME_KEY); assertThat(creationTime).isEqualTo(session.getCreationTime().toEpochMilli()); assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY)) - .isEqualTo((int) Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS).getSeconds()); + .isEqualTo((int) Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS).getSeconds()); assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY)) - .isEqualTo(session.getCreationTime().toEpochMilli()); + .isEqualTo(session.getCreationTime().toEpochMilli()); } @Test // gh-1409 @@ -736,26 +736,26 @@ void flushModeSetLastAccessedTime() { Map delta = getDelta(2); assertThat(delta.size()).isEqualTo(1); - assertThat(delta).isEqualTo( - map(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, session.getLastAccessedTime().toEpochMilli())); + assertThat(delta) + .isEqualTo(map(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, session.getLastAccessedTime().toEpochMilli())); } @Test void setFlushModeNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setFlushMode(null)) - .withMessage("flushMode cannot be null"); + .withMessage("flushMode cannot be null"); } @Test void setCleanupCronNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setCleanupCron(null)) - .withMessage("cleanupCron must not be null"); + .withMessage("cleanupCron must not be null"); } @Test void setCleanupCronInvalid() { assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setCleanupCron("test")) - .withMessage("cleanupCron must be valid"); + .withMessage("cleanupCron must be valid"); } @Test @@ -784,13 +784,13 @@ void changeRedisNamespace() { @Test void setRedisKeyNamespaceNullNamespace() { assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setRedisKeyNamespace(null)) - .withMessage("namespace cannot be null or empty"); + .withMessage("namespace cannot be null or empty"); } @Test void setRedisKeyNamespaceEmptyNamespace() { assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setRedisKeyNamespace(" ")) - .withMessage("namespace cannot be null or empty"); + .withMessage("namespace cannot be null or empty"); } @Test // gh-1120 diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionExpirationPolicyTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionExpirationPolicyTests.java index af4719684..7d5da8fa3 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionExpirationPolicyTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionExpirationPolicyTests.java @@ -84,7 +84,7 @@ void setup() { void onExpirationUpdatedRemovesOriginalExpirationTimeRoundedUp() { long originalExpirationTimeInMs = ONE_MINUTE_AGO; long originalRoundedToNextMinInMs = RedisSessionExpirationPolicy - .roundUpToNextMinute(originalExpirationTimeInMs); + .roundUpToNextMinute(originalExpirationTimeInMs); String originalExpireKey = this.policy.getExpirationKey(originalRoundedToNextMinInMs); this.policy.onExpirationUpdated(originalExpirationTimeInMs, this.session); @@ -98,7 +98,7 @@ void onExpirationUpdatedRemovesOriginalExpirationTimeRoundedUp() { void onExpirationUpdatedDoNotSendDeleteWhenExpirationTimeDoesNotChange() { long originalExpirationTimeInMs = RedisSessionExpirationPolicy.expiresInMillis(this.session) - 10; long originalRoundedToNextMinInMs = RedisSessionExpirationPolicy - .roundUpToNextMinute(originalExpirationTimeInMs); + .roundUpToNextMinute(originalExpirationTimeInMs); String originalExpireKey = this.policy.getExpirationKey(originalRoundedToNextMinInMs); this.policy.onExpirationUpdated(originalExpirationTimeInMs, this.session); diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionMapperTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionMapperTests.java index 3e345c590..696bf17ca 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionMapperTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionMapperTests.java @@ -48,25 +48,25 @@ void setUp() { @Test void constructor_NullId_ShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> new RedisSessionMapper(null)) - .withMessage("sessionId must not be empty"); + .withMessage("sessionId must not be empty"); } @Test void constructor_EmptyId_ShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> new RedisSessionMapper(" ")) - .withMessage("sessionId must not be empty"); + .withMessage("sessionId must not be empty"); } @Test void apply_NullMap_ShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> this.mapper.apply(null)) - .withMessage("map must not be empty"); + .withMessage("map must not be empty"); } @Test void apply_EmptyMap_ShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> this.mapper.apply(Collections.emptyMap())) - .withMessage("map must not be empty"); + .withMessage("map must not be empty"); } @Test @@ -75,7 +75,7 @@ void apply_MapWithoutCreationTime_ShouldThrowException() { sessionMap.put(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, 0L); sessionMap.put(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1800); assertThatIllegalStateException().isThrownBy(() -> this.mapper.apply(sessionMap)) - .withMessage(RedisSessionMapper.CREATION_TIME_KEY + " key must not be null"); + .withMessage(RedisSessionMapper.CREATION_TIME_KEY + " key must not be null"); } @Test @@ -84,7 +84,7 @@ void apply_MapWithoutLastAccessedTime_ShouldThrowException() { sessionMap.put(RedisSessionMapper.CREATION_TIME_KEY, 0L); sessionMap.put(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1800); assertThatIllegalStateException().isThrownBy(() -> this.mapper.apply(sessionMap)) - .withMessage(RedisSessionMapper.LAST_ACCESSED_TIME_KEY + " key must not be null"); + .withMessage(RedisSessionMapper.LAST_ACCESSED_TIME_KEY + " key must not be null"); } @Test @@ -93,7 +93,7 @@ void apply_MapWithoutMaxInactiveInterval_ShouldThrowException() { sessionMap.put(RedisSessionMapper.CREATION_TIME_KEY, 0L); sessionMap.put(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, 0L); assertThatIllegalStateException().isThrownBy(() -> this.mapper.apply(sessionMap)) - .withMessage(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY + " key must not be null"); + .withMessage(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY + " key must not be null"); } @Test diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionRepositoryTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionRepositoryTests.java index 0092e217e..f5989920e 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionRepositoryTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionRepositoryTests.java @@ -79,21 +79,21 @@ void setUp() { @Test void constructor_NullRedisOperations_ShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> new ReactiveRedisSessionRepository(null)) - .withMessageContaining("sessionRedisOperations cannot be null"); + .withMessageContaining("sessionRedisOperations cannot be null"); } @Test void setDefaultMaxInactiveInterval_ValidInterval_ShouldSetInterval() { this.sessionRepository.setDefaultMaxInactiveInterval(Duration.ofMinutes(10)); assertThat(ReflectionTestUtils.getField(this.sessionRepository, "defaultMaxInactiveInterval")) - .isEqualTo(Duration.ofMinutes(10)); + .isEqualTo(Duration.ofMinutes(10)); } @Test void setDefaultMaxInactiveInterval_NullInterval_ShouldThrowException() { assertThatIllegalArgumentException() - .isThrownBy(() -> this.sessionRepository.setDefaultMaxInactiveInterval(null)) - .withMessage("defaultMaxInactiveInterval must not be null"); + .isThrownBy(() -> this.sessionRepository.setDefaultMaxInactiveInterval(null)) + .withMessage("defaultMaxInactiveInterval must not be null"); } @Test @@ -105,13 +105,13 @@ void setRedisKeyNamespace_ValidNamespace_ShouldSetNamespace() { @Test void setRedisKeyNamespace_NullNamespace_ShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setRedisKeyNamespace(null)) - .withMessage("namespace must not be empty"); + .withMessage("namespace must not be empty"); } @Test void setRedisKeyNamespace_EmptyNamespace_ShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setRedisKeyNamespace(" ")) - .withMessage("namespace must not be empty"); + .withMessage("namespace must not be empty"); } @Test @@ -123,27 +123,27 @@ void setFlushMode_ValidFlushMode_ShouldSetFlushMode() { @Test void setFlushMode_NullFlushMode_ShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setFlushMode(null)) - .withMessage("flushMode must not be null"); + .withMessage("flushMode must not be null"); } @Test void setSaveMode_ValidSaveMode_ShouldSetSaveMode() { this.sessionRepository.setSaveMode(SaveMode.ON_GET_ATTRIBUTE); assertThat(ReflectionTestUtils.getField(this.sessionRepository, "saveMode")) - .isEqualTo(SaveMode.ON_GET_ATTRIBUTE); + .isEqualTo(SaveMode.ON_GET_ATTRIBUTE); } @Test void setSaveMode_NullSaveMode_ShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setSaveMode(null)) - .withMessage("saveMode must not be null"); + .withMessage("saveMode must not be null"); } @Test void createSession_DefaultMaxInactiveInterval_ShouldCreateSession() { RedisSession redisSession = this.sessionRepository.createSession(); assertThat(redisSession.getMaxInactiveInterval()) - .isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS)); + .isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS)); verifyNoMoreInteractions(this.sessionRedisOperations); verifyNoMoreInteractions(this.sessionHashOperations); } @@ -304,7 +304,7 @@ void saveWithSaveModeAlways() { void save_SessionNotExists_ShouldThrowException() { RedisSession session = createTestSession(); assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(session)) - .withMessage("Session was invalidated"); + .withMessage("Session was invalidated"); verify(this.sessionRedisOperations).hasKey(eq(TEST_SESSION_KEY)); verifyNoMoreInteractions(this.sessionRedisOperations); verifyNoMoreInteractions(this.sessionHashOperations); @@ -315,16 +315,16 @@ void save_SessionNotExists_ShouldThrowException() { void findById_SessionExists_ShouldReturnSession() { Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS); given(this.sessionHashOperations.entries(eq(TEST_SESSION_KEY))) - .willReturn(mapOf(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(), - RedisSessionMapper.LAST_ACCESSED_TIME_KEY, now.toEpochMilli(), - RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS, - RedisSessionMapper.ATTRIBUTE_PREFIX + "attribute1", "value1")); + .willReturn(mapOf(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(), + RedisSessionMapper.LAST_ACCESSED_TIME_KEY, now.toEpochMilli(), + RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS, + RedisSessionMapper.ATTRIBUTE_PREFIX + "attribute1", "value1")); RedisSession session = this.sessionRepository.findById(TEST_SESSION_ID); assertThat(session.getId()).isEqualTo(TEST_SESSION_ID); assertThat(session.getCreationTime()).isEqualTo(Instant.EPOCH); assertThat(session.getLastAccessedTime()).isEqualTo(now); assertThat(session.getMaxInactiveInterval()) - .isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS)); + .isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS)); assertThat(session.getAttributeNames()).isEqualTo(Collections.singleton("attribute1")); assertThat(session.getAttribute("attribute1")).isEqualTo("value1"); verify(this.sessionRedisOperations).opsForHash(); @@ -337,10 +337,10 @@ void findById_SessionExists_ShouldReturnSession() { @SuppressWarnings("unchecked") void findById_SessionExistsAndIsExpired_ShouldReturnNull() { given(this.sessionHashOperations.entries(eq(TEST_SESSION_KEY))) - .willReturn(mapOf(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(), - RedisSessionMapper.LAST_ACCESSED_TIME_KEY, Instant.EPOCH.toEpochMilli(), - RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS, - RedisSessionMapper.ATTRIBUTE_PREFIX + "attribute1", "value1")); + .willReturn(mapOf(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(), + RedisSessionMapper.LAST_ACCESSED_TIME_KEY, Instant.EPOCH.toEpochMilli(), + RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS, + RedisSessionMapper.ATTRIBUTE_PREFIX + "attribute1", "value1")); assertThat(this.sessionRepository.findById(TEST_SESSION_ID)).isNull(); verify(this.sessionRedisOperations).opsForHash(); verify(this.sessionHashOperations).entries(eq(TEST_SESSION_KEY)); @@ -379,7 +379,7 @@ private static String getSessionKey(String sessionId) { private static Instant getExpiry(RedisSession session) { return Instant.ofEpochMilli(session.getLastAccessedTime().toEpochMilli()) - .plusSeconds(session.getMaxInactiveInterval().getSeconds()); + .plusSeconds(session.getMaxInactiveInterval().getSeconds()); } private static Map mapOf(Object... objects) { diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpsSessionConfigurationTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpsSessionConfigurationTests.java index 736201c7d..a81921638 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpsSessionConfigurationTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpsSessionConfigurationTests.java @@ -86,7 +86,7 @@ void resolveValue() { @Test void resolveValueByPlaceholder() { this.context - .setEnvironment(new MockEnvironment().withProperty("session.redis.namespace", "customRedisNamespace")); + .setEnvironment(new MockEnvironment().withProperty("session.redis.namespace", "customRedisNamespace")); registerAndRefresh(RedisConfig.class, PropertySourceConfiguration.class, CustomRedisHttpSessionConfiguration2.class); RedisHttpSessionConfiguration configuration = this.context.getBean(RedisHttpSessionConfiguration.class); @@ -127,10 +127,10 @@ void qualifiedConnectionFactoryRedisConfig() { assertThat(redisConnectionFactory).isNotNull(); @SuppressWarnings("unchecked") RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils - .getField(repository, "sessionRedisOperations"); + .getField(repository, "sessionRedisOperations"); assertThat(redisOperations).isNotNull(); assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")) - .isEqualTo(redisConnectionFactory); + .isEqualTo(redisConnectionFactory); } @Test @@ -144,10 +144,10 @@ void primaryConnectionFactoryRedisConfig() { assertThat(redisConnectionFactory).isNotNull(); @SuppressWarnings("unchecked") RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils - .getField(repository, "sessionRedisOperations"); + .getField(repository, "sessionRedisOperations"); assertThat(redisOperations).isNotNull(); assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")) - .isEqualTo(redisConnectionFactory); + .isEqualTo(redisConnectionFactory); } @Test @@ -161,10 +161,10 @@ void qualifiedAndPrimaryConnectionFactoryRedisConfig() { assertThat(redisConnectionFactory).isNotNull(); @SuppressWarnings("unchecked") RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils - .getField(repository, "sessionRedisOperations"); + .getField(repository, "sessionRedisOperations"); assertThat(redisOperations).isNotNull(); assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")) - .isEqualTo(redisConnectionFactory); + .isEqualTo(redisConnectionFactory); } @Test @@ -178,17 +178,18 @@ void namedConnectionFactoryRedisConfig() { assertThat(redisConnectionFactory).isNotNull(); @SuppressWarnings("unchecked") RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils - .getField(repository, "sessionRedisOperations"); + .getField(repository, "sessionRedisOperations"); assertThat(redisOperations).isNotNull(); assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")) - .isEqualTo(redisConnectionFactory); + .isEqualTo(redisConnectionFactory); } @Test void multipleConnectionFactoryRedisConfig() { assertThatExceptionOfType(BeanCreationException.class) - .isThrownBy(() -> registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class)) - .havingRootCause().withMessageContaining("expected single matching bean but found 2"); + .isThrownBy(() -> registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class)) + .havingRootCause() + .withMessageContaining("expected single matching bean but found 2"); } @Test @@ -365,7 +366,7 @@ SessionRepositoryCustomizer sessionRepositoryCustomizerO @Order(1) SessionRepositoryCustomizer sessionRepositoryCustomizerTwo() { return (sessionRepository) -> sessionRepository - .setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } } diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisIndexedHttpSessionConfigurationTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisIndexedHttpSessionConfigurationTests.java index f89dc8b4f..68ee4c6fe 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisIndexedHttpSessionConfigurationTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisIndexedHttpSessionConfigurationTests.java @@ -84,18 +84,18 @@ void after() { void resolveValue() { registerAndRefresh(RedisConfig.class, CustomRedisHttpSessionConfiguration.class); RedisIndexedHttpSessionConfiguration configuration = this.context - .getBean(RedisIndexedHttpSessionConfiguration.class); + .getBean(RedisIndexedHttpSessionConfiguration.class); assertThat(ReflectionTestUtils.getField(configuration, "redisNamespace")).isEqualTo("myRedisNamespace"); } @Test void resolveValueByPlaceholder() { this.context - .setEnvironment(new MockEnvironment().withProperty("session.redis.namespace", "customRedisNamespace")); + .setEnvironment(new MockEnvironment().withProperty("session.redis.namespace", "customRedisNamespace")); registerAndRefresh(RedisConfig.class, PropertySourceConfiguration.class, CustomRedisHttpSessionConfiguration2.class); RedisIndexedHttpSessionConfiguration configuration = this.context - .getBean(RedisIndexedHttpSessionConfiguration.class); + .getBean(RedisIndexedHttpSessionConfiguration.class); assertThat(ReflectionTestUtils.getField(configuration, "redisNamespace")).isEqualTo("customRedisNamespace"); } @@ -141,10 +141,10 @@ void qualifiedConnectionFactoryRedisConfig() { assertThat(redisConnectionFactory).isNotNull(); @SuppressWarnings("unchecked") RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils - .getField(repository, "sessionRedisOperations"); + .getField(repository, "sessionRedisOperations"); assertThat(redisOperations).isNotNull(); assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")) - .isEqualTo(redisConnectionFactory); + .isEqualTo(redisConnectionFactory); } @Test @@ -158,10 +158,10 @@ void primaryConnectionFactoryRedisConfig() { assertThat(redisConnectionFactory).isNotNull(); @SuppressWarnings("unchecked") RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils - .getField(repository, "sessionRedisOperations"); + .getField(repository, "sessionRedisOperations"); assertThat(redisOperations).isNotNull(); assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")) - .isEqualTo(redisConnectionFactory); + .isEqualTo(redisConnectionFactory); } @Test @@ -175,10 +175,10 @@ void qualifiedAndPrimaryConnectionFactoryRedisConfig() { assertThat(redisConnectionFactory).isNotNull(); @SuppressWarnings("unchecked") RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils - .getField(repository, "sessionRedisOperations"); + .getField(repository, "sessionRedisOperations"); assertThat(redisOperations).isNotNull(); assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")) - .isEqualTo(redisConnectionFactory); + .isEqualTo(redisConnectionFactory); } @Test @@ -192,17 +192,18 @@ void namedConnectionFactoryRedisConfig() { assertThat(redisConnectionFactory).isNotNull(); @SuppressWarnings("unchecked") RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils - .getField(repository, "sessionRedisOperations"); + .getField(repository, "sessionRedisOperations"); assertThat(redisOperations).isNotNull(); assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")) - .isEqualTo(redisConnectionFactory); + .isEqualTo(redisConnectionFactory); } @Test void multipleConnectionFactoryRedisConfig() { assertThatExceptionOfType(BeanCreationException.class) - .isThrownBy(() -> registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class)) - .havingRootCause().withMessageContaining("expected single matching bean but found 2"); + .isThrownBy(() -> registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class)) + .havingRootCause() + .withMessageContaining("expected single matching bean but found 2"); } @Test @@ -220,7 +221,7 @@ void customIndexResolverConfiguration() { void customRedisMessageListenerContainerConfig() { registerAndRefresh(RedisConfig.class, CustomRedisMessageListenerContainerConfig.class); Map beans = this.context - .getBeansOfType(RedisMessageListenerContainer.class); + .getBeansOfType(RedisMessageListenerContainer.class); assertThat(beans).hasSize(2); assertThat(beans).containsKeys("springSessionRedisMessageListenerContainer", "redisMessageListenerContainer"); } @@ -230,7 +231,7 @@ void sessionRepositoryCustomizer() { registerAndRefresh(RedisConfig.class, SessionRepositoryCustomizerConfiguration.class); RedisIndexedSessionRepository sessionRepository = this.context.getBean(RedisIndexedSessionRepository.class); assertThat(sessionRepository).extracting("defaultMaxInactiveInterval") - .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } @Test @@ -428,7 +429,7 @@ SessionRepositoryCustomizer sessionRepositoryCust @Order(1) SessionRepositoryCustomizer sessionRepositoryCustomizerTwo() { return (sessionRepository) -> sessionRepository - .setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } } diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/server/RedisWebSessionConfigurationTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/server/RedisWebSessionConfigurationTests.java index 78e6b33e0..1ee920b5e 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/server/RedisWebSessionConfigurationTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/server/RedisWebSessionConfigurationTests.java @@ -85,10 +85,11 @@ void springSessionRedisOperationsResolvingConfiguration() { ReactiveRedisSessionRepository repository = this.context.getBean(ReactiveRedisSessionRepository.class); assertThat(repository).isNotNull(); ReactiveRedisOperations springSessionRedisOperations = this.context - .getBean(SpringSessionRedisOperationsResolvingConfig.class).getSpringSessionRedisOperations(); + .getBean(SpringSessionRedisOperationsResolvingConfig.class) + .getSpringSessionRedisOperations(); assertThat(springSessionRedisOperations).isNotNull(); assertThat((ReactiveRedisOperations) ReflectionTestUtils.getField(repository, "sessionRedisOperations")) - .isEqualTo(springSessionRedisOperations); + .isEqualTo(springSessionRedisOperations); } @Test @@ -106,7 +107,7 @@ void customMaxInactiveInterval() { ReactiveRedisSessionRepository repository = this.context.getBean(ReactiveRedisSessionRepository.class); assertThat(repository).extracting("defaultMaxInactiveInterval") - .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } @Test @@ -136,7 +137,7 @@ void qualifiedConnectionFactoryRedisConfig() { "sessionRedisOperations"); assertThat(redisOperations).isNotNull(); assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")) - .isEqualTo(redisConnectionFactory); + .isEqualTo(redisConnectionFactory); } @Test @@ -152,7 +153,7 @@ void primaryConnectionFactoryRedisConfig() { "sessionRedisOperations"); assertThat(redisOperations).isNotNull(); assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")) - .isEqualTo(redisConnectionFactory); + .isEqualTo(redisConnectionFactory); } @Test @@ -168,7 +169,7 @@ void qualifiedAndPrimaryConnectionFactoryRedisConfig() { "sessionRedisOperations"); assertThat(redisOperations).isNotNull(); assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")) - .isEqualTo(redisConnectionFactory); + .isEqualTo(redisConnectionFactory); } @Test @@ -184,15 +185,16 @@ void namedConnectionFactoryRedisConfig() { "sessionRedisOperations"); assertThat(redisOperations).isNotNull(); assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")) - .isEqualTo(redisConnectionFactory); + .isEqualTo(redisConnectionFactory); } @Test void multipleConnectionFactoryRedisConfig() { assertThatExceptionOfType(BeanCreationException.class) - .isThrownBy(() -> registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class)) - .havingRootCause().isInstanceOf(NoUniqueBeanDefinitionException.class) - .withMessageContaining("expected single matching bean but found 2"); + .isThrownBy(() -> registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class)) + .havingRootCause() + .isInstanceOf(NoUniqueBeanDefinitionException.class) + .withMessageContaining("expected single matching bean but found 2"); } @Test @@ -210,13 +212,17 @@ void customRedisSerializerConfig() { assertThat(redisOperations).isNotNull(); RedisSerializationContext serializationContext = redisOperations.getSerializationContext(); assertThat(ReflectionTestUtils.getField(serializationContext.getValueSerializationPair().getReader(), - "serializer")).isEqualTo(redisSerializer); + "serializer")) + .isEqualTo(redisSerializer); assertThat(ReflectionTestUtils.getField(serializationContext.getValueSerializationPair().getWriter(), - "serializer")).isEqualTo(redisSerializer); + "serializer")) + .isEqualTo(redisSerializer); assertThat(ReflectionTestUtils.getField(serializationContext.getHashValueSerializationPair().getReader(), - "serializer")).isEqualTo(redisSerializer); + "serializer")) + .isEqualTo(redisSerializer); assertThat(ReflectionTestUtils.getField(serializationContext.getHashValueSerializationPair().getWriter(), - "serializer")).isEqualTo(redisSerializer); + "serializer")) + .isEqualTo(redisSerializer); } @Test @@ -224,7 +230,7 @@ void sessionRepositoryCustomizer() { registerAndRefresh(RedisConfig.class, SessionRepositoryCustomizerConfiguration.class); ReactiveRedisSessionRepository sessionRepository = this.context.getBean(ReactiveRedisSessionRepository.class); assertThat(sessionRepository).extracting("defaultMaxInactiveInterval") - .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } @Test @@ -385,7 +391,7 @@ ReactiveSessionRepositoryCustomizer sessionRepos @Order(1) ReactiveSessionRepositoryCustomizer sessionRepositoryCustomizerTwo() { return (sessionRepository) -> sessionRepository - .setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } } diff --git a/spring-session-docs/modules/ROOT/examples/java/docs/IndexDocTests.java b/spring-session-docs/modules/ROOT/examples/java/docs/IndexDocTests.java index 2a19061ca..886f59706 100644 --- a/spring-session-docs/modules/ROOT/examples/java/docs/IndexDocTests.java +++ b/spring-session-docs/modules/ROOT/examples/java/docs/IndexDocTests.java @@ -147,7 +147,8 @@ void newRedisIndexedSessionRepository() { void newReactiveRedisSessionRepository() { LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(); RedisSerializationContext serializationContext = RedisSerializationContext - .newSerializationContext(new JdkSerializationRedisSerializer()).build(); + .newSerializationContext(new JdkSerializationRedisSerializer()) + .build(); // tag::new-reactiveredissessionrepository[] // ... create and configure connectionFactory and serializationContext ... diff --git a/spring-session-docs/modules/ROOT/examples/java/docs/http/HazelcastHttpSessionConfig.java b/spring-session-docs/modules/ROOT/examples/java/docs/http/HazelcastHttpSessionConfig.java index fbfb6d84f..dd38f7866 100644 --- a/spring-session-docs/modules/ROOT/examples/java/docs/http/HazelcastHttpSessionConfig.java +++ b/spring-session-docs/modules/ROOT/examples/java/docs/http/HazelcastHttpSessionConfig.java @@ -41,11 +41,12 @@ public class HazelcastHttpSessionConfig { public HazelcastInstance hazelcastInstance() { Config config = new Config(); AttributeConfig attributeConfig = new AttributeConfig() - .setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) - .setExtractorClassName(PrincipalNameExtractor.class.getName()); + .setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) + .setExtractorClassName(PrincipalNameExtractor.class.getName()); config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME) // <2> - .addAttributeConfig(attributeConfig).addIndexConfig( - new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)); + .addAttributeConfig(attributeConfig) + .addIndexConfig( + new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)); SerializerConfig serializerConfig = new SerializerConfig(); serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class); config.getSerializationConfig().addSerializerConfig(serializerConfig); // <3> diff --git a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/AbstractHazelcastIndexedSessionRepositoryITests.java b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/AbstractHazelcastIndexedSessionRepositoryITests.java index 668f1b423..5a64aff27 100644 --- a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/AbstractHazelcastIndexedSessionRepositoryITests.java +++ b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/AbstractHazelcastIndexedSessionRepositoryITests.java @@ -59,7 +59,7 @@ void createAndDestroySession() { String sessionId = sessionToSave.getId(); IMap hazelcastMap = this.hazelcastInstance - .getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME); + .getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME); this.repository.save(sessionToSave); @@ -222,8 +222,8 @@ void createSessionWithSecurityContextAndFindByPrincipal() { this.repository.save(session); assertThat(this.repository - .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username)) - .hasSize(1); + .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username)) + .hasSize(1); this.repository.deleteById(session.getId()); } @@ -233,7 +233,7 @@ void createAndUpdateSessionWhileKeepingOriginalTimeToLiveConfiguredOnRepository( final Duration defaultSessionTimeout = Duration.ofSeconds(1800); final IMap hazelcastMap = this.hazelcastInstance - .getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME); + .getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME); HazelcastSession session = this.repository.createSession(); String sessionId = session.getId(); @@ -256,7 +256,7 @@ void createAndUpdateSessionWhileKeepingTimeToLiveSetOnSession() { final Duration individualSessionTimeout = Duration.ofSeconds(23); final IMap hazelcastMap = this.hazelcastInstance - .getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME); + .getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME); HazelcastSession session = this.repository.createSession(); session.setMaxInactiveInterval(individualSessionTimeout); diff --git a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/ClientServerHazelcastIndexedSessionRepositoryITests.java b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/ClientServerHazelcastIndexedSessionRepositoryITests.java index c37204969..c3250f96a 100644 --- a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/ClientServerHazelcastIndexedSessionRepositoryITests.java +++ b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/ClientServerHazelcastIndexedSessionRepositoryITests.java @@ -78,8 +78,11 @@ static class HazelcastSessionConfig { HazelcastInstance hazelcastInstance() { ClientConfig clientConfig = new ClientConfig(); clientConfig.getNetworkConfig().addAddress(container.getHost() + ":" + container.getFirstMappedPort()); - clientConfig.getUserCodeDeploymentConfig().setEnabled(true).addClass(Session.class) - .addClass(MapSession.class).addClass(SessionUpdateEntryProcessor.class); + clientConfig.getUserCodeDeploymentConfig() + .setEnabled(true) + .addClass(Session.class) + .addClass(MapSession.class) + .addClass(SessionUpdateEntryProcessor.class); return HazelcastClient.newHazelcastClient(clientConfig); } diff --git a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/FlushImmediateHazelcastIndexedSessionRepositoryITests.java b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/FlushImmediateHazelcastIndexedSessionRepositoryITests.java index b316f03c7..89936ad8b 100644 --- a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/FlushImmediateHazelcastIndexedSessionRepositoryITests.java +++ b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/FlushImmediateHazelcastIndexedSessionRepositoryITests.java @@ -68,7 +68,7 @@ void createSessionWithSecurityContextAndFindByPrincipalName() { this.repository.save(session); Map findByPrincipalName = this.repository - .findByPrincipalName(username); + .findByPrincipalName(username); assertThat(findByPrincipalName).hasSize(1); assertThat(findByPrincipalName.keySet()).containsOnly(sessionId); diff --git a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/HazelcastITestUtils.java b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/HazelcastITestUtils.java index b3de50aa8..e77bd2441 100644 --- a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/HazelcastITestUtils.java +++ b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/HazelcastITestUtils.java @@ -47,11 +47,12 @@ static HazelcastInstance embeddedHazelcastServer() { networkConfig.setPort(0); networkConfig.getJoin().getAutoDetectionConfig().setEnabled(false); AttributeConfig attributeConfig = new AttributeConfig() - .setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) - .setExtractorClassName(PrincipalNameExtractor.class.getName()); + .setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) + .setExtractorClassName(PrincipalNameExtractor.class.getName()); config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME) - .addAttributeConfig(attributeConfig).addIndexConfig( - new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)); + .addAttributeConfig(attributeConfig) + .addIndexConfig( + new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)); SerializerConfig serializerConfig = new SerializerConfig(); serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class); config.getSerializationConfig().addSerializerConfig(serializerConfig); diff --git a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/SessionEventHazelcastIndexedSessionRepositoryTests.java b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/SessionEventHazelcastIndexedSessionRepositoryTests.java index b17eadf2d..d27c951aa 100644 --- a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/SessionEventHazelcastIndexedSessionRepositoryTests.java +++ b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/SessionEventHazelcastIndexedSessionRepositoryTests.java @@ -91,14 +91,14 @@ void saveSessionTest() throws InterruptedException { assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue(); assertThat(this.registry.getEvent(sessionToSave.getId())) - .isInstanceOf(SessionCreatedEvent.class); + .isInstanceOf(SessionCreatedEvent.class); Session session = this.repository.findById(sessionToSave.getId()); assertThat(session.getId()).isEqualTo(sessionToSave.getId()); assertThat(session.getAttributeNames()).isEqualTo(sessionToSave.getAttributeNames()); assertThat(session.getAttribute(expectedAttributeName)) - .isEqualTo(sessionToSave.getAttribute(expectedAttributeName)); + .isEqualTo(sessionToSave.getAttribute(expectedAttributeName)); } @Test @@ -109,15 +109,15 @@ void expiredSessionTest() throws InterruptedException { assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue(); assertThat(this.registry.getEvent(sessionToSave.getId())) - .isInstanceOf(SessionCreatedEvent.class); + .isInstanceOf(SessionCreatedEvent.class); this.registry.clear(); assertThat(sessionToSave.getMaxInactiveInterval()) - .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue(); assertThat(this.registry.getEvent(sessionToSave.getId())) - .isInstanceOf(SessionExpiredEvent.class); + .isInstanceOf(SessionExpiredEvent.class); assertThat(this.repository.findById(sessionToSave.getId())).isNull(); } @@ -130,14 +130,14 @@ void deletedSessionTest() throws InterruptedException { assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue(); assertThat(this.registry.getEvent(sessionToSave.getId())) - .isInstanceOf(SessionCreatedEvent.class); + .isInstanceOf(SessionCreatedEvent.class); this.registry.clear(); this.repository.deleteById(sessionToSave.getId()); assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue(); assertThat(this.registry.getEvent(sessionToSave.getId())) - .isInstanceOf(SessionDeletedEvent.class); + .isInstanceOf(SessionDeletedEvent.class); assertThat(this.repository.findById(sessionToSave.getId())).isNull(); } @@ -169,7 +169,7 @@ void changeSessionIdNoEventTest() throws InterruptedException { assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue(); assertThat(this.registry.getEvent(sessionToSave.getId())) - .isInstanceOf(SessionCreatedEvent.class); + .isInstanceOf(SessionCreatedEvent.class); this.registry.clear(); sessionToSave.changeSessionId(); @@ -186,7 +186,7 @@ void updateMaxInactiveIntervalTest() throws InterruptedException { assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue(); assertThat(this.registry.getEvent(sessionToSave.getId())) - .isInstanceOf(SessionCreatedEvent.class); + .isInstanceOf(SessionCreatedEvent.class); this.registry.clear(); S sessionToUpdate = this.repository.findById(sessionToSave.getId()); @@ -196,7 +196,7 @@ void updateMaxInactiveIntervalTest() throws InterruptedException { assertThat(this.registry.receivedEvent(sessionToUpdate.getId())).isTrue(); assertThat(this.registry.getEvent(sessionToUpdate.getId())) - .isInstanceOf(SessionExpiredEvent.class); + .isInstanceOf(SessionExpiredEvent.class); assertThat(this.repository.findById(sessionToUpdate.getId())).isNull(); } diff --git a/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepository.java b/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepository.java index d9be431ba..b41783cb4 100644 --- a/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepository.java +++ b/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepository.java @@ -377,7 +377,7 @@ final class HazelcastSession implements Session { this.originalId = cached.getId(); if (this.isNew || (HazelcastIndexedSessionRepository.this.saveMode == SaveMode.ALWAYS)) { getAttributeNames() - .forEach((attributeName) -> this.delta.put(attributeName, cached.getAttribute(attributeName))); + .forEach((attributeName) -> this.delta.put(attributeName, cached.getAttribute(attributeName))); } } @@ -448,7 +448,7 @@ public void setAttribute(String attributeName, Object attributeValue) { this.delta.put(attributeName, attributeValue); if (SPRING_SECURITY_CONTEXT.equals(attributeName)) { Map indexes = HazelcastIndexedSessionRepository.this.indexResolver - .resolveIndexesFor(this); + .resolveIndexesFor(this); String principal = (attributeValue != null) ? indexes.get(PRINCIPAL_NAME_INDEX_NAME) : null; this.delegate.setAttribute(PRINCIPAL_NAME_INDEX_NAME, principal); this.delta.put(PRINCIPAL_NAME_INDEX_NAME, principal); diff --git a/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfiguration.java b/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfiguration.java index 55c542abb..1cd7f91b6 100644 --- a/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfiguration.java +++ b/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfiguration.java @@ -131,7 +131,7 @@ public void setSessionRepositoryCustomizer( @Override public void setImportMetadata(AnnotationMetadata importMetadata) { Map attributeMap = importMetadata - .getAnnotationAttributes(EnableHazelcastHttpSession.class.getName()); + .getAnnotationAttributes(EnableHazelcastHttpSession.class.getName()); AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap); if (attributes == null) { return; @@ -159,7 +159,7 @@ private HazelcastIndexedSessionRepository createHazelcastIndexedSessionRepositor sessionRepository.setFlushMode(this.flushMode); sessionRepository.setSaveMode(this.saveMode); this.sessionRepositoryCustomizers - .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository)); + .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository)); return sessionRepository; } diff --git a/spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepositoryTests.java b/spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepositoryTests.java index abe728e38..ee672b92b 100644 --- a/spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepositoryTests.java +++ b/spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepositoryTests.java @@ -82,13 +82,13 @@ void setUp() { @Test void constructorNullHazelcastInstance() { assertThatIllegalArgumentException().isThrownBy(() -> new HazelcastIndexedSessionRepository(null)) - .withMessage("HazelcastInstance must not be null"); + .withMessage("HazelcastInstance must not be null"); } @Test void setSaveModeNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSaveMode(null)) - .withMessage("saveMode must not be null"); + .withMessage("saveMode must not be null"); } @Test @@ -364,7 +364,7 @@ void findByIndexNameAndIndexValuePrincipalIndexNameNotFound() { String principal = "username"; Map sessions = this.repository - .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal); + .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal); assertThat(sessions).isEmpty(); verify(this.sessions, times(1)).values(isA(EqualPredicate.class)); @@ -388,7 +388,7 @@ void findByIndexNameAndIndexValuePrincipalIndexNameFound() { given(this.sessions.values(isA(EqualPredicate.class))).willReturn(saved); Map sessions = this.repository - .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal); + .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal); assertThat(sessions).hasSize(2); verify(this.sessions, times(1)).values(isA(EqualPredicate.class)); diff --git a/spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfigurationTests.java b/spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfigurationTests.java index bb201fe79..42fa5d6ea 100644 --- a/spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfigurationTests.java +++ b/spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfigurationTests.java @@ -71,8 +71,10 @@ void closeContext() { @Test void noHazelcastInstanceConfiguration() { assertThatExceptionOfType(BeanCreationException.class) - .isThrownBy(() -> registerAndRefresh(NoHazelcastInstanceConfiguration.class)).havingRootCause() - .isInstanceOf(NoSuchBeanDefinitionException.class).withMessageContaining("HazelcastInstance"); + .isThrownBy(() -> registerAndRefresh(NoHazelcastInstanceConfiguration.class)) + .havingRootCause() + .isInstanceOf(NoSuchBeanDefinitionException.class) + .withMessageContaining("HazelcastInstance"); } @Test @@ -108,7 +110,7 @@ void setCustomMaxInactiveIntervalInSeconds() { HazelcastIndexedSessionRepository repository = this.context.getBean(HazelcastIndexedSessionRepository.class); assertThat(repository).extracting("defaultMaxInactiveInterval") - .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } @Test @@ -117,7 +119,7 @@ void customMaxInactiveIntervalInSeconds() { HazelcastIndexedSessionRepository repository = this.context.getBean(HazelcastIndexedSessionRepository.class); assertThat(repository).extracting("defaultMaxInactiveInterval") - .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } @Test @@ -142,14 +144,14 @@ void setCustomFlushImmediately() { void customSaveModeAnnotation() { registerAndRefresh(BaseConfiguration.class, CustomSaveModeExpressionAnnotationConfiguration.class); assertThat(this.context.getBean(HazelcastIndexedSessionRepository.class)) - .hasFieldOrPropertyWithValue("saveMode", SaveMode.ALWAYS); + .hasFieldOrPropertyWithValue("saveMode", SaveMode.ALWAYS); } @Test void customSaveModeSetter() { registerAndRefresh(BaseConfiguration.class, CustomSaveModeExpressionSetterConfiguration.class); assertThat(this.context.getBean(HazelcastIndexedSessionRepository.class)) - .hasFieldOrPropertyWithValue("saveMode", SaveMode.ALWAYS); + .hasFieldOrPropertyWithValue("saveMode", SaveMode.ALWAYS); } @Test @@ -162,7 +164,7 @@ void qualifiedHazelcastInstanceConfiguration() { assertThat(repository).isNotNull(); assertThat(hazelcastInstance).isNotNull(); assertThat(ReflectionTestUtils.getField(repository, "sessions")) - .isEqualTo(QualifiedHazelcastInstanceConfiguration.qualifiedHazelcastInstanceSessions); + .isEqualTo(QualifiedHazelcastInstanceConfiguration.qualifiedHazelcastInstanceSessions); } @Test @@ -174,7 +176,7 @@ void primaryHazelcastInstanceConfiguration() { assertThat(repository).isNotNull(); assertThat(hazelcastInstance).isNotNull(); assertThat(ReflectionTestUtils.getField(repository, "sessions")) - .isEqualTo(PrimaryHazelcastInstanceConfiguration.primaryHazelcastInstanceSessions); + .isEqualTo(PrimaryHazelcastInstanceConfiguration.primaryHazelcastInstanceSessions); } @Test @@ -187,7 +189,7 @@ void qualifiedAndPrimaryHazelcastInstanceConfiguration() { assertThat(repository).isNotNull(); assertThat(hazelcastInstance).isNotNull(); assertThat(ReflectionTestUtils.getField(repository, "sessions")) - .isEqualTo(QualifiedAndPrimaryHazelcastInstanceConfiguration.qualifiedHazelcastInstanceSessions); + .isEqualTo(QualifiedAndPrimaryHazelcastInstanceConfiguration.qualifiedHazelcastInstanceSessions); } @Test @@ -199,15 +201,16 @@ void namedHazelcastInstanceConfiguration() { assertThat(repository).isNotNull(); assertThat(hazelcastInstance).isNotNull(); assertThat(ReflectionTestUtils.getField(repository, "sessions")) - .isEqualTo(NamedHazelcastInstanceConfiguration.hazelcastInstanceSessions); + .isEqualTo(NamedHazelcastInstanceConfiguration.hazelcastInstanceSessions); } @Test void multipleHazelcastInstanceConfiguration() { assertThatExceptionOfType(BeanCreationException.class) - .isThrownBy(() -> registerAndRefresh(MultipleHazelcastInstanceConfiguration.class)).havingRootCause() - .isInstanceOf(NoUniqueBeanDefinitionException.class) - .withMessageContaining("expected single matching bean but found 2"); + .isThrownBy(() -> registerAndRefresh(MultipleHazelcastInstanceConfiguration.class)) + .havingRootCause() + .isInstanceOf(NoUniqueBeanDefinitionException.class) + .withMessageContaining("expected single matching bean but found 2"); } @Test @@ -225,16 +228,16 @@ void customIndexResolverConfiguration() { void sessionRepositoryCustomizer() { registerAndRefresh(SessionRepositoryCustomizerConfiguration.class); HazelcastIndexedSessionRepository sessionRepository = this.context - .getBean(HazelcastIndexedSessionRepository.class); + .getBean(HazelcastIndexedSessionRepository.class); assertThat(sessionRepository).extracting("defaultMaxInactiveInterval") - .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } @Test void importConfigAndCustomize() { registerAndRefresh(ImportConfigAndCustomizeConfiguration.class); HazelcastIndexedSessionRepository sessionRepository = this.context - .getBean(HazelcastIndexedSessionRepository.class); + .getBean(HazelcastIndexedSessionRepository.class); assertThat(sessionRepository).extracting("defaultMaxInactiveInterval").isEqualTo(Duration.ZERO); } @@ -449,7 +452,7 @@ SessionRepositoryCustomizer sessionRepository @Order(1) SessionRepositoryCustomizer sessionRepositoryCustomizerTwo() { return (sessionRepository) -> sessionRepository - .setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } } diff --git a/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/AbstractJdbcIndexedSessionRepositoryITests.java b/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/AbstractJdbcIndexedSessionRepositoryITests.java index 293e6f6ce..ebb36f62e 100644 --- a/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/AbstractJdbcIndexedSessionRepositoryITests.java +++ b/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/AbstractJdbcIndexedSessionRepositoryITests.java @@ -134,7 +134,7 @@ void saves() { assertThat(session.getDelta()).isEmpty(); assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames()); assertThat(session.getAttribute(expectedAttributeName)) - .isEqualTo(toSave.getAttribute(expectedAttributeName)); + .isEqualTo(toSave.getAttribute(expectedAttributeName)); this.repository.deleteById(toSave.getId()); @@ -190,7 +190,7 @@ void updateLastAccessedTime() { assertThat(session.getDelta()).isEmpty(); assertThat(session.isExpired()).isFalse(); assertThat(session.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS)) - .isEqualTo(lastAccessedTime.truncatedTo(ChronoUnit.MILLIS)); + .isEqualTo(lastAccessedTime.truncatedTo(ChronoUnit.MILLIS)); } @Test @@ -816,7 +816,7 @@ void saveNewSessionAttributeConcurrently() { // with DB specific upsert configured we're fine assertThatCode(() -> this.repository.save(session)).doesNotThrowAnyException(); assertThat((String) this.repository.findById(session.getId()).getAttribute(attributeName)) - .isEqualTo(attributeValue); + .isEqualTo(attributeValue); } } diff --git a/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/DerbyJdbcIndexedSessionRepositoryITests.java b/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/DerbyJdbcIndexedSessionRepositoryITests.java index 65bc4a380..f8965e04d 100644 --- a/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/DerbyJdbcIndexedSessionRepositoryITests.java +++ b/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/DerbyJdbcIndexedSessionRepositoryITests.java @@ -43,7 +43,8 @@ static class Config extends BaseConfig { @Bean EmbeddedDatabase dataSource() { return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY) - .addScript("org/springframework/session/jdbc/schema-derby.sql").build(); + .addScript("org/springframework/session/jdbc/schema-derby.sql") + .build(); } } diff --git a/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/H2JdbcIndexedSessionRepositoryITests.java b/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/H2JdbcIndexedSessionRepositoryITests.java index 981865cc8..d3174a18a 100644 --- a/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/H2JdbcIndexedSessionRepositoryITests.java +++ b/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/H2JdbcIndexedSessionRepositoryITests.java @@ -43,7 +43,8 @@ static class Config extends BaseConfig { @Bean EmbeddedDatabase dataSource() { return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2) - .addScript("org/springframework/session/jdbc/schema-h2.sql").build(); + .addScript("org/springframework/session/jdbc/schema-h2.sql") + .build(); } } diff --git a/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/HsqldbJdbcIndexedSessionRepositoryITests.java b/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/HsqldbJdbcIndexedSessionRepositoryITests.java index fbaed7681..c7da3cbd7 100644 --- a/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/HsqldbJdbcIndexedSessionRepositoryITests.java +++ b/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/HsqldbJdbcIndexedSessionRepositoryITests.java @@ -43,7 +43,8 @@ static class Config extends BaseConfig { @Bean EmbeddedDatabase dataSource() { return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL) - .addScript("org/springframework/session/jdbc/schema-hsqldb.sql").build(); + .addScript("org/springframework/session/jdbc/schema-hsqldb.sql") + .build(); } } diff --git a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java index 1d12c1607..1cbca6ccc 100644 --- a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java +++ b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java @@ -499,7 +499,7 @@ public JdbcSession findById(final String id) { @Override public void deleteById(final String id) { this.transactionOperations.executeWithoutResult((status) -> JdbcIndexedSessionRepository.this.jdbcOperations - .update(JdbcIndexedSessionRepository.this.deleteSessionQuery, id)); + .update(JdbcIndexedSessionRepository.this.deleteSessionQuery, id)); } @Override @@ -509,9 +509,9 @@ public Map findByIndexNameAndIndexValue(String indexName, f } List sessions = this.transactionOperations - .execute((status) -> JdbcIndexedSessionRepository.this.jdbcOperations.query( - JdbcIndexedSessionRepository.this.listSessionsByPrincipalNameQuery, - (ps) -> ps.setString(1, indexValue), JdbcIndexedSessionRepository.this.extractor)); + .execute((status) -> JdbcIndexedSessionRepository.this.jdbcOperations.query( + JdbcIndexedSessionRepository.this.listSessionsByPrincipalNameQuery, + (ps) -> ps.setString(1, indexValue), JdbcIndexedSessionRepository.this.extractor)); Map sessionMap = new HashMap<>(sessions.size()); @@ -641,8 +641,8 @@ public int getBatchSize() { public void cleanUpExpiredSessions() { Integer deletedCount = this.transactionOperations - .execute((status) -> JdbcIndexedSessionRepository.this.jdbcOperations.update( - JdbcIndexedSessionRepository.this.deleteSessionsByExpiryTimeQuery, System.currentTimeMillis())); + .execute((status) -> JdbcIndexedSessionRepository.this.jdbcOperations + .update(JdbcIndexedSessionRepository.this.deleteSessionsByExpiryTimeQuery, System.currentTimeMillis())); if (logger.isDebugEnabled()) { logger.debug("Cleaned up " + deletedCount + " expired sessions"); @@ -873,17 +873,17 @@ private void save() { if (this.isNew) { JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> { Map indexes = JdbcIndexedSessionRepository.this.indexResolver - .resolveIndexesFor(JdbcSession.this); + .resolveIndexesFor(JdbcSession.this); JdbcIndexedSessionRepository.this.jdbcOperations - .update(JdbcIndexedSessionRepository.this.createSessionQuery, (ps) -> { - ps.setString(1, JdbcSession.this.primaryKey); - ps.setString(2, getId()); - ps.setLong(3, getCreationTime().toEpochMilli()); - ps.setLong(4, getLastAccessedTime().toEpochMilli()); - ps.setInt(5, (int) getMaxInactiveInterval().getSeconds()); - ps.setLong(6, getExpiryTime().toEpochMilli()); - ps.setString(7, indexes.get(PRINCIPAL_NAME_INDEX_NAME)); - }); + .update(JdbcIndexedSessionRepository.this.createSessionQuery, (ps) -> { + ps.setString(1, JdbcSession.this.primaryKey); + ps.setString(2, getId()); + ps.setLong(3, getCreationTime().toEpochMilli()); + ps.setLong(4, getLastAccessedTime().toEpochMilli()); + ps.setInt(5, (int) getMaxInactiveInterval().getSeconds()); + ps.setLong(6, getExpiryTime().toEpochMilli()); + ps.setString(7, indexes.get(PRINCIPAL_NAME_INDEX_NAME)); + }); Set attributeNames = getAttributeNames(); if (!attributeNames.isEmpty()) { insertSessionAttributes(JdbcSession.this, new ArrayList<>(attributeNames)); @@ -894,32 +894,38 @@ private void save() { JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> { if (JdbcSession.this.changed) { Map indexes = JdbcIndexedSessionRepository.this.indexResolver - .resolveIndexesFor(JdbcSession.this); + .resolveIndexesFor(JdbcSession.this); JdbcIndexedSessionRepository.this.jdbcOperations - .update(JdbcIndexedSessionRepository.this.updateSessionQuery, (ps) -> { - ps.setString(1, getId()); - ps.setLong(2, getLastAccessedTime().toEpochMilli()); - ps.setInt(3, (int) getMaxInactiveInterval().getSeconds()); - ps.setLong(4, getExpiryTime().toEpochMilli()); - ps.setString(5, indexes.get(PRINCIPAL_NAME_INDEX_NAME)); - ps.setString(6, JdbcSession.this.primaryKey); - }); + .update(JdbcIndexedSessionRepository.this.updateSessionQuery, (ps) -> { + ps.setString(1, getId()); + ps.setLong(2, getLastAccessedTime().toEpochMilli()); + ps.setInt(3, (int) getMaxInactiveInterval().getSeconds()); + ps.setLong(4, getExpiryTime().toEpochMilli()); + ps.setString(5, indexes.get(PRINCIPAL_NAME_INDEX_NAME)); + ps.setString(6, JdbcSession.this.primaryKey); + }); } - List addedAttributeNames = JdbcSession.this.delta.entrySet().stream() - .filter((entry) -> entry.getValue() == DeltaValue.ADDED).map(Map.Entry::getKey) - .collect(Collectors.toList()); + List addedAttributeNames = JdbcSession.this.delta.entrySet() + .stream() + .filter((entry) -> entry.getValue() == DeltaValue.ADDED) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); if (!addedAttributeNames.isEmpty()) { insertSessionAttributes(JdbcSession.this, addedAttributeNames); } - List updatedAttributeNames = JdbcSession.this.delta.entrySet().stream() - .filter((entry) -> entry.getValue() == DeltaValue.UPDATED).map(Map.Entry::getKey) - .collect(Collectors.toList()); + List updatedAttributeNames = JdbcSession.this.delta.entrySet() + .stream() + .filter((entry) -> entry.getValue() == DeltaValue.UPDATED) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); if (!updatedAttributeNames.isEmpty()) { updateSessionAttributes(JdbcSession.this, updatedAttributeNames); } - List removedAttributeNames = JdbcSession.this.delta.entrySet().stream() - .filter((entry) -> entry.getValue() == DeltaValue.REMOVED).map(Map.Entry::getKey) - .collect(Collectors.toList()); + List removedAttributeNames = JdbcSession.this.delta.entrySet() + .stream() + .filter((entry) -> entry.getValue() == DeltaValue.REMOVED) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); if (!removedAttributeNames.isEmpty()) { deleteSessionAttributes(JdbcSession.this, removedAttributeNames); } diff --git a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/aot/hint/SessionJdbcRuntimeHints.java b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/aot/hint/SessionJdbcRuntimeHints.java index e1a4071d2..57fb8e830 100644 --- a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/aot/hint/SessionJdbcRuntimeHints.java +++ b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/aot/hint/SessionJdbcRuntimeHints.java @@ -30,28 +30,30 @@ class SessionJdbcRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - hints.reflection().registerType(TypeReference.of("javax.sql.DataSource"), - (hint) -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS)); - hints.resources().registerPattern("org/springframework/session/jdbc/schema-db2.sql") - .registerPattern("org/springframework/session/jdbc/schema-derby.sql") - .registerPattern("org/springframework/session/jdbc/schema-drop-db2.sql") - .registerPattern("org/springframework/session/jdbc/schema-drop-derby.sql") - .registerPattern("org/springframework/session/jdbc/schema-drop-h2.sql") - .registerPattern("org/springframework/session/jdbc/schema-drop-hsqldb.sql") - .registerPattern("org/springframework/session/jdbc/schema-drop-mysql.sql") - .registerPattern("org/springframework/session/jdbc/schema-drop-oracle.sql") - .registerPattern("org/springframework/session/jdbc/schema-drop-postgresql.sql") - .registerPattern("org/springframework/session/jdbc/schema-drop-sqlite.sql") - .registerPattern("org/springframework/session/jdbc/schema-drop-sqlserver.sql") - .registerPattern("org/springframework/session/jdbc/schema-drop-sybase.sql") - .registerPattern("org/springframework/session/jdbc/schema-h2.sql") - .registerPattern("org/springframework/session/jdbc/schema-hsqldb.sql") - .registerPattern("org/springframework/session/jdbc/schema-mysql.sql") - .registerPattern("org/springframework/session/jdbc/schema-oracle.sql") - .registerPattern("org/springframework/session/jdbc/schema-postgresql.sql") - .registerPattern("org/springframework/session/jdbc/schema-sqlite.sql") - .registerPattern("org/springframework/session/jdbc/schema-sqlserver.sql") - .registerPattern("org/springframework/session/jdbc/schema-sybase.sql"); + hints.reflection() + .registerType(TypeReference.of("javax.sql.DataSource"), + (hint) -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS)); + hints.resources() + .registerPattern("org/springframework/session/jdbc/schema-db2.sql") + .registerPattern("org/springframework/session/jdbc/schema-derby.sql") + .registerPattern("org/springframework/session/jdbc/schema-drop-db2.sql") + .registerPattern("org/springframework/session/jdbc/schema-drop-derby.sql") + .registerPattern("org/springframework/session/jdbc/schema-drop-h2.sql") + .registerPattern("org/springframework/session/jdbc/schema-drop-hsqldb.sql") + .registerPattern("org/springframework/session/jdbc/schema-drop-mysql.sql") + .registerPattern("org/springframework/session/jdbc/schema-drop-oracle.sql") + .registerPattern("org/springframework/session/jdbc/schema-drop-postgresql.sql") + .registerPattern("org/springframework/session/jdbc/schema-drop-sqlite.sql") + .registerPattern("org/springframework/session/jdbc/schema-drop-sqlserver.sql") + .registerPattern("org/springframework/session/jdbc/schema-drop-sybase.sql") + .registerPattern("org/springframework/session/jdbc/schema-h2.sql") + .registerPattern("org/springframework/session/jdbc/schema-hsqldb.sql") + .registerPattern("org/springframework/session/jdbc/schema-mysql.sql") + .registerPattern("org/springframework/session/jdbc/schema-oracle.sql") + .registerPattern("org/springframework/session/jdbc/schema-postgresql.sql") + .registerPattern("org/springframework/session/jdbc/schema-sqlite.sql") + .registerPattern("org/springframework/session/jdbc/schema-sqlserver.sql") + .registerPattern("org/springframework/session/jdbc/schema-sybase.sql"); } } diff --git a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/config/annotation/web/http/JdbcHttpSessionConfiguration.java b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/config/annotation/web/http/JdbcHttpSessionConfiguration.java index 5c0cb2648..8a7951cae 100644 --- a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/config/annotation/web/http/JdbcHttpSessionConfiguration.java +++ b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/config/annotation/web/http/JdbcHttpSessionConfiguration.java @@ -145,7 +145,7 @@ else if (this.conversionService != null) { sessionRepository.setConversionService(createConversionServiceWithBeanClassLoader(this.classLoader)); } this.sessionRepositoryCustomizers - .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository)); + .forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository)); return sessionRepository; } @@ -248,7 +248,7 @@ public void setEmbeddedValueResolver(StringValueResolver resolver) { @Override public void setImportMetadata(AnnotationMetadata importMetadata) { Map attributeMap = importMetadata - .getAnnotationAttributes(EnableJdbcHttpSession.class.getName()); + .getAnnotationAttributes(EnableJdbcHttpSession.class.getName()); AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap); if (attributes == null) { return; diff --git a/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcIndexedSessionRepositoryTests.java b/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcIndexedSessionRepositoryTests.java index 1d3283eaa..ba98824ff 100644 --- a/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcIndexedSessionRepositoryTests.java +++ b/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcIndexedSessionRepositoryTests.java @@ -89,171 +89,171 @@ void setUp() { @Test void constructorNullJdbcOperations() { assertThatIllegalArgumentException() - .isThrownBy(() -> new JdbcIndexedSessionRepository(null, TransactionOperations.withoutTransaction())) - .withMessage("jdbcOperations must not be null"); + .isThrownBy(() -> new JdbcIndexedSessionRepository(null, TransactionOperations.withoutTransaction())) + .withMessage("jdbcOperations must not be null"); } @Test void constructorNullTransactionOperations() { assertThatIllegalArgumentException() - .isThrownBy(() -> new JdbcIndexedSessionRepository(this.jdbcOperations, null)) - .withMessage("transactionOperations must not be null"); + .isThrownBy(() -> new JdbcIndexedSessionRepository(this.jdbcOperations, null)) + .withMessage("transactionOperations must not be null"); } @Test void setTableNameNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setTableName(null)) - .withMessage("Table name must not be empty"); + .withMessage("Table name must not be empty"); } @Test void setTableNameEmpty() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setTableName(" ")) - .withMessage("Table name must not be empty"); + .withMessage("Table name must not be empty"); } @Test void setCreateSessionQueryNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCreateSessionQuery(null)) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setCreateSessionQueryEmpty() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCreateSessionQuery(" ")) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setCreateSessionAttributeQueryNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCreateSessionAttributeQuery(null)) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setCreateSessionAttributeQueryEmpty() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCreateSessionAttributeQuery(" ")) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setGetSessionQueryNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setGetSessionQuery(null)) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setGetSessionQueryEmpty() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setGetSessionQuery(" ")) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setUpdateSessionQueryNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setUpdateSessionQuery(null)) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setUpdateSessionQueryEmpty() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setUpdateSessionQuery(" ")) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setUpdateSessionAttributeQueryNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setUpdateSessionAttributeQuery(null)) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setUpdateSessionAttributeQueryEmpty() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setUpdateSessionAttributeQuery(" ")) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setDeleteSessionAttributeQueryNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeQuery(null)) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setDeleteSessionAttributeQueryEmpty() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeQuery(" ")) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setDeleteSessionQueryNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionQuery(null)) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setDeleteSessionQueryEmpty() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionQuery(" ")) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setListSessionsByPrincipalNameQueryNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setListSessionsByPrincipalNameQuery(null)) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setListSessionsByPrincipalNameQueryEmpty() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setListSessionsByPrincipalNameQuery(" ")) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setDeleteSessionsByLastAccessTimeQueryNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionsByExpiryTimeQuery(null)) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setDeleteSessionsByLastAccessTimeQueryEmpty() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionsByExpiryTimeQuery(" ")) - .withMessage("Query must not be empty"); + .withMessage("Query must not be empty"); } @Test void setLobHandlerNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setLobHandler(null)) - .withMessage("LobHandler must not be null"); + .withMessage("LobHandler must not be null"); } @Test void setConversionServiceNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setConversionService(null)) - .withMessage("conversionService must not be null"); + .withMessage("conversionService must not be null"); } @Test void setFlushModeNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setFlushMode(null)) - .withMessage("flushMode must not be null"); + .withMessage("flushMode must not be null"); } @Test void setSaveModeNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSaveMode(null)) - .withMessage("saveMode must not be null"); + .withMessage("saveMode must not be null"); } @Test void setCleanupCronNull() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCleanupCron(null)) - .withMessage("cleanupCron must not be null"); + .withMessage("cleanupCron must not be null"); } @Test void setCleanupCronInvalid() { assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCleanupCron("test")) - .withMessage("cleanupCron must be valid"); + .withMessage("cleanupCron must be valid"); } @Test @@ -523,7 +523,8 @@ void saveUnchanged() { void getSessionNotFound() { String sessionId = "testSessionId"; given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class), - isA(ResultSetExtractor.class))).willReturn(Collections.emptyList()); + isA(ResultSetExtractor.class))) + .willReturn(Collections.emptyList()); JdbcSession session = this.repository.findById(sessionId); @@ -538,7 +539,8 @@ void getSessionExpired() { Session expired = this.repository.createSession(); expired.setLastAccessedTime(Instant.now().minusSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS + 1)); given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class), - isA(ResultSetExtractor.class))).willReturn(Collections.singletonList(expired)); + isA(ResultSetExtractor.class))) + .willReturn(Collections.singletonList(expired)); JdbcSession session = this.repository.findById(expired.getId()); @@ -554,7 +556,8 @@ void getSessionFound() { Session saved = this.repository.new JdbcSession(new MapSession(), "primaryKey", false); saved.setAttribute("savedName", "savedValue"); given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class), - isA(ResultSetExtractor.class))).willReturn(Collections.singletonList(saved)); + isA(ResultSetExtractor.class))) + .willReturn(Collections.singletonList(saved)); JdbcSession session = this.repository.findById(saved.getId()); @@ -589,10 +592,11 @@ void findByIndexNameAndIndexValueUnknownIndexName() { void findByIndexNameAndIndexValuePrincipalIndexNameNotFound() { String principal = "username"; given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class), - isA(ResultSetExtractor.class))).willReturn(Collections.emptyList()); + isA(ResultSetExtractor.class))) + .willReturn(Collections.emptyList()); Map sessions = this.repository - .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal); + .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal); assertThat(sessions).isEmpty(); verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class), @@ -613,10 +617,11 @@ void findByIndexNameAndIndexValuePrincipalIndexNameFound() { saved2.setAttribute(SPRING_SECURITY_CONTEXT, authentication); saved.add(saved2); given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class), - isA(ResultSetExtractor.class))).willReturn(saved); + isA(ResultSetExtractor.class))) + .willReturn(saved); Map sessions = this.repository - .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal); + .findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal); assertThat(sessions).hasSize(2); verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class), @@ -671,7 +676,7 @@ void saveWithSaveModeOnGetAttribute() { session.setAttribute("attribute3", "value4"); this.repository.save(session); ArgumentCaptor captor = ArgumentCaptor - .forClass(BatchPreparedStatementSetter.class); + .forClass(BatchPreparedStatementSetter.class); verify(this.jdbcOperations).batchUpdate(matches("^UPDATE SPRING_SESSION_ATTRIBUTES\\s*SET.*"), captor.capture()); assertThat(captor.getValue().getBatchSize()).isEqualTo(2); @@ -704,7 +709,7 @@ void saveWithSaveModeAlways() { session.setAttribute("attribute3", "value4"); this.repository.save(session); ArgumentCaptor captor = ArgumentCaptor - .forClass(BatchPreparedStatementSetter.class); + .forClass(BatchPreparedStatementSetter.class); verify(this.jdbcOperations).batchUpdate(matches("^UPDATE SPRING_SESSION_ATTRIBUTES\\s*SET.*"), captor.capture()); assertThat(captor.getValue().getBatchSize()).isEqualTo(3); diff --git a/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/aot/hint/SessionJdbcRuntimeHintsTests.java b/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/aot/hint/SessionJdbcRuntimeHintsTests.java index c6f33e26f..67fd5d636 100644 --- a/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/aot/hint/SessionJdbcRuntimeHintsTests.java +++ b/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/aot/hint/SessionJdbcRuntimeHintsTests.java @@ -48,8 +48,9 @@ class SessionJdbcRuntimeHintsTests { @Test void aotFactoriesContainsRegistrar() { boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories") - .load(RuntimeHintsRegistrar.class).stream() - .anyMatch((registrar) -> registrar instanceof SessionJdbcRuntimeHints); + .load(RuntimeHintsRegistrar.class) + .stream() + .anyMatch((registrar) -> registrar instanceof SessionJdbcRuntimeHints); assertThat(match).isTrue(); } @@ -58,21 +59,21 @@ void aotFactoriesContainsRegistrar() { void jdbcSchemasHasHints(String schemaFileName) { this.sessionJdbcRuntimeHints.registerHints(this.hints, getClass().getClassLoader()); assertThat(RuntimeHintsPredicates.resource().forResource("org/springframework/session/jdbc/" + schemaFileName)) - .accepts(this.hints); + .accepts(this.hints); } private static Stream getSchemaFileNames() throws IOException { return Arrays - .stream(new PathMatchingResourcePatternResolver() - .getResources("classpath*:org/springframework/session/jdbc/schema-*.sql")) - .map(Resource::getFilename); + .stream(new PathMatchingResourcePatternResolver() + .getResources("classpath*:org/springframework/session/jdbc/schema-*.sql")) + .map(Resource::getFilename); } @Test void dataSourceHasHints() { this.sessionJdbcRuntimeHints.registerHints(this.hints, getClass().getClassLoader()); assertThat(RuntimeHintsPredicates.reflection().onType(TypeReference.of("javax.sql.DataSource"))) - .accepts(this.hints); + .accepts(this.hints); } } diff --git a/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/config/annotation/web/http/JdbcHttpSessionConfigurationTests.java b/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/config/annotation/web/http/JdbcHttpSessionConfigurationTests.java index dcf5c2c7e..b12787dbe 100644 --- a/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/config/annotation/web/http/JdbcHttpSessionConfigurationTests.java +++ b/spring-session-jdbc/src/test/java/org/springframework/session/jdbc/config/annotation/web/http/JdbcHttpSessionConfigurationTests.java @@ -81,9 +81,10 @@ void closeContext() { @Test void noDataSourceConfiguration() { assertThatExceptionOfType(BeanCreationException.class) - .isThrownBy(() -> registerAndRefresh(NoDataSourceConfiguration.class)) - .withRootCauseInstanceOf(NoSuchBeanDefinitionException.class).havingRootCause() - .withMessageContaining("expected at least 1 bean which qualifies as autowire candidate"); + .isThrownBy(() -> registerAndRefresh(NoDataSourceConfiguration.class)) + .withRootCauseInstanceOf(NoSuchBeanDefinitionException.class) + .havingRootCause() + .withMessageContaining("expected at least 1 bean which qualifies as autowire candidate"); } @Test @@ -93,7 +94,7 @@ void defaultConfiguration() { JdbcIndexedSessionRepository sessionRepository = this.context.getBean(JdbcIndexedSessionRepository.class); assertThat(sessionRepository).isNotNull(); assertThat(sessionRepository).extracting("transactionOperations") - .hasFieldOrPropertyWithValue("propagationBehavior", TransactionDefinition.PROPAGATION_REQUIRES_NEW); + .hasFieldOrPropertyWithValue("propagationBehavior", TransactionDefinition.PROPAGATION_REQUIRES_NEW); } @Test @@ -121,7 +122,7 @@ void customMaxInactiveIntervalInSecondsAnnotation() { JdbcIndexedSessionRepository repository = this.context.getBean(JdbcIndexedSessionRepository.class); assertThat(repository).extracting("defaultMaxInactiveInterval") - .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } @Test @@ -130,7 +131,7 @@ void customMaxInactiveIntervalInSecondsSetter() { JdbcIndexedSessionRepository repository = this.context.getBean(JdbcIndexedSessionRepository.class); assertThat(repository).extracting("defaultMaxInactiveInterval") - .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } @Test @@ -232,10 +233,10 @@ void namedDataSourceConfiguration() { @Test void multipleDataSourceConfiguration() { assertThatExceptionOfType(BeanCreationException.class) - .isThrownBy( - () -> registerAndRefresh(DataSourceConfiguration.class, MultipleDataSourceConfiguration.class)) - .withRootCauseInstanceOf(NoUniqueBeanDefinitionException.class).havingRootCause() - .withMessageContaining("expected single matching bean but found 2"); + .isThrownBy(() -> registerAndRefresh(DataSourceConfiguration.class, MultipleDataSourceConfiguration.class)) + .withRootCauseInstanceOf(NoUniqueBeanDefinitionException.class) + .havingRootCause() + .withMessageContaining("expected single matching bean but found 2"); } @Test @@ -287,7 +288,7 @@ void customConversionServiceConfiguration() { @Test void resolveTableNameByPropertyPlaceholder() { this.context - .setEnvironment(new MockEnvironment().withProperty("session.jdbc.tableName", "custom_session_table")); + .setEnvironment(new MockEnvironment().withProperty("session.jdbc.tableName", "custom_session_table")); registerAndRefresh(DataSourceConfiguration.class, CustomJdbcHttpSessionConfiguration.class); JdbcHttpSessionConfiguration configuration = this.context.getBean(JdbcHttpSessionConfiguration.class); assertThat(ReflectionTestUtils.getField(configuration, "tableName")).isEqualTo("custom_session_table"); @@ -298,7 +299,7 @@ void sessionRepositoryCustomizer() { registerAndRefresh(DataSourceConfiguration.class, SessionRepositoryCustomizerConfiguration.class); JdbcIndexedSessionRepository sessionRepository = this.context.getBean(JdbcIndexedSessionRepository.class); assertThat(sessionRepository).extracting("defaultMaxInactiveInterval") - .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } @Test @@ -559,7 +560,7 @@ SessionRepositoryCustomizer sessionRepositoryCusto @Order(1) SessionRepositoryCustomizer sessionRepositoryCustomizerTwo() { return (sessionRepository) -> sessionRepository - .setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); + .setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS)); } } diff --git a/spring-session-samples/spring-session-sample-boot-hazelcast/src/main/java/sample/config/SessionConfig.java b/spring-session-samples/spring-session-sample-boot-hazelcast/src/main/java/sample/config/SessionConfig.java index 0f3d40199..c18672616 100644 --- a/spring-session-samples/spring-session-sample-boot-hazelcast/src/main/java/sample/config/SessionConfig.java +++ b/spring-session-samples/spring-session-sample-boot-hazelcast/src/main/java/sample/config/SessionConfig.java @@ -41,11 +41,12 @@ public Config hazelcastConfig() { networkConfig.setPort(0); networkConfig.getJoin().getAutoDetectionConfig().setEnabled(false); AttributeConfig attributeConfig = new AttributeConfig() - .setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) - .setExtractorClassName(PrincipalNameExtractor.class.getName()); + .setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) + .setExtractorClassName(PrincipalNameExtractor.class.getName()); config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME) - .addAttributeConfig(attributeConfig).addIndexConfig( - new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)); + .addAttributeConfig(attributeConfig) + .addIndexConfig( + new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)); SerializerConfig serializerConfig = new SerializerConfig(); serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class); config.getSerializationConfig().addSerializerConfig(serializerConfig); diff --git a/spring-session-samples/spring-session-sample-boot-mongodb-reactive/src/test/java/org/springframework/session/mongodb/examples/pages/HomePage.java b/spring-session-samples/spring-session-sample-boot-mongodb-reactive/src/test/java/org/springframework/session/mongodb/examples/pages/HomePage.java index 7db5526a2..fc2e349e3 100644 --- a/spring-session-samples/spring-session-sample-boot-mongodb-reactive/src/test/java/org/springframework/session/mongodb/examples/pages/HomePage.java +++ b/spring-session-samples/spring-session-sample-boot-mongodb-reactive/src/test/java/org/springframework/session/mongodb/examples/pages/HomePage.java @@ -70,8 +70,8 @@ public void assertAt() { public List attributes() { List rows = this.trs.stream() // - .map(Attribute::new) // - .collect(Collectors.toList()); + .map(Attribute::new) // + .collect(Collectors.toList()); this.attributes.addAll(rows); diff --git a/spring-session-samples/spring-session-sample-boot-redis-json/src/integration-test/java/sample/RedisSerializerTest.java b/spring-session-samples/spring-session-sample-boot-redis-json/src/integration-test/java/sample/RedisSerializerTest.java index b43d007eb..dde4746c4 100644 --- a/spring-session-samples/spring-session-sample-boot-redis-json/src/integration-test/java/sample/RedisSerializerTest.java +++ b/spring-session-samples/spring-session-sample-boot-redis-json/src/integration-test/java/sample/RedisSerializerTest.java @@ -49,7 +49,7 @@ void testRedisTemplate() { assertThat(this.sessionRedisTemplate).isNotNull(); assertThat(this.sessionRedisTemplate.getDefaultSerializer()).isNotNull(); assertThat(this.sessionRedisTemplate.getDefaultSerializer()) - .isInstanceOf(GenericJackson2JsonRedisSerializer.class); + .isInstanceOf(GenericJackson2JsonRedisSerializer.class); } @TestConfiguration diff --git a/spring-session-samples/spring-session-sample-boot-websocket/src/integration-test/java/sample/ApplicationTests.java b/spring-session-samples/spring-session-sample-boot-websocket/src/integration-test/java/sample/ApplicationTests.java index c251be2e8..1a837aaf1 100644 --- a/spring-session-samples/spring-session-sample-boot-websocket/src/integration-test/java/sample/ApplicationTests.java +++ b/spring-session-samples/spring-session-sample-boot-websocket/src/integration-test/java/sample/ApplicationTests.java @@ -71,7 +71,7 @@ void run() { "ws://localhost:" + this.port + "/sockjs"); assertThatExceptionOfType(ExecutionException.class) - .isThrownBy(() -> wsSession.get().sendMessage(new TextMessage("a"))); + .isThrownBy(() -> wsSession.get().sendMessage(new TextMessage("a"))); } @TestConfiguration diff --git a/spring-session-samples/spring-session-sample-javaconfig-hazelcast/src/main/java/sample/SecurityConfig.java b/spring-session-samples/spring-session-sample-javaconfig-hazelcast/src/main/java/sample/SecurityConfig.java index 3c9711476..7fe5233f7 100644 --- a/spring-session-samples/spring-session-sample-javaconfig-hazelcast/src/main/java/sample/SecurityConfig.java +++ b/spring-session-samples/spring-session-sample-javaconfig-hazelcast/src/main/java/sample/SecurityConfig.java @@ -32,7 +32,7 @@ public class SecurityConfig { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() - .withUser(User.withUsername("user").password("{noop}password").roles("USER").build()); + .withUser(User.withUsername("user").password("{noop}password").roles("USER").build()); } } diff --git a/spring-session-samples/spring-session-sample-javaconfig-hazelcast/src/main/java/sample/SessionConfig.java b/spring-session-samples/spring-session-sample-javaconfig-hazelcast/src/main/java/sample/SessionConfig.java index 49146de23..560415bd5 100644 --- a/spring-session-samples/spring-session-sample-javaconfig-hazelcast/src/main/java/sample/SessionConfig.java +++ b/spring-session-samples/spring-session-sample-javaconfig-hazelcast/src/main/java/sample/SessionConfig.java @@ -42,11 +42,12 @@ public HazelcastInstance hazelcastInstance() { networkConfig.setPort(0); networkConfig.getJoin().getAutoDetectionConfig().setEnabled(false); AttributeConfig attributeConfig = new AttributeConfig() - .setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) - .setExtractorClassName(PrincipalNameExtractor.class.getName()); + .setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) + .setExtractorClassName(PrincipalNameExtractor.class.getName()); config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME) - .addAttributeConfig(attributeConfig).addIndexConfig( - new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)); + .addAttributeConfig(attributeConfig) + .addIndexConfig( + new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)); return Hazelcast.newHazelcastInstance(config); } diff --git a/spring-session-samples/spring-session-sample-javaconfig-jdbc/src/main/java/sample/Config.java b/spring-session-samples/spring-session-sample-javaconfig-jdbc/src/main/java/sample/Config.java index a2ede0de3..587ac3917 100644 --- a/spring-session-samples/spring-session-sample-javaconfig-jdbc/src/main/java/sample/Config.java +++ b/spring-session-samples/spring-session-sample-javaconfig-jdbc/src/main/java/sample/Config.java @@ -35,7 +35,9 @@ public class Config { @Bean public EmbeddedDatabase dataSource() { return new EmbeddedDatabaseBuilder() // <2> - .setType(EmbeddedDatabaseType.H2).addScript("org/springframework/session/jdbc/schema-h2.sql").build(); + .setType(EmbeddedDatabaseType.H2) + .addScript("org/springframework/session/jdbc/schema-h2.sql") + .build(); } @Bean diff --git a/spring-session-samples/spring-session-sample-javaconfig-rest/src/integration-test/java/rest/RestMockMvcTests.java b/spring-session-samples/spring-session-sample-javaconfig-rest/src/integration-test/java/rest/RestMockMvcTests.java index ef77c5e9d..8bc05bb05 100644 --- a/spring-session-samples/spring-session-sample-javaconfig-rest/src/integration-test/java/rest/RestMockMvcTests.java +++ b/spring-session-samples/spring-session-sample-javaconfig-rest/src/integration-test/java/rest/RestMockMvcTests.java @@ -65,14 +65,18 @@ class RestMockMvcTests { @BeforeEach void setup() { - this.mvc = MockMvcBuilders.webAppContextSetup(this.context).alwaysDo(print()) - .addFilters(this.sessionRepositoryFilter).apply(springSecurity()).build(); + this.mvc = MockMvcBuilders.webAppContextSetup(this.context) + .alwaysDo(print()) + .addFilters(this.sessionRepositoryFilter) + .apply(springSecurity()) + .build(); } @Test void noSessionOnNoCredentials() throws Exception { - this.mvc.perform(get("/")).andExpect(header().doesNotExist("X-Auth-Token")) - .andExpect(status().isUnauthorized()); + this.mvc.perform(get("/")) + .andExpect(header().doesNotExist("X-Auth-Token")) + .andExpect(status().isUnauthorized()); } @WithMockUser diff --git a/spring-session-samples/spring-session-sample-javaconfig-rest/src/integration-test/java/sample/RestTests.java b/spring-session-samples/spring-session-sample-javaconfig-rest/src/integration-test/java/sample/RestTests.java index ae1c9ca30..be401af3f 100644 --- a/spring-session-samples/spring-session-sample-javaconfig-rest/src/integration-test/java/sample/RestTests.java +++ b/spring-session-samples/spring-session-sample-javaconfig-rest/src/integration-test/java/sample/RestTests.java @@ -60,8 +60,8 @@ void unauthenticatedUserSentToLogInPage() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); assertThatExceptionOfType(HttpClientErrorException.class) - .isThrownBy(() -> getForUser(this.baseUrl + "/", headers, String.class)) - .satisfies((e) -> assertThat(e.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED)); + .isThrownBy(() -> getForUser(this.baseUrl + "/", headers, String.class)) + .satisfies((e) -> assertThat(e.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED)); } @Test diff --git a/spring-session-samples/spring-session-sample-javaconfig-rest/src/main/java/sample/SecurityConfig.java b/spring-session-samples/spring-session-sample-javaconfig-rest/src/main/java/sample/SecurityConfig.java index c86ef1203..de134568a 100644 --- a/spring-session-samples/spring-session-sample-javaconfig-rest/src/main/java/sample/SecurityConfig.java +++ b/spring-session-samples/spring-session-sample-javaconfig-rest/src/main/java/sample/SecurityConfig.java @@ -52,7 +52,7 @@ SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() - .withUser(User.withUsername("user").password("{noop}password").roles("USER").build()); + .withUser(User.withUsername("user").password("{noop}password").roles("USER").build()); } } diff --git a/spring-session-samples/spring-session-sample-javaconfig-security/src/main/java/sample/SecurityConfig.java b/spring-session-samples/spring-session-sample-javaconfig-security/src/main/java/sample/SecurityConfig.java index 3c9711476..7fe5233f7 100644 --- a/spring-session-samples/spring-session-sample-javaconfig-security/src/main/java/sample/SecurityConfig.java +++ b/spring-session-samples/spring-session-sample-javaconfig-security/src/main/java/sample/SecurityConfig.java @@ -32,7 +32,7 @@ public class SecurityConfig { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() - .withUser(User.withUsername("user").password("{noop}password").roles("USER").build()); + .withUser(User.withUsername("user").password("{noop}password").roles("USER").build()); } }