use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceTest method replaceJpgToLargeHeightClient.
@Test
public void replaceJpgToLargeHeightClient() throws IOException {
// prepare
Long userId = 1L;
User pennyClient = UserUtils.clientPennyTeller(userId);
String oldImgName = "test.jpeg";
Path pathTestJpeg = UPLOAD_PATH.resolve(oldImgName);
final String fileUuid = "e9365637-bb5b-4792-9f25-ad36776fccf3";
Path fileUuidPath = createFileUuidPath(fileUuid);
Files.copy(pathTestJpeg, fileUuidPath, StandardCopyOption.REPLACE_EXISTING);
Long oldFileSize = Files.size(fileUuidPath);
File oldFileEntity = new File(UUID.fromString(fileUuid), FileType.JPEG, oldImgName, Files.size(fileUuidPath), Timestamp.valueOf(LocalDateTime.now()), pennyClient);
MultipartFile newFile = getImgWithType("testLargeHeight", "jpeg");
when(fileRepoMock.save(any(File.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
FileLinkDTO fileLinkDTO = fileService.replace(newFile, oldFileEntity, pennyClient);
assertEquals(fileUuid, fileLinkDTO.getFileUuid());
assertTrue(oldFileSize < Files.size(fileUuidPath));
BufferedImage bufferedImage = ImageIO.read(fileUuidPath.toFile());
int newImgHeight = bufferedImage.getHeight();
assertEquals(CLIENT_IMAGE_HEIGHT, newImgHeight);
verify(fileRepoMock, times(1)).save(any(File.class));
}
use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceTest method saveJpegLargeHeightAdmin.
@Test
public void saveJpegLargeHeightAdmin() throws IOException {
// prepare
Long userId = 1L;
User sheldonAdmin = UserUtils.adminSheldonCooper(userId);
MultipartFile file = getImgWithType("testLargeHeight", "jpeg");
Long fileSize = file.getSize();
log.info("FILE SIZE before uploading: " + fileSize + " FILE NAME: " + file.getName());
when(fileRepoMock.save(any(File.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
FileLinkDTO fileLinkDTO = fileService.save(file, sheldonAdmin);
Path uploadedFile = getUploadedFilePath(fileLinkDTO.getFileUuid());
assertTrue(Files.exists(uploadedFile));
Long uploadedFileSize = Files.size(uploadedFile);
log.info("FILE SIZE after uploading: " + uploadedFileSize + " FILE UUID: " + fileLinkDTO.getFileUuid());
assertEquals(fileSize, uploadedFileSize);
verify(fileRepoMock, times(1)).save(any(File.class));
}
use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceTest method saveJpegClient.
@Test
public void saveJpegClient() throws IOException {
// prepare
Long userId = 1L;
User rajeshClient = UserUtils.clientRajeshKoothrappali(userId);
MultipartFile file = getImgWithType("test", "jpeg");
Long fileSize = file.getSize();
log.info("FILE SIZE before uploading: " + fileSize + " FILE NAME: " + file.getName());
when(fileRepoMock.save(any(File.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
FileLinkDTO fileLinkDTO = fileService.save(file, rajeshClient);
Path uploadedFile = getUploadedFilePath(fileLinkDTO.getFileUuid());
assertTrue(Files.exists(uploadedFile));
Long uploadedFileSize = Files.size(uploadedFile);
log.info("FILE SIZE after uploading: " + uploadedFileSize + " FILE UUID: " + fileLinkDTO.getFileUuid());
assertEquals(fileSize, uploadedFileSize);
verify(fileRepoMock, times(1)).save(any(File.class));
}
use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceTest method deleteImgOwner.
@Test
public void deleteImgOwner() throws IOException {
// prepare
Long ownerId = 1L;
User howardOwner = UserUtils.courierHowardWolowitz(ownerId);
String imgName = "test.jpeg";
Path pathTestPng = UPLOAD_PATH.resolve(imgName);
// file name, where we locate our test.png
final String fileUuid = "24816b73-f989-4c72-89b3-67450141dafc";
Path fileUuidPath = createFileUuidPath(fileUuid);
Files.copy(pathTestPng, fileUuidPath, StandardCopyOption.REPLACE_EXISTING);
File fileEntity = new File(UUID.fromString(fileUuid), FileType.JPEG, imgName, Files.size(fileUuidPath), Timestamp.valueOf(LocalDateTime.now()), howardOwner);
doNothing().when(fileRepoMock).delete(fileEntity);
fileService.delete(fileEntity, howardOwner);
assertFalse(Files.exists(fileUuidPath));
verify(fileRepoMock, times(1)).delete(fileEntity);
}
use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceTest method replaceImgAdmin.
@Test
public void replaceImgAdmin() throws IOException {
// prepare
Long userId = 1L;
User sheldonAdmin = UserUtils.adminSheldonCooper(userId);
String oldImgName = "test.png";
int oldImgHeight = pictureNamesAndSize.get("test")[1];
Path pathTestPng = UPLOAD_PATH.resolve(oldImgName);
final String fileUuid = "7cdb597b-303e-41d2-8bcc-802ccaaa83a5";
Path fileUuidPath = createFileUuidPath(fileUuid);
Files.copy(pathTestPng, fileUuidPath, StandardCopyOption.REPLACE_EXISTING);
Long oldFileSize = Files.size(fileUuidPath);
MultipartFile newFile = getImgWithType("testLargeHeight", "jpeg");
File oldFileEntity = new File(UUID.fromString(fileUuid), FileType.PNG, oldImgName, Files.size(fileUuidPath), Timestamp.valueOf(LocalDateTime.now()), sheldonAdmin);
when(fileRepoMock.save(any(File.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
FileLinkDTO fileLinkDTO = fileService.replace(newFile, oldFileEntity, sheldonAdmin);
assertEquals(fileUuid, fileLinkDTO.getFileUuid());
assertTrue(oldFileSize < Files.size(fileUuidPath));
BufferedImage bufferedImage = ImageIO.read(fileUuidPath.toFile());
int newImgHeight = bufferedImage.getHeight();
assertTrue(oldImgHeight < newImgHeight);
verify(fileRepoMock, times(1)).save(any(File.class));
}
Aggregations