|
1 | 1 | /* |
2 | | - * Copyright 2012-2022 the original author or authors. |
| 2 | + * Copyright 2012-2023 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
49 | 49 | import org.springframework.session.data.redis.RedisIndexedSessionRepository; |
50 | 50 | import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository; |
51 | 51 | import org.springframework.session.jdbc.JdbcIndexedSessionRepository; |
| 52 | +import org.springframework.session.jdbc.PostgreSqlJdbcIndexedSessionRepositoryCustomizer; |
52 | 53 | import org.springframework.session.jdbc.config.annotation.SpringSessionDataSource; |
53 | 54 |
|
54 | 55 | import static org.assertj.core.api.Assertions.assertThat; |
@@ -243,6 +244,23 @@ void whenTheUserDefinesTheirOwnDatabaseInitializerThenTheAutoConfiguredJdbcSessi |
243 | 244 | .hasBean("customInitializer")); |
244 | 245 | } |
245 | 246 |
|
| 247 | + @Test |
| 248 | + void whenTheUserDefinesTheirOwnJdbcIndexedSessionRepositoryCustomizerThenDefaultConfigurationIsOverwritten() { |
| 249 | + String expectedCreateSessionAttributeQuery = """ |
| 250 | + INSERT INTO SPRING_SESSION_ATTRIBUTES (SESSION_PRIMARY_ID, ATTRIBUTE_NAME, ATTRIBUTE_BYTES) |
| 251 | + VALUES (?, ?, ?) |
| 252 | + ON CONFLICT (SESSION_PRIMARY_ID, ATTRIBUTE_NAME) |
| 253 | + DO UPDATE SET ATTRIBUTE_BYTES = EXCLUDED.ATTRIBUTE_BYTES |
| 254 | + """; |
| 255 | + this.contextRunner.withUserConfiguration(CustomJdbcIndexedSessionRepositoryCustomizerConfiguration.class) |
| 256 | + .withConfiguration(AutoConfigurations.of(JdbcSessionConfiguration.class)).run((context) -> { |
| 257 | + JdbcIndexedSessionRepository repository = validateSessionRepository(context, |
| 258 | + JdbcIndexedSessionRepository.class); |
| 259 | + assertThat(repository).hasFieldOrPropertyWithValue("createSessionAttributeQuery", |
| 260 | + expectedCreateSessionAttributeQuery); |
| 261 | + }); |
| 262 | + } |
| 263 | + |
246 | 264 | @Configuration |
247 | 265 | static class SessionDataSourceConfiguration { |
248 | 266 |
|
@@ -289,4 +307,14 @@ DataSourceScriptDatabaseInitializer customInitializer(DataSource dataSource) { |
289 | 307 |
|
290 | 308 | } |
291 | 309 |
|
| 310 | + @Configuration |
| 311 | + static class CustomJdbcIndexedSessionRepositoryCustomizerConfiguration { |
| 312 | + |
| 313 | + @Bean |
| 314 | + PostgreSqlJdbcIndexedSessionRepositoryCustomizer postgreSqlJdbcIndexedSessionRepositoryCustomizer() { |
| 315 | + return new PostgreSqlJdbcIndexedSessionRepositoryCustomizer(); |
| 316 | + } |
| 317 | + |
| 318 | + } |
| 319 | + |
292 | 320 | } |
0 commit comments