use of com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx in project 2021-msk-food-delivery by netcracker-edu.
the class UserDetailsServiceImpl method loadUserByUsername.
// TODO: add courier repo for finding user by phoneNumber
@Override
public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException {
User user = userRepo.findByEmail(login);
// if user not found by Email try find client/courier by phoneNumber
if (user == null) {
Client client = clientRepo.findByPhoneNumber(login);
if (client == null) {
throw new NotFoundEx(login);
}
user = client.getUser();
}
return user;
}
use of com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx in project 2021-msk-food-delivery by netcracker-edu.
the class ModeratorServiceTest method getModeratorDTObyIDNotFoundEx.
@Test
public void getModeratorDTObyIDNotFoundEx() {
Long userId = 0L;
when(moderatorRepoMock.findById(userId)).thenReturn(Optional.empty());
Exception exception = assertThrows(NotFoundEx.class, () -> {
moderatorService.getModeratorById(userId);
});
String resultMessage = exception.getMessage();
String perfectMessage = new NotFoundEx(userId.toString()).getMessage();
verify(moderatorRepoMock, times(1)).findById(userId);
assertEquals(perfectMessage, resultMessage);
}
use of com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx in project 2021-msk-food-delivery by netcracker-edu.
the class ModeratorServiceTest method getModeratorByIdNotFoundEx.
@Test
public void getModeratorByIdNotFoundEx() {
Long userId = 0L;
when(moderatorRepoMock.findById(userId)).thenReturn(Optional.empty());
Exception exception = assertThrows(NotFoundEx.class, () -> {
moderatorService.getModeratorById(userId);
});
String resultMessage = exception.getMessage();
String perfectMessage = new NotFoundEx(userId.toString()).getMessage();
verify(moderatorRepoMock, times(1)).findById(userId);
assertEquals(perfectMessage, resultMessage);
}
use of com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx in project 2021-msk-food-delivery by netcracker-edu.
the class ProductServiceTest method getProductDTOByIdInShowCaseError.
@Test
public void getProductDTOByIdInShowCaseError() {
Long productId = 1L;
Product product = ProductUtils.createMilkNOTinShowcase(productId);
when(productRepoMock.findById(productId)).thenReturn(Optional.of(product));
Exception exception = assertThrows(NotFoundEx.class, () -> {
productService.getProductDTOByIdInShowcase(productId);
});
String resultMessage = exception.getMessage();
String perfectMessage = new NotFoundEx(productId.toString()).getMessage();
verify(productRepoMock, times(1)).findById(productId);
assertEquals(perfectMessage, resultMessage);
}
use of com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx in project 2021-msk-food-delivery by netcracker-edu.
the class ClientServiceTest method getClientByIdError.
@Test
public void getClientByIdError() {
Long userId = 0L;
when(clientRepoMock.findById(userId)).thenReturn(Optional.ofNullable(null));
Exception exception = assertThrows(NotFoundEx.class, () -> {
clientService.getClientById(userId);
});
String perfectMessage = new NotFoundEx(userId.toString()).getMessage();
String resultMessage = exception.getMessage();
verify(clientRepoMock, times(1)).findById(userId);
assertEquals(perfectMessage, resultMessage);
}
Aggregations