Search in sources :

Example 31 with MappingMongoConverter

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

the class SessionBoundMongoTemplateUnitTests 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(), any())).thenReturn(collection);
    when(database.listCollectionNames(any(ClientSession.class))).thenReturn(mongoIterable);
    when(collection.find(any(ClientSession.class), any(), any())).thenReturn(findIterable);
    when(collection.aggregate(any(ClientSession.class), anyList(), any())).thenReturn(aggregateIterable);
    when(collection.distinct(any(ClientSession.class), any(), any(), any())).thenReturn(distinctIterable);
    when(collection.mapReduce(any(ClientSession.class), any(), any(), any())).thenReturn(mapReduceIterable);
    when(findIterable.iterator()).thenReturn(cursor);
    when(aggregateIterable.collation(any())).thenReturn(aggregateIterable);
    when(aggregateIterable.allowDiskUse(anyBoolean())).thenReturn(aggregateIterable);
    when(aggregateIterable.batchSize(anyInt())).thenReturn(aggregateIterable);
    when(aggregateIterable.map(any())).thenReturn(aggregateIterable);
    when(aggregateIterable.useCursor(anyBoolean())).thenReturn(aggregateIterable);
    when(aggregateIterable.into(any())).thenReturn(Collections.emptyList());
    when(mongoIterable.iterator()).thenReturn(cursor);
    when(distinctIterable.map(any())).thenReturn(distinctIterable);
    when(distinctIterable.into(any())).thenReturn(Collections.emptyList());
    when(mapReduceIterable.sort(any())).thenReturn(mapReduceIterable);
    when(mapReduceIterable.filter(any())).thenReturn(mapReduceIterable);
    when(mapReduceIterable.map(any())).thenReturn(mapReduceIterable);
    when(mapReduceIterable.iterator()).thenReturn(cursor);
    when(cursor.hasNext()).thenReturn(false);
    when(findIterable.projection(any())).thenReturn(findIterable);
    factory = new SimpleMongoDbFactory(client, "foo");
    this.mappingContext = new MongoMappingContext();
    this.converter = new MappingMongoConverter(new DefaultDbRefResolver(factory), mappingContext);
    this.template = new SessionBoundMongoTemplate(clientSession, new MongoTemplate(factory, converter));
}
Also used : BsonValueCodec(org.bson.codecs.BsonValueCodec) ClientSession(com.mongodb.session.ClientSession) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) SessionBoundMongoTemplate(org.springframework.data.mongodb.core.MongoTemplate.SessionBoundMongoTemplate) SessionBoundMongoTemplate(org.springframework.data.mongodb.core.MongoTemplate.SessionBoundMongoTemplate) Before(org.junit.Before)

Example 32 with MappingMongoConverter

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

the class MongoTemplateUnitTests method setUp.

@Before
public void setUp() {
    when(findIterable.iterator()).thenReturn(cursor);
    when(factory.getDb()).thenReturn(db);
    when(factory.getExceptionTranslator()).thenReturn(exceptionTranslator);
    when(db.getCollection(Mockito.any(String.class), eq(Document.class))).thenReturn(collection);
    when(db.runCommand(Mockito.any(), Mockito.any(Class.class))).thenReturn(commandResultDocument);
    when(collection.find(Mockito.any(org.bson.Document.class), any(Class.class))).thenReturn(findIterable);
    when(collection.mapReduce(Mockito.any(), Mockito.any(), eq(Document.class))).thenReturn(mapReduceIterable);
    when(collection.count(any(Bson.class), any(CountOptions.class))).thenReturn(1L);
    when(collection.aggregate(any(List.class), any())).thenReturn(aggregateIterable);
    when(collection.withReadPreference(any())).thenReturn(collection);
    when(findIterable.projection(Mockito.any())).thenReturn(findIterable);
    when(findIterable.sort(Mockito.any(org.bson.Document.class))).thenReturn(findIterable);
    when(findIterable.modifiers(Mockito.any(org.bson.Document.class))).thenReturn(findIterable);
    when(findIterable.collation(Mockito.any())).thenReturn(findIterable);
    when(findIterable.limit(anyInt())).thenReturn(findIterable);
    when(mapReduceIterable.collation(Mockito.any())).thenReturn(mapReduceIterable);
    when(mapReduceIterable.sort(Mockito.any())).thenReturn(mapReduceIterable);
    when(mapReduceIterable.iterator()).thenReturn(cursor);
    when(mapReduceIterable.filter(any())).thenReturn(mapReduceIterable);
    when(aggregateIterable.collation(any())).thenReturn(aggregateIterable);
    when(aggregateIterable.allowDiskUse(any())).thenReturn(aggregateIterable);
    when(aggregateIterable.batchSize(anyInt())).thenReturn(aggregateIterable);
    when(aggregateIterable.map(any())).thenReturn(aggregateIterable);
    when(aggregateIterable.into(any())).thenReturn(Collections.emptyList());
    this.mappingContext = new MongoMappingContext();
    this.converter = new MappingMongoConverter(new DefaultDbRefResolver(factory), mappingContext);
    this.template = new MongoTemplate(factory, converter);
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) CountOptions(com.mongodb.client.model.CountOptions) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) List(java.util.List) Document(org.bson.Document) Bson(org.bson.conversions.Bson) Before(org.junit.Before)

Example 33 with MappingMongoConverter

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

the class ReactiveMongoTemplateUnitTests method setUp.

@Before
public void setUp() {
    when(factory.getExceptionTranslator()).thenReturn(exceptionTranslator);
    when(factory.getMongoDatabase()).thenReturn(db);
    when(db.getCollection(any())).thenReturn(collection);
    when(db.getCollection(any(), any())).thenReturn(collection);
    when(db.runCommand(any(), any(Class.class))).thenReturn(runCommandPublisher);
    when(collection.find(any(Class.class))).thenReturn(findPublisher);
    when(collection.find(any(Document.class), any(Class.class))).thenReturn(findPublisher);
    when(findPublisher.projection(any())).thenReturn(findPublisher);
    when(findPublisher.limit(anyInt())).thenReturn(findPublisher);
    when(findPublisher.collation(any())).thenReturn(findPublisher);
    when(findPublisher.first()).thenReturn(findPublisher);
    this.mappingContext = new MongoMappingContext();
    this.converter = new MappingMongoConverter(new NoOpDbRefResolver(), mappingContext);
    this.template = new ReactiveMongoTemplate(factory, converter);
}
Also used : NoOpDbRefResolver(org.springframework.data.mongodb.core.ReactiveMongoTemplate.NoOpDbRefResolver) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Document(org.bson.Document) Before(org.junit.Before)

Example 34 with MappingMongoConverter

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

the class TypeBasedAggregationOperationContextUnitTests method setUp.

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

Example 35 with MappingMongoConverter

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

the class SpringDataMongodbSerializerUnitTests method setUp.

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

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