Search in sources :

Example 1 with NotFoundEx

use of com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx in project 2021-msk-food-delivery by netcracker-edu.

the class FileServiceTest method downloadNotExistentFile.

@Test
public void downloadNotExistentFile() {
    final String fileUuid = "179173a2-cf35-4191-a383-46cf1892d9c0";
    File fileEntity = new File();
    fileEntity.setId(UUID.fromString(fileUuid));
    Exception exception = assertThrows(NotFoundEx.class, () -> {
        fileService.load(fileEntity);
    });
    String perfectMessage = new NotFoundEx(fileUuid).getMessage();
    String resultMessage = exception.getMessage();
    assertEquals(perfectMessage, resultMessage);
}
Also used : NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) File(com.ncedu.fooddelivery.api.v1.entities.File) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) IOException(java.io.IOException) CustomAccessDeniedException(com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException) BadFileExtensionException(com.ncedu.fooddelivery.api.v1.errors.badrequest.BadFileExtensionException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 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 getProductByIdNotFoundEx.

@Test
public void getProductByIdNotFoundEx() {
    Long productId = 0L;
    when(productRepoMock.findById(productId)).thenReturn(Optional.empty());
    Exception exception = assertThrows(NotFoundEx.class, () -> {
        productService.getProductById(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) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 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 getProductDTOByIdNotFoundEx.

@Test
public void getProductDTOByIdNotFoundEx() {
    Long productId = 0L;
    when(productRepoMock.findById(productId)).thenReturn(Optional.empty());
    Exception exception = assertThrows(NotFoundEx.class, () -> {
        productService.getProductDTOById(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) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with NotFoundEx

use of com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method deleteUserByIdNotFound.

@Test
public void deleteUserByIdNotFound() {
    Long userId = 0L;
    when(userRepoMock.findById(userId)).thenReturn(Optional.empty());
    Exception exception = assertThrows(NotFoundEx.class, () -> {
        userService.deleteUserById(userId);
    });
    String resultMessage = exception.getMessage();
    String perfectMessage = new NotFoundEx(userId.toString()).getMessage();
    assertEquals(perfectMessage, resultMessage);
    verify(userRepoMock, times(1)).findById(userId);
    verify(userRepoMock, never()).delete(any());
}
Also used : NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) AlreadyExistsException(com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException) PasswordsMismatchException(com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with NotFoundEx

use of com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx in project 2021-msk-food-delivery by netcracker-edu.

the class FileServiceImpl method load.

@Override
public Resource load(File file) {
    try {
        Path fullFilePath = createFullPathToFile(file.getId());
        Resource resource = new UrlResource(fullFilePath.toUri());
        if (resource.exists() || resource.isReadable()) {
            return resource;
        }
        throw new NotFoundEx(file.getId().toString());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new NotFoundEx(file.getId().toString());
    }
}
Also used : Path(java.nio.file.Path) UrlResource(org.springframework.core.io.UrlResource) NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) FileStorageException(com.ncedu.fooddelivery.api.v1.errors.badrequest.FileStorageException) FileDeleteException(com.ncedu.fooddelivery.api.v1.errors.badrequest.FileDeleteException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CustomAccessDeniedException(com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException) BadFileExtensionException(com.ncedu.fooddelivery.api.v1.errors.badrequest.BadFileExtensionException)

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