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);
}
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);
}
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);
}
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());
}
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());
}
}
Aggregations