Polishing.
Reformat code. Suppress warnings in tests. Original pull request: #4541 See #4495
This commit is contained in:
@@ -736,6 +736,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
public <T> Mono<Void> dropCollection(Class<T> entityClass) {
|
||||
return dropCollection(getCollectionName(entityClass));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> dropCollection(String collectionName) {
|
||||
|
||||
@@ -874,7 +875,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
Assert.notNull(targetClass, "Target type must not be null");
|
||||
|
||||
EntityProjection<T, ?> projection = operations.introspectProjection(targetClass, sourceClass);
|
||||
ProjectingReadCallback<?,T> callback = new ProjectingReadCallback<>(mongoConverter, projection, collectionName);
|
||||
ProjectingReadCallback<?, T> callback = new ProjectingReadCallback<>(mongoConverter, projection, collectionName);
|
||||
int limit = query.isLimited() ? query.getLimit() + 1 : Integer.MAX_VALUE;
|
||||
|
||||
if (query.hasKeyset()) {
|
||||
@@ -884,7 +885,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
Mono<List<T>> result = doFind(collectionName, ReactiveCollectionPreparerDelegate.of(query),
|
||||
keysetPaginationQuery.query(), keysetPaginationQuery.fields(), sourceClass,
|
||||
new QueryFindPublisherPreparer(query, keysetPaginationQuery.sort(), limit, 0, sourceClass), callback).collectList();
|
||||
new QueryFindPublisherPreparer(query, keysetPaginationQuery.sort(), limit, 0, sourceClass), callback)
|
||||
.collectList();
|
||||
|
||||
return result.map(it -> ScrollUtils.createWindow(query, it, sourceClass, operations));
|
||||
}
|
||||
@@ -2012,8 +2014,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
publisher = options.getCollation().map(Collation::toMongoCollation).map(publisher::collation)
|
||||
.orElse(publisher);
|
||||
publisher = options.getResumeBsonTimestamp().map(publisher::startAtOperationTime).orElse(publisher);
|
||||
|
||||
if(options.getFullDocumentBeforeChangeLookup().isPresent()) {
|
||||
|
||||
if (options.getFullDocumentBeforeChangeLookup().isPresent()) {
|
||||
publisher = publisher.fullDocumentBeforeChange(options.getFullDocumentBeforeChangeLookup().get());
|
||||
}
|
||||
return publisher.fullDocument(options.getFullDocumentLookup().orElse(fullDocument));
|
||||
@@ -2622,7 +2624,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(WriteResultChecking.EXCEPTION, writeResultChecking)) {
|
||||
if (wc == null || wc.getWObject() == null
|
||||
|| (wc.getWObject() instanceof Number concern && concern.intValue() < 1)) {
|
||||
|| (wc.getWObject()instanceof Number concern && concern.intValue() < 1)) {
|
||||
return WriteConcern.ACKNOWLEDGED;
|
||||
}
|
||||
}
|
||||
@@ -3200,8 +3202,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
HintFunction hintFunction = HintFunction.from(query.getHint());
|
||||
Meta meta = query.getMeta();
|
||||
if (skip <= 0 && limit <= 0 && ObjectUtils.isEmpty(sortObject) && hintFunction.isEmpty()
|
||||
&& !meta.hasValues()) {
|
||||
if (skip <= 0 && limit <= 0 && ObjectUtils.isEmpty(sortObject) && hintFunction.isEmpty() && !meta.hasValues()) {
|
||||
return findPublisherToUse;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,9 +91,9 @@ class ChangeStreamTask extends CursorReadingTask<ChangeStreamDocument<Document>,
|
||||
BsonTimestamp startAt = null;
|
||||
boolean resumeAfter = true;
|
||||
|
||||
if (options instanceof ChangeStreamRequest.ChangeStreamRequestOptions changeStreamRequestOptions) {
|
||||
if (options instanceof ChangeStreamRequest.ChangeStreamRequestOptions requestOptions) {
|
||||
|
||||
ChangeStreamOptions changeStreamOptions = changeStreamRequestOptions.getChangeStreamOptions();
|
||||
ChangeStreamOptions changeStreamOptions = requestOptions.getChangeStreamOptions();
|
||||
filter = prepareFilter(template, changeStreamOptions);
|
||||
|
||||
if (changeStreamOptions.getFilter().isPresent()) {
|
||||
@@ -115,9 +115,7 @@ class ChangeStreamTask extends CursorReadingTask<ChangeStreamDocument<Document>,
|
||||
.orElseGet(() -> ClassUtils.isAssignable(Document.class, targetType) ? FullDocument.DEFAULT
|
||||
: FullDocument.UPDATE_LOOKUP);
|
||||
|
||||
if(changeStreamOptions.getFullDocumentBeforeChangeLookup().isPresent()) {
|
||||
fullDocumentBeforeChange = changeStreamOptions.getFullDocumentBeforeChangeLookup().get();
|
||||
}
|
||||
fullDocumentBeforeChange = changeStreamOptions.getFullDocumentBeforeChangeLookup().orElse(null);
|
||||
|
||||
startAt = changeStreamOptions.getResumeBsonTimestamp().orElse(null);
|
||||
}
|
||||
@@ -158,7 +156,7 @@ class ChangeStreamTask extends CursorReadingTask<ChangeStreamDocument<Document>,
|
||||
}
|
||||
|
||||
iterable = iterable.fullDocument(fullDocument);
|
||||
if(fullDocumentBeforeChange != null) {
|
||||
if (fullDocumentBeforeChange != null) {
|
||||
iterable = iterable.fullDocumentBeforeChange(fullDocumentBeforeChange);
|
||||
}
|
||||
|
||||
@@ -180,7 +178,8 @@ class ChangeStreamTask extends CursorReadingTask<ChangeStreamDocument<Document>,
|
||||
template.getConverter().getMappingContext(), queryMapper)
|
||||
: Aggregation.DEFAULT_CONTEXT;
|
||||
|
||||
return aggregation.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", denylist));
|
||||
return aggregation
|
||||
.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", denylist));
|
||||
}
|
||||
|
||||
if (filter instanceof List) {
|
||||
|
||||
@@ -23,7 +23,6 @@ import static org.springframework.data.mongodb.test.util.Assertions.assertThat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.data.mongodb.util.BsonUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
@@ -93,6 +92,7 @@ import org.springframework.data.mongodb.core.query.NearQuery;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
import org.springframework.data.mongodb.core.timeseries.Granularity;
|
||||
import org.springframework.data.mongodb.util.BsonUtils;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
@@ -101,7 +101,6 @@ import org.springframework.util.CollectionUtils;
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.ReadConcern;
|
||||
import com.mongodb.ReadPreference;
|
||||
import com.mongodb.WriteConcern;
|
||||
import com.mongodb.client.model.CountOptions;
|
||||
import com.mongodb.client.model.CreateCollectionOptions;
|
||||
import com.mongodb.client.model.DeleteOptions;
|
||||
@@ -369,7 +368,8 @@ public class ReactiveMongoTemplateUnitTests {
|
||||
@Test // GH-3218
|
||||
void updateUsesHintDocumentFromQuery() {
|
||||
|
||||
template.updateFirst(new Query().withHint("{ firstname : 1 }"), new Update().set("spring", "data"), Person.class).subscribe();
|
||||
template.updateFirst(new Query().withHint("{ firstname : 1 }"), new Update().set("spring", "data"), Person.class)
|
||||
.subscribe();
|
||||
|
||||
ArgumentCaptor<UpdateOptions> options = ArgumentCaptor.forClass(UpdateOptions.class);
|
||||
verify(collection).updateOne(any(Bson.class), any(Bson.class), options.capture());
|
||||
@@ -1617,11 +1617,11 @@ public class ReactiveMongoTemplateUnitTests {
|
||||
when(changeStreamPublisher.fullDocument(any())).thenReturn(changeStreamPublisher);
|
||||
when(changeStreamPublisher.fullDocumentBeforeChange(any())).thenReturn(changeStreamPublisher);
|
||||
|
||||
template
|
||||
.changeStream("database", "collection", ChangeStreamOptions.builder().fullDocumentBeforeChangeLookup(FullDocumentBeforeChange.REQUIRED).build(), Object.class)
|
||||
.subscribe();
|
||||
ChangeStreamOptions options = ChangeStreamOptions.builder()
|
||||
.fullDocumentBeforeChangeLookup(FullDocumentBeforeChange.REQUIRED).build();
|
||||
template.changeStream("database", "collection", options, Object.class).subscribe();
|
||||
|
||||
verify(changeStreamPublisher).fullDocumentBeforeChange(eq(FullDocumentBeforeChange.REQUIRED));
|
||||
verify(changeStreamPublisher).fullDocumentBeforeChange(FullDocumentBeforeChange.REQUIRED);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -41,18 +41,21 @@ import com.mongodb.client.model.changestream.ChangeStreamDocument;
|
||||
import com.mongodb.client.model.changestream.FullDocumentBeforeChange;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ChangeStreamTask}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Myroslav Kosinskyi
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
class ChangeStreamTaskUnitTests {
|
||||
|
||||
ChangeStreamTask task;
|
||||
@Mock MongoTemplate template;
|
||||
@Mock MongoDatabase mongoDatabase;
|
||||
@Mock MongoCollection<Document> mongoCollection;
|
||||
@Mock ChangeStreamIterable<Document> changeStreamIterable;
|
||||
private MongoConverter converter;
|
||||
|
||||
MongoConverter converter;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@@ -64,9 +67,7 @@ class ChangeStreamTaskUnitTests {
|
||||
when(template.getDb()).thenReturn(mongoDatabase);
|
||||
|
||||
when(mongoDatabase.getCollection(any())).thenReturn(mongoCollection);
|
||||
|
||||
when(mongoCollection.watch(eq(Document.class))).thenReturn(changeStreamIterable);
|
||||
|
||||
when(changeStreamIterable.fullDocument(any())).thenReturn(changeStreamIterable);
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ class ChangeStreamTaskUnitTests {
|
||||
|
||||
initTask(request, Document.class);
|
||||
|
||||
verify(changeStreamIterable).resumeAfter(eq(resumeToken));
|
||||
verify(changeStreamIterable).resumeAfter(resumeToken);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2258
|
||||
@@ -102,7 +103,7 @@ class ChangeStreamTaskUnitTests {
|
||||
|
||||
initTask(request, Document.class);
|
||||
|
||||
verify(changeStreamIterable).resumeAfter(eq(resumeToken));
|
||||
verify(changeStreamIterable).resumeAfter(resumeToken);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2258
|
||||
@@ -120,7 +121,7 @@ class ChangeStreamTaskUnitTests {
|
||||
|
||||
initTask(request, Document.class);
|
||||
|
||||
verify(changeStreamIterable).startAfter(eq(resumeToken));
|
||||
verify(changeStreamIterable).startAfter(resumeToken);
|
||||
}
|
||||
|
||||
@Test // GH-4495
|
||||
@@ -136,7 +137,7 @@ class ChangeStreamTaskUnitTests {
|
||||
|
||||
initTask(request, Document.class);
|
||||
|
||||
verify(changeStreamIterable).fullDocumentBeforeChange(eq(FullDocumentBeforeChange.REQUIRED));
|
||||
verify(changeStreamIterable).fullDocumentBeforeChange(FullDocumentBeforeChange.REQUIRED);
|
||||
}
|
||||
|
||||
private MongoCursor<ChangeStreamDocument<Document>> initTask(ChangeStreamRequest request, Class<?> targetType) {
|
||||
|
||||
Reference in New Issue
Block a user