Search in sources :

Example 1 with MongoExceptionTranslator

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

the class MongoTransactionManagerUnitTests method setUp.

@BeforeEach
void setUp() {
    when(dbFactory.getSession(any())).thenReturn(session, session2);
    when(dbFactory.getExceptionTranslator()).thenReturn(new MongoExceptionTranslator());
    when(dbFactory2.getExceptionTranslator()).thenReturn(new MongoExceptionTranslator());
    when(dbFactory.withSession(session)).thenReturn(dbFactory);
    when(dbFactory.getMongoDatabase()).thenReturn(db);
    when(session.getServerSession()).thenReturn(serverSession);
}
Also used : MongoExceptionTranslator(org.springframework.data.mongodb.core.MongoExceptionTranslator) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with MongoExceptionTranslator

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

the class DefaultDbRefResolverUnitTests method setUp.

@BeforeEach
void setUp() {
    when(factoryMock.getMongoDatabase()).thenReturn(dbMock);
    when(factoryMock.getExceptionTranslator()).thenReturn(new MongoExceptionTranslator());
    when(dbMock.getCollection(anyString(), any(Class.class))).thenReturn(collectionMock);
    when(collectionMock.find(any(Document.class))).thenReturn(cursorMock);
    resolver = new DefaultDbRefResolver(factoryMock);
}
Also used : Document(org.bson.Document) MongoExceptionTranslator(org.springframework.data.mongodb.core.MongoExceptionTranslator) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with MongoExceptionTranslator

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

the class DbRefMappingMongoConverterUnitTests method setUp.

@BeforeEach
void setUp() {
    when(dbFactory.getExceptionTranslator()).thenReturn(new MongoExceptionTranslator());
    this.dbRefResolver = spy(new DefaultDbRefResolver(dbFactory));
    this.mappingContext = new MongoMappingContext();
    this.mappingContext.setSimpleTypeHolder(new MongoCustomConversions(Collections.emptyList()).getSimpleTypeHolder());
    this.converter = new MappingMongoConverter(dbRefResolver, mappingContext);
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MongoExceptionTranslator(org.springframework.data.mongodb.core.MongoExceptionTranslator) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with MongoExceptionTranslator

use of org.springframework.data.mongodb.core.MongoExceptionTranslator 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 5 with MongoExceptionTranslator

use of org.springframework.data.mongodb.core.MongoExceptionTranslator 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)

Aggregations

BeforeEach (org.junit.jupiter.api.BeforeEach)8 MongoExceptionTranslator (org.springframework.data.mongodb.core.MongoExceptionTranslator)8 IndexOptions (com.mongodb.client.model.IndexOptions)2 DefaultDbRefResolver (org.springframework.data.mongodb.core.convert.DefaultDbRefResolver)2 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)2 Document (org.springframework.data.mongodb.core.mapping.Document)2 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)2 Document (org.bson.Document)1 MongoDatabaseFactory (org.springframework.data.mongodb.MongoDatabaseFactory)1 FindWithQuery (org.springframework.data.mongodb.core.ExecutableFindOperation.FindWithQuery)1 UpdateWithQuery (org.springframework.data.mongodb.core.ExecutableUpdateOperation.UpdateWithQuery)1 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)1 ReactiveMongoTemplate (org.springframework.data.mongodb.core.ReactiveMongoTemplate)1 DbRefResolver (org.springframework.data.mongodb.core.convert.DbRefResolver)1 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)1 Query (org.springframework.data.mongodb.core.query.Query)1 UpdateDefinition (org.springframework.data.mongodb.core.query.UpdateDefinition)1