Merge branch '3.1.x'

Closes gh-2530
This commit is contained in:
Marcus Da Coregio
2023-10-19 10:35:43 -03:00
104 changed files with 732 additions and 634 deletions

View File

@@ -89,7 +89,7 @@ public class JacksonMongoSessionConverterTest extends AbstractMongoSessionConver
void shouldNotAllowNullObjectMapperToBeInjected() {
Assertions.assertThatIllegalArgumentException()
.isThrownBy(() -> new JacksonMongoSessionConverter((ObjectMapper) null));
.isThrownBy(() -> new JacksonMongoSessionConverter((ObjectMapper) null));
}
@Test

View File

@@ -43,14 +43,14 @@ public class JdkMongoSessionConverterTest extends AbstractMongoSessionConverterT
@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));
}
}

View File

@@ -79,7 +79,7 @@ public class MongoIndexedSessionRepositoryTest {
// then
assertThat(session.getId()).isNotEmpty();
assertThat(session.getMaxInactiveInterval().getSeconds())
.isEqualTo(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
.isEqualTo(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
}
@Test
@@ -90,7 +90,8 @@ public class MongoIndexedSessionRepositoryTest {
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);
@@ -106,12 +107,14 @@ public class MongoIndexedSessionRepositoryTest {
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);
@@ -128,13 +131,15 @@ public class MongoIndexedSessionRepositoryTest {
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
@@ -157,9 +162,11 @@ public class MongoIndexedSessionRepositoryTest {
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);
@@ -180,14 +187,15 @@ public class MongoIndexedSessionRepositoryTest {
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<String, MongoSession> sessionsMap = this.repository.findByIndexNameAndIndexValue(principalNameIndexName,
@@ -231,12 +239,14 @@ public class MongoIndexedSessionRepositoryTest {
Document sessionDocument = new Document();
given(this.mongoOperations.findById("123", Document.class,
MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(sessionDocument);
MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME))
.willReturn(sessionDocument);
MongoSession session = new MongoSession("123");
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
TypeDescriptor.valueOf(MongoSession.class))).willReturn(session);
TypeDescriptor.valueOf(MongoSession.class)))
.willReturn(session);
MongoSession retrievedSession = this.repository.findById("123");
assertThat(retrievedSession.getId()).isEqualTo("123");

View File

@@ -84,14 +84,14 @@ public class ReactiveMongoSessionRepositoryTest {
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
@@ -102,14 +102,15 @@ public class ReactiveMongoSessionRepositoryTest {
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);
}
@@ -122,18 +123,20 @@ public class ReactiveMongoSessionRepositoryTest {
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
@@ -144,21 +147,23 @@ public class ReactiveMongoSessionRepositoryTest {
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),
@@ -173,20 +178,22 @@ public class ReactiveMongoSessionRepositoryTest {
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));
@@ -224,7 +231,7 @@ public class ReactiveMongoSessionRepositoryTest {
@Test
void setSessionIdGeneratorWhenNullThenThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerator(null))
.withMessage("sessionIdGenerator cannot be null");
.withMessage("sessionIdGenerator cannot be null");
}
@Test
@@ -235,12 +242,14 @@ public class ReactiveMongoSessionRepositoryTest {
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(sessionId);
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
TypeDescriptor.valueOf(MongoSession.class))).willReturn(session);
TypeDescriptor.valueOf(MongoSession.class)))
.willReturn(session);
this.repository.findById(sessionId).as(StepVerifier::create).assertNext((mongoSession) -> {
String oldId = mongoSession.getId();

View File

@@ -74,8 +74,8 @@ public class MongoHttpSessionConfigurationTest {
void noMongoOperationsConfiguration() {
assertThatExceptionOfType(UnsatisfiedDependencyException.class)
.isThrownBy(() -> registerAndRefresh(EmptyConfiguration.class))
.withMessageContaining("mongoSessionRepository");
.isThrownBy(() -> registerAndRefresh(EmptyConfiguration.class))
.withMessageContaining("mongoSessionRepository");
}
@Test
@@ -116,7 +116,7 @@ public class MongoHttpSessionConfigurationTest {
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
@@ -127,7 +127,7 @@ public class MongoHttpSessionConfigurationTest {
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
@@ -147,7 +147,7 @@ public class MongoHttpSessionConfigurationTest {
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);
@@ -176,8 +176,8 @@ public class MongoHttpSessionConfigurationTest {
assertThat(repository).isNotNull();
assertThat(indexResolver).isNotNull();
assertThat(repository).extracting("mongoSessionConverter").hasFieldOrPropertyWithValue("indexResolver",
indexResolver);
assertThat(repository).extracting("mongoSessionConverter")
.hasFieldOrPropertyWithValue("indexResolver", indexResolver);
}
@Test
@@ -191,8 +191,8 @@ public class MongoHttpSessionConfigurationTest {
assertThat(repository).isNotNull();
assertThat(indexResolver).isNotNull();
assertThat(repository).extracting("mongoSessionConverter").hasFieldOrPropertyWithValue("indexResolver",
indexResolver);
assertThat(repository).extracting("mongoSessionConverter")
.hasFieldOrPropertyWithValue("indexResolver", indexResolver);
}
@Test

View File

@@ -97,9 +97,8 @@ public class ReactiveMongoWebSessionConfigurationTest {
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
@@ -195,8 +194,8 @@ public class ReactiveMongoWebSessionConfigurationTest {
assertThat(repository).isNotNull();
assertThat(indexResolver).isNotNull();
assertThat(repository).extracting("mongoSessionConverter").hasFieldOrPropertyWithValue("indexResolver",
indexResolver);
assertThat(repository).extracting("mongoSessionConverter")
.hasFieldOrPropertyWithValue("indexResolver", indexResolver);
}
@Test
@@ -211,8 +210,8 @@ public class ReactiveMongoWebSessionConfigurationTest {
assertThat(repository).isNotNull();
assertThat(indexResolver).isNotNull();
assertThat(repository).extracting("mongoSessionConverter").hasFieldOrPropertyWithValue("indexResolver",
indexResolver);
assertThat(repository).extracting("mongoSessionConverter")
.hasFieldOrPropertyWithValue("indexResolver", indexResolver);
}
@Test