Search in sources :

Example 11 with NotFoundEx

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;
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) Client(com.ncedu.fooddelivery.api.v1.entities.Client)

Example 12 with NotFoundEx

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);
}
Also used : NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with NotFoundEx

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);
}
Also used : NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with NotFoundEx

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);
}
Also used : NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) Product(com.ncedu.fooddelivery.api.v1.entities.Product) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with NotFoundEx

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);
}
Also used : NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)20 Test (org.junit.jupiter.api.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 ProductPosition (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition)6 CustomAccessDeniedException (com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 OrderProductPosition (com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition)3 AlreadyExistsException (com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException)3 PasswordsMismatchException (com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException)3 ResponseEntity (org.springframework.http.ResponseEntity)3 WarehouseInfoDTO (com.ncedu.fooddelivery.api.v1.dto.warehouseDTOs.WarehouseInfoDTO)2 Client (com.ncedu.fooddelivery.api.v1.entities.Client)2 Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)2 BadFileExtensionException (com.ncedu.fooddelivery.api.v1.errors.badrequest.BadFileExtensionException)2 ProductAvailabilityEx (com.ncedu.fooddelivery.api.v1.errors.orderRegistration.ProductAvailabilityEx)2 WarehouseCoordsBindingEx (com.ncedu.fooddelivery.api.v1.errors.orderRegistration.WarehouseCoordsBindingEx)2 IOException (java.io.IOException)2 UserChangeInfoDTO (com.ncedu.fooddelivery.api.v1.dto.user.UserChangeInfoDTO)1 File (com.ncedu.fooddelivery.api.v1.entities.File)1 Product (com.ncedu.fooddelivery.api.v1.entities.Product)1