Merge branch '3.0.x' into 3.1.x
Closes gh-2529
This commit is contained in:
@@ -134,7 +134,7 @@ abstract class AbstractJdbcIndexedSessionRepositoryITests {
|
||||
assertThat(session.getDelta()).isEmpty();
|
||||
assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
|
||||
assertThat(session.<String>getAttribute(expectedAttributeName))
|
||||
.isEqualTo(toSave.getAttribute(expectedAttributeName));
|
||||
.isEqualTo(toSave.getAttribute(expectedAttributeName));
|
||||
|
||||
this.repository.deleteById(toSave.getId());
|
||||
|
||||
@@ -190,7 +190,7 @@ abstract class AbstractJdbcIndexedSessionRepositoryITests {
|
||||
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 @@ abstract class AbstractJdbcIndexedSessionRepositoryITests {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@ class DerbyJdbcIndexedSessionRepositoryITests extends AbstractJdbcIndexedSession
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ class H2JdbcIndexedSessionRepositoryITests extends AbstractJdbcIndexedSessionRep
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ class HsqldbJdbcIndexedSessionRepositoryITests extends AbstractJdbcIndexedSessio
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -499,7 +499,7 @@ public class JdbcIndexedSessionRepository implements
|
||||
@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 class JdbcIndexedSessionRepository implements
|
||||
}
|
||||
|
||||
List<JdbcSession> 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<String, JdbcSession> sessionMap = new HashMap<>(sessions.size());
|
||||
|
||||
@@ -641,8 +641,8 @@ public class JdbcIndexedSessionRepository implements
|
||||
|
||||
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 @@ public class JdbcIndexedSessionRepository implements
|
||||
if (this.isNew) {
|
||||
JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> {
|
||||
Map<String, String> 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<String> attributeNames = getAttributeNames();
|
||||
if (!attributeNames.isEmpty()) {
|
||||
insertSessionAttributes(JdbcSession.this, new ArrayList<>(attributeNames));
|
||||
@@ -894,32 +894,38 @@ public class JdbcIndexedSessionRepository implements
|
||||
JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> {
|
||||
if (JdbcSession.this.changed) {
|
||||
Map<String, String> 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<String> addedAttributeNames = JdbcSession.this.delta.entrySet().stream()
|
||||
.filter((entry) -> entry.getValue() == DeltaValue.ADDED).map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
List<String> 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<String> updatedAttributeNames = JdbcSession.this.delta.entrySet().stream()
|
||||
.filter((entry) -> entry.getValue() == DeltaValue.UPDATED).map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
List<String> 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<String> removedAttributeNames = JdbcSession.this.delta.entrySet().stream()
|
||||
.filter((entry) -> entry.getValue() == DeltaValue.REMOVED).map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
List<String> 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);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public class JdbcHttpSessionConfiguration implements BeanClassLoaderAware, Embed
|
||||
sessionRepository.setConversionService(createConversionServiceWithBeanClassLoader(this.classLoader));
|
||||
}
|
||||
this.sessionRepositoryCustomizers
|
||||
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
|
||||
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
|
||||
return sessionRepository;
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ public class JdbcHttpSessionConfiguration implements BeanClassLoaderAware, Embed
|
||||
@Override
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
Map<String, Object> attributeMap = importMetadata
|
||||
.getAnnotationAttributes(EnableJdbcHttpSession.class.getName());
|
||||
.getAnnotationAttributes(EnableJdbcHttpSession.class.getName());
|
||||
AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
|
||||
if (attributes == null) {
|
||||
return;
|
||||
|
||||
@@ -89,171 +89,171 @@ class JdbcIndexedSessionRepositoryTests {
|
||||
@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 @@ class JdbcIndexedSessionRepositoryTests {
|
||||
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 @@ class JdbcIndexedSessionRepositoryTests {
|
||||
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 @@ class JdbcIndexedSessionRepositoryTests {
|
||||
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 @@ class JdbcIndexedSessionRepositoryTests {
|
||||
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<String, JdbcSession> 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 @@ class JdbcIndexedSessionRepositoryTests {
|
||||
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<String, JdbcSession> 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 @@ class JdbcIndexedSessionRepositoryTests {
|
||||
session.setAttribute("attribute3", "value4");
|
||||
this.repository.save(session);
|
||||
ArgumentCaptor<BatchPreparedStatementSetter> 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 @@ class JdbcIndexedSessionRepositoryTests {
|
||||
session.setAttribute("attribute3", "value4");
|
||||
this.repository.save(session);
|
||||
ArgumentCaptor<BatchPreparedStatementSetter> 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);
|
||||
|
||||
@@ -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 @@ class SessionJdbcRuntimeHintsTests {
|
||||
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<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -81,9 +81,10 @@ class JdbcHttpSessionConfigurationTests {
|
||||
@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 @@ class JdbcHttpSessionConfigurationTests {
|
||||
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 @@ class JdbcHttpSessionConfigurationTests {
|
||||
|
||||
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 @@ class JdbcHttpSessionConfigurationTests {
|
||||
|
||||
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 @@ class JdbcHttpSessionConfigurationTests {
|
||||
@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 @@ class JdbcHttpSessionConfigurationTests {
|
||||
@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 @@ class JdbcHttpSessionConfigurationTests {
|
||||
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 @@ class JdbcHttpSessionConfigurationTests {
|
||||
@Order(1)
|
||||
SessionRepositoryCustomizer<JdbcIndexedSessionRepository> sessionRepositoryCustomizerTwo() {
|
||||
return (sessionRepository) -> sessionRepository
|
||||
.setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||
.setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class JdbcSchemaUtilsTests {
|
||||
|
||||
private static Stream<Resource> getSchemaFiles() throws IOException {
|
||||
return Arrays.stream(new PathMatchingResourcePatternResolver()
|
||||
.getResources("classpath*:org/springframework/session/jdbc/schema-*.sql"));
|
||||
.getResources("classpath*:org/springframework/session/jdbc/schema-*.sql"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user