Search in sources :

Example 21 with DefaultDbRefResolver

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

the class SpelExpressionTransformerIntegrationTests method setUp.

@Before
public void setUp() {
    this.transformer = new SpelExpressionTransformer();
    this.dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);
}
Also used : DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) Before(org.junit.Before)

Example 22 with DefaultDbRefResolver

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

the class ConvertingParameterAccessorUnitTests method setUp.

@BeforeEach
void setUp() {
    when(factory.getExceptionTranslator()).thenReturn(new MongoExceptionTranslator());
    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) MongoExceptionTranslator(org.springframework.data.mongodb.core.MongoExceptionTranslator) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 23 with DefaultDbRefResolver

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

the class AbstractMongoQueryUnitTests method setUp.

@BeforeEach
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();
    MongoDatabaseFactory mongoDbFactory = mock(MongoDatabaseFactory.class);
    when(mongoDbFactory.getExceptionTranslator()).thenReturn(new MongoExceptionTranslator());
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);
    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(Query.class));
    doReturn(executableUpdate).when(mongoOperationsMock).update(any());
    doReturn(updateWithQuery).when(executableUpdate).matching(any(Query.class));
    doReturn(terminatingUpdate).when(updateWithQuery).apply(any(UpdateDefinition.class));
    when(mongoOperationsMock.remove(any(), any(), anyString())).thenReturn(deleteResultMock);
    when(mongoOperationsMock.updateMulti(any(), any(), any(), anyString())).thenReturn(updateResultMock);
}
Also used : BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) FindWithQuery(org.springframework.data.mongodb.core.ExecutableFindOperation.FindWithQuery) UpdateWithQuery(org.springframework.data.mongodb.core.ExecutableUpdateOperation.UpdateWithQuery) Query(org.springframework.data.mongodb.core.query.Query) UpdateDefinition(org.springframework.data.mongodb.core.query.UpdateDefinition) MongoDatabaseFactory(org.springframework.data.mongodb.MongoDatabaseFactory) 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) MongoExceptionTranslator(org.springframework.data.mongodb.core.MongoExceptionTranslator) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with DefaultDbRefResolver

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

the class PerformanceTests method setUp.

@BeforeEach
public void setUp() throws Exception {
    this.mongo = MongoClients.create();
    SimpleMongoClientDatabaseFactory mongoDbFactory = new SimpleMongoClientDatabaseFactory(this.mongo, DATABASE_NAME);
    MongoMappingContext context = new MongoMappingContext();
    context.setInitialEntitySet(Collections.singleton(Person.class));
    context.afterPropertiesSet();
    this.converter = new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory), context);
    this.operations = new MongoTemplate(new SimpleMongoClientDatabaseFactory(this.mongo, DATABASE_NAME), converter);
    MongoRepositoryFactoryBean<PersonRepository, Person, ObjectId> factory = new MongoRepositoryFactoryBean<PersonRepository, Person, ObjectId>(PersonRepository.class);
    factory.setMongoOperations(operations);
    factory.afterPropertiesSet();
    this.repository = factory.getObject();
}
Also used : ObjectId(org.bson.types.ObjectId) MongoRepositoryFactoryBean(org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) SimpleMongoClientDatabaseFactory(org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 25 with DefaultDbRefResolver

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

the class MongoTestTemplateConfiguration method mongoConverter.

MongoConverter mongoConverter() {
    if (converter == null) {
        converter = new MappingMongoConverter(new DefaultDbRefResolver(databaseFactory()), mappingContext());
        if (mongoConverterConfigurer.customConversions != null) {
            converter.setCustomConversions(mongoConverterConfigurer.customConversions);
        }
        converter.afterPropertiesSet();
    }
    return converter;
}
Also used : DefaultDbRefResolver(org.springframework.data.mongodb.core.convert.DefaultDbRefResolver) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter)

Aggregations

DefaultDbRefResolver (org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)25 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)24 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)14 DbRefResolver (org.springframework.data.mongodb.core.convert.DbRefResolver)12 MongoCustomConversions (org.springframework.data.mongodb.core.convert.MongoCustomConversions)7 Bean (org.springframework.context.annotation.Bean)6 Before (org.junit.Before)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Document (org.bson.Document)3 Bson (org.bson.conversions.Bson)3 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)3 ClientSession (com.mongodb.client.ClientSession)2 CountOptions (com.mongodb.client.model.CountOptions)2 List (java.util.List)2 MongoDatabaseFactory (org.springframework.data.mongodb.MongoDatabaseFactory)2 MongoExceptionTranslator (org.springframework.data.mongodb.core.MongoExceptionTranslator)2 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)2 Query (org.springframework.data.mongodb.core.query.Query)2 UpdateDefinition (org.springframework.data.mongodb.core.query.UpdateDefinition)2 ReportPortalRepositoryFactoryBean (com.epam.ta.reportportal.database.dao.ReportPortalRepositoryFactoryBean)1