use of com.sanctionco.thunder.dao.DatabaseException in project thunder by RohanNagar.
the class MongoDbUsersDaoTest method testUpdatePutDatabaseDown.
@Test
void testUpdatePutDatabaseDown() {
MongoCollection<Document> collection = mock(MongoCollection.class);
FindIterable<Document> findIterable = mock(FindIterable.class);
when(findIterable.first()).thenReturn(DOCUMENT);
doReturn(findIterable).when(collection).find(any(Bson.class));
doThrow(MongoTimeoutException.class).when(collection).updateOne(any(Bson.class), any(Bson.class));
MongoDbUsersDao usersDao = new MongoDbUsersDao(collection, MAPPER);
CompletionException e = assertThrows(CompletionException.class, () -> usersDao.update(null, USER).join());
assertTrue(e.getCause() instanceof DatabaseException);
var exp = (DatabaseException) e.getCause();
assertEquals(DatabaseException.Error.DATABASE_DOWN, exp.getError());
verify(collection, times(1)).find(any(Bson.class));
verify(collection, times(1)).updateOne(argThat((Bson bson) -> {
BsonDocument doc = bson.toBsonDocument(BsonDocument.class, MongoClientSettings.getDefaultCodecRegistry());
return doc.containsKey("version");
}), any(Bson.class));
}
use of com.sanctionco.thunder.dao.DatabaseException in project thunder by RohanNagar.
the class MongoDbUsersDaoTest method testFindByEmailDatabaseDown.
@Test
void testFindByEmailDatabaseDown() {
MongoCollection<Document> collection = mock(MongoCollection.class);
MongoDbUsersDao usersDao = new MongoDbUsersDao(collection, MAPPER);
doThrow(MongoTimeoutException.class).when(collection).find(any(Bson.class));
CompletionException e = assertThrows(CompletionException.class, () -> usersDao.findByEmail("test@test.com").join());
assertTrue(e.getCause() instanceof DatabaseException);
var exp = (DatabaseException) e.getCause();
assertEquals(DatabaseException.Error.DATABASE_DOWN, exp.getError());
verify(collection, times(1)).find(eq(Filters.eq("_id", "test@test.com")));
}
use of com.sanctionco.thunder.dao.DatabaseException in project thunder by RohanNagar.
the class MongoDbUsersDaoTest method testUnsuccessfulDeleteRequestRejected.
@Test
void testUnsuccessfulDeleteRequestRejected() {
MongoCollection<Document> collection = mock(MongoCollection.class);
FindIterable<Document> findIterable = mock(FindIterable.class);
MongoCommandException exception = mock(MongoCommandException.class);
when(exception.getErrorMessage()).thenReturn("Test error");
when(findIterable.first()).thenReturn(DOCUMENT);
doReturn(findIterable).when(collection).find(any(Bson.class));
doThrow(exception).when(collection).deleteOne(any(Bson.class));
MongoDbUsersDao usersDao = new MongoDbUsersDao(collection, MAPPER);
CompletionException e = assertThrows(CompletionException.class, () -> usersDao.delete("test@test.com").join());
assertTrue(e.getCause() instanceof DatabaseException);
var exp = (DatabaseException) e.getCause();
assertEquals(DatabaseException.Error.REQUEST_REJECTED, exp.getError());
verify(collection, times(1)).find(eq(Filters.eq("_id", "test@test.com")));
verify(collection, times(1)).deleteOne(eq(Filters.eq("_id", "test@test.com")));
}
use of com.sanctionco.thunder.dao.DatabaseException in project thunder by RohanNagar.
the class MongoDbUsersDaoTest method testUnsuccessfulFindByEmailEmptyItem.
@Test
void testUnsuccessfulFindByEmailEmptyItem() {
MongoCollection<Document> collection = mock(MongoCollection.class);
FindIterable<Document> findIterable = mock(FindIterable.class);
when(findIterable.first()).thenReturn(null);
doReturn(findIterable).when(collection).find(any(Bson.class));
MongoDbUsersDao usersDao = new MongoDbUsersDao(collection, MAPPER);
CompletionException e = assertThrows(CompletionException.class, () -> usersDao.findByEmail("test@test.com").join());
assertTrue(e.getCause() instanceof DatabaseException);
var exp = (DatabaseException) e.getCause();
assertEquals(DatabaseException.Error.USER_NOT_FOUND, exp.getError());
verify(collection, times(1)).find(eq(Filters.eq("_id", "test@test.com")));
}
Aggregations