Search in sources :

Example 26 with MappingMongoConverter

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

the class AbstractMongoQueryUnitTests method setUp.

@Before
public void setUp() {
    doReturn("persons").when(persitentEntityMock).getCollection();
    doReturn(persitentEntityMock).when(mappingContextMock).getPersistentEntity(Mockito.any(Class.class));
    doReturn(persitentEntityMock).when(mappingContextMock).getRequiredPersistentEntity(Mockito.any(Class.class));
    doReturn(Person.class).when(persitentEntityMock).getType();
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(mock(MongoDbFactory.class));
    MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContextMock);
    converter.afterPropertiesSet();
    doReturn(converter).when(mongoOperationsMock).getConverter();
    doReturn(executableFind).when(mongoOperationsMock).query(any());
    doReturn(withQueryMock).when(executableFind).as(any());
    doReturn(withQueryMock).when(withQueryMock).matching(any());
}
Also used : MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) 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) Before(org.junit.Before)

Example 27 with MappingMongoConverter

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

the class ConvertingParameterAccessorUnitTests method setUp.

@Before
public void setUp() {
    this.context = new MongoMappingContext();
    this.resolver = new DefaultDbRefResolver(factory);
    this.converter = new MappingMongoConverter(resolver, context);
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Before(org.junit.Before)

Example 28 with MappingMongoConverter

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

the class ReactiveStringBasedMongoQueryUnitTests method setUp.

@Before
public void setUp() {
    when(operations.query(any())).thenReturn(reactiveFind);
    this.converter = new MappingMongoConverter(factory, new MongoMappingContext());
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Before(org.junit.Before)

Example 29 with MappingMongoConverter

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

the class AbstractMongoConfiguration method mappingMongoConverter.

/**
 * Creates a {@link MappingMongoConverter} using the configured {@link #mongoDbFactory()} and
 * {@link #mongoMappingContext()}. Will get {@link #customConversions()} applied.
 *
 * @see #customConversions()
 * @see #mongoMappingContext()
 * @see #mongoDbFactory()
 * @return
 * @throws Exception
 */
@Bean
public MappingMongoConverter mappingMongoConverter() throws Exception {
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory());
    MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext());
    converter.setCustomConversions(customConversions());
    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) Bean(org.springframework.context.annotation.Bean)

Example 30 with MappingMongoConverter

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

the class SessionBoundMongoTemplateTests method getDefaultMongoConverter.

private MongoConverter getDefaultMongoConverter(MongoDbFactory factory) {
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
    MongoCustomConversions conversions = new MongoCustomConversions(Collections.emptyList());
    MongoMappingContext mappingContext = new MongoMappingContext();
    mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
    mappingContext.afterPropertiesSet();
    MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContext);
    converter.setCustomConversions(conversions);
    converter.afterPropertiesSet();
    return converter;
}
Also used : DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MongoCustomConversions(org.springframework.data.mongodb.core.convert.MongoCustomConversions) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) 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