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);
}
use of org.springframework.data.mongodb.core.MongoExceptionTranslator in project spring-data-mongodb by spring-projects.
the class ReactiveMongoPersistentEntityIndexCreatorUnitTests method setUp.
@BeforeEach
@SuppressWarnings("unchecked")
void setUp() {
when(factory.getExceptionTranslator()).thenReturn(new MongoExceptionTranslator());
when(factory.getMongoDatabase()).thenReturn(Mono.just(db));
when(db.getCollection(any(), any(Class.class))).thenReturn(collection);
indexOperations = new ReactiveMongoTemplate(factory).indexOps("foo");
keysCaptor = ArgumentCaptor.forClass(org.bson.Document.class);
optionsCaptor = ArgumentCaptor.forClass(IndexOptions.class);
collectionCaptor = ArgumentCaptor.forClass(String.class);
when(collection.createIndex(keysCaptor.capture(), optionsCaptor.capture())).thenReturn(Mono.just("OK"));
}
use of org.springframework.data.mongodb.core.MongoExceptionTranslator in project spring-data-mongodb by spring-projects.
the class CursorReadingTaskUnitTests method setUp.
@BeforeEach
public void setUp() {
when(request.getRequestOptions()).thenReturn(options);
when(request.getMessageListener()).thenReturn(listener);
when(options.getCollectionName()).thenReturn("collection-name");
when(template.getDb()).thenReturn(db);
when(template.getExceptionTranslator()).thenReturn(new MongoExceptionTranslator());
when(db.getName()).thenReturn("mock-db");
task = new ValueCapturingTaskStub(template, request, Object.class, cursor, errorHandler);
}
Aggregations