Search in sources :

Example 11 with MongoCustomConversions

use of org.springframework.data.mongodb.core.convert.MongoCustomConversions in project spring-data-mongodb by spring-projects.

the class ReactiveMongoTemplate method getDefaultMongoConverter.

private MappingMongoConverter getDefaultMongoConverter() {
    MongoCustomConversions conversions = new MongoCustomConversions(Collections.emptyList());
    MongoMappingContext context = new MongoMappingContext();
    context.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
    context.afterPropertiesSet();
    MappingMongoConverter converter = new MappingMongoConverter(NO_OP_REF_RESOLVER, context);
    converter.setCustomConversions(conversions);
    converter.setCodecRegistryProvider(this.mongoDatabaseFactory);
    converter.afterPropertiesSet();
    return converter;
}
Also used : MongoCustomConversions(org.springframework.data.mongodb.core.convert.MongoCustomConversions) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter)

Example 12 with MongoCustomConversions

use of org.springframework.data.mongodb.core.convert.MongoCustomConversions in project spring-data-mongodb by spring-projects.

the class ReactiveMongoTemplateUnitTests method beforeEach.

@BeforeEach
void beforeEach() {
    when(factory.getExceptionTranslator()).thenReturn(exceptionTranslator);
    when(factory.getCodecRegistry()).thenReturn(MongoClientSettings.getDefaultCodecRegistry());
    when(factory.getMongoDatabase()).thenReturn(Mono.just(db));
    when(db.getCollection(any())).thenReturn(collection);
    when(db.getCollection(any(), any())).thenReturn(collection);
    when(db.runCommand(any(), any(Class.class))).thenReturn(runCommandPublisher);
    when(db.createCollection(any(), any(CreateCollectionOptions.class))).thenReturn(runCommandPublisher);
    when(collection.withReadPreference(any())).thenReturn(collection);
    when(collection.find(any(Class.class))).thenReturn(findPublisher);
    when(collection.find(any(Document.class), any(Class.class))).thenReturn(findPublisher);
    when(collection.aggregate(anyList())).thenReturn(aggregatePublisher);
    when(collection.aggregate(anyList(), any(Class.class))).thenReturn(aggregatePublisher);
    when(collection.countDocuments(any(), any(CountOptions.class))).thenReturn(Mono.just(0L));
    when(collection.estimatedDocumentCount(any())).thenReturn(Mono.just(0L));
    when(collection.updateOne(any(), any(Bson.class), any(UpdateOptions.class))).thenReturn(updateResultPublisher);
    when(collection.updateMany(any(Bson.class), any(Bson.class), any())).thenReturn(updateResultPublisher);
    when(collection.updateOne(any(), anyList(), any())).thenReturn(updateResultPublisher);
    when(collection.updateMany(any(), anyList(), any())).thenReturn(updateResultPublisher);
    when(collection.findOneAndUpdate(any(), any(Bson.class), any(FindOneAndUpdateOptions.class))).thenReturn(findAndUpdatePublisher);
    when(collection.findOneAndReplace(any(Bson.class), any(), any())).thenReturn(findPublisher);
    when(collection.findOneAndDelete(any(), any(FindOneAndDeleteOptions.class))).thenReturn(findPublisher);
    when(collection.distinct(anyString(), any(Document.class), any())).thenReturn(distinctPublisher);
    when(collection.deleteMany(any(Bson.class), any())).thenReturn(deletePublisher);
    when(collection.findOneAndUpdate(any(), any(Bson.class), any(FindOneAndUpdateOptions.class))).thenReturn(findAndUpdatePublisher);
    when(collection.mapReduce(anyString(), anyString(), any())).thenReturn(mapReducePublisher);
    when(collection.replaceOne(any(Bson.class), any(), any(ReplaceOptions.class))).thenReturn(updateResultPublisher);
    when(collection.insertOne(any(Bson.class))).thenReturn(successPublisher);
    when(collection.insertMany(anyList())).thenReturn(successPublisher);
    when(findPublisher.projection(any())).thenReturn(findPublisher);
    when(findPublisher.limit(anyInt())).thenReturn(findPublisher);
    when(findPublisher.collation(any())).thenReturn(findPublisher);
    when(findPublisher.first()).thenReturn(findPublisher);
    when(findPublisher.allowDiskUse(anyBoolean())).thenReturn(findPublisher);
    when(aggregatePublisher.allowDiskUse(anyBoolean())).thenReturn(aggregatePublisher);
    when(aggregatePublisher.collation(any())).thenReturn(aggregatePublisher);
    when(aggregatePublisher.maxTime(anyLong(), any())).thenReturn(aggregatePublisher);
    when(aggregatePublisher.first()).thenReturn(findPublisher);
    this.mappingContext = new MongoMappingContext();
    this.mappingContext.setSimpleTypeHolder(new MongoCustomConversions(Collections.emptyList()).getSimpleTypeHolder());
    this.converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext);
    this.template = new ReactiveMongoTemplate(factory, converter);
}
Also used : CountOptions(com.mongodb.client.model.CountOptions) Document(org.bson.Document) UpdateOptions(com.mongodb.client.model.UpdateOptions) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) FindOneAndDeleteOptions(com.mongodb.client.model.FindOneAndDeleteOptions) Bson(org.bson.conversions.Bson) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MongoCustomConversions(org.springframework.data.mongodb.core.convert.MongoCustomConversions) CreateCollectionOptions(com.mongodb.client.model.CreateCollectionOptions) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) ReplaceOptions(com.mongodb.client.model.ReplaceOptions) FindOneAndReplaceOptions(com.mongodb.client.model.FindOneAndReplaceOptions) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MongoCustomConversions (org.springframework.data.mongodb.core.convert.MongoCustomConversions)12 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)10 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)9 DefaultDbRefResolver (org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)6 Document (org.bson.Document)4 DbRefResolver (org.springframework.data.mongodb.core.convert.DbRefResolver)4 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 CountOptions (com.mongodb.client.model.CountOptions)2 FindOneAndReplaceOptions (com.mongodb.client.model.FindOneAndReplaceOptions)2 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)2 ReplaceOptions (com.mongodb.client.model.ReplaceOptions)2 UpdateOptions (com.mongodb.client.model.UpdateOptions)2 Bson (org.bson.conversions.Bson)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 CustomConversions (org.springframework.data.convert.CustomConversions)2 MongoNamespace (com.mongodb.MongoNamespace)1 CreateCollectionOptions (com.mongodb.client.model.CreateCollectionOptions)1 FindOneAndDeleteOptions (com.mongodb.client.model.FindOneAndDeleteOptions)1 DateToOffsetDateTimeConverter (de.spring.example.persistence.converters.DateToOffsetDateTimeConverter)1