Search in sources :

Example 16 with MappingMongoConverter

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

the class ReactiveSessionBoundMongoTemplateUnitTests method setUp.

@Before
public void setUp() {
    when(client.getDatabase(anyString())).thenReturn(database);
    when(codecRegistry.get(any(Class.class))).thenReturn(new BsonValueCodec());
    when(database.getCodecRegistry()).thenReturn(codecRegistry);
    when(database.getCollection(anyString())).thenReturn(collection);
    when(database.getCollection(anyString(), any())).thenReturn(collection);
    when(database.listCollectionNames(any(ClientSession.class))).thenReturn(findPublisher);
    when(database.createCollection(any(ClientSession.class), any(), any())).thenReturn(resultPublisher);
    when(database.runCommand(any(ClientSession.class), any(), any(Class.class))).thenReturn(resultPublisher);
    when(collection.find(any(ClientSession.class))).thenReturn(findPublisher);
    when(collection.find(any(ClientSession.class), any(Document.class))).thenReturn(findPublisher);
    when(collection.find(any(ClientSession.class), any(Class.class))).thenReturn(findPublisher);
    when(collection.find(any(ClientSession.class), any(), any())).thenReturn(findPublisher);
    when(collection.deleteMany(any(ClientSession.class), any(), any())).thenReturn(resultPublisher);
    when(collection.insertOne(any(ClientSession.class), any(Document.class))).thenReturn(resultPublisher);
    when(collection.aggregate(any(ClientSession.class), anyList(), any(Class.class))).thenReturn(aggregatePublisher);
    when(collection.count(any(ClientSession.class), any(), any(CountOptions.class))).thenReturn(resultPublisher);
    when(collection.drop(any(ClientSession.class))).thenReturn(resultPublisher);
    when(collection.findOneAndUpdate(any(ClientSession.class), any(), any(), any())).thenReturn(resultPublisher);
    when(collection.distinct(any(ClientSession.class), any(), any(), any())).thenReturn(distinctPublisher);
    when(collection.updateOne(any(ClientSession.class), any(), any(), any(UpdateOptions.class))).thenReturn(resultPublisher);
    when(collection.updateMany(any(ClientSession.class), any(), any(), any(UpdateOptions.class))).thenReturn(resultPublisher);
    when(collection.dropIndex(any(ClientSession.class), anyString())).thenReturn(resultPublisher);
    when(findPublisher.projection(any())).thenReturn(findPublisher);
    when(findPublisher.limit(anyInt())).thenReturn(findPublisher);
    when(findPublisher.collation(any())).thenReturn(findPublisher);
    when(findPublisher.first()).thenReturn(resultPublisher);
    when(aggregatePublisher.allowDiskUse(anyBoolean())).thenReturn(aggregatePublisher);
    when(aggregatePublisher.useCursor(anyBoolean())).thenReturn(aggregatePublisher);
    factory = new SimpleReactiveMongoDatabaseFactory(client, "foo");
    this.mappingContext = new MongoMappingContext();
    this.converter = new MappingMongoConverter(new NoOpDbRefResolver(), mappingContext);
    this.template = new ReactiveSessionBoundMongoTemplate(clientSession, new ReactiveMongoTemplate(factory, converter));
}
Also used : BsonValueCodec(org.bson.codecs.BsonValueCodec) NoOpDbRefResolver(org.springframework.data.mongodb.core.ReactiveMongoTemplate.NoOpDbRefResolver) ClientSession(com.mongodb.session.ClientSession) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) CountOptions(com.mongodb.client.model.CountOptions) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Document(org.bson.Document) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) UpdateOptions(com.mongodb.client.model.UpdateOptions) ReactiveSessionBoundMongoTemplate(org.springframework.data.mongodb.core.ReactiveMongoTemplate.ReactiveSessionBoundMongoTemplate) Before(org.junit.Before)

Example 17 with MappingMongoConverter

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

the class AbstractMongoConfigurationUnitTests method shouldBeAbleToConfigureCustomTypeMapperViaJavaConfig.

// DATAMONGO-725
@Test
public void shouldBeAbleToConfigureCustomTypeMapperViaJavaConfig() {
    AbstractApplicationContext context = new AnnotationConfigApplicationContext(SampleMongoConfiguration.class);
    MongoTypeMapper typeMapper = context.getBean(CustomMongoTypeMapper.class);
    MappingMongoConverter mmc = context.getBean(MappingMongoConverter.class);
    assertThat(mmc, is(notNullValue()));
    assertThat(mmc.getTypeMapper(), is(typeMapper));
    context.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoTypeMapper(org.springframework.data.mongodb.core.convert.MongoTypeMapper) Test(org.junit.Test)

Example 18 with MappingMongoConverter

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

the class AbstractReactiveMongoConfigurationUnitTests method shouldBeAbleToConfigureCustomTypeMapperViaJavaConfig.

// DATAMONGO-1444
@Test
public void shouldBeAbleToConfigureCustomTypeMapperViaJavaConfig() {
    AbstractApplicationContext context = new AnnotationConfigApplicationContext(SampleMongoConfiguration.class);
    MongoTypeMapper typeMapper = context.getBean(CustomMongoTypeMapper.class);
    MappingMongoConverter mmc = context.getBean(MappingMongoConverter.class);
    assertThat(mmc, is(notNullValue()));
    assertThat(mmc.getTypeMapper(), is(typeMapper));
    context.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoTypeMapper(org.springframework.data.mongodb.core.convert.MongoTypeMapper) Test(org.junit.Test)

Example 19 with MappingMongoConverter

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

the class MongoDataAutoConfiguration method mappingMongoConverter.

@Bean
@ConditionalOnMissingBean(MongoConverter.class)
public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory, MongoMappingContext context, BeanFactory beanFactory, CustomConversions conversions) {
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
    MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver, context);
    mappingConverter.setCustomConversions(conversions);
    return mappingConverter;
}
Also used : DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) DbRefResolver(org.springframework.data.mongodb.core.convert.DbRefResolver) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 20 with MappingMongoConverter

use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project cas by apereo.

the class MongoDbConnectionFactory method mappingMongoConverter.

private MappingMongoConverter mappingMongoConverter(final MongoDbFactory mongoDbFactory) {
    final DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);
    final MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, this.mongoMappingContext());
    converter.setCustomConversions(customConversions);
    converter.afterPropertiesSet();
    return converter;
}
Also used : DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) DbRefResolver(org.springframework.data.mongodb.core.convert.DbRefResolver) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)

Aggregations

MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)35 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)21 Before (org.junit.Before)19 DefaultDbRefResolver (org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)14 DbRefResolver (org.springframework.data.mongodb.core.convert.DbRefResolver)9 Bean (org.springframework.context.annotation.Bean)7 Test (org.junit.Test)6 Document (org.bson.Document)5 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)5 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)5 QueryMapper (org.springframework.data.mongodb.core.convert.QueryMapper)5 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)3 MongoCustomConversions (org.springframework.data.mongodb.core.convert.MongoCustomConversions)3 MongoTypeMapper (org.springframework.data.mongodb.core.convert.MongoTypeMapper)3 BasicDBObject (com.mongodb.BasicDBObject)2 MongoClientURI (com.mongodb.MongoClientURI)2 CountOptions (com.mongodb.client.model.CountOptions)2 ClientSession (com.mongodb.session.ClientSession)2 Net (de.flapdoodle.embed.mongo.config.Net)2 BsonValueCodec (org.bson.codecs.BsonValueCodec)2