use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceTest method savePngLargeHeightClient.
@Test
public void savePngLargeHeightClient() throws IOException {
// prepare
Long userId = 1L;
User rajeshClient = UserUtils.clientRajeshKoothrappali(userId);
MultipartFile file = getImgWithType("testLargeHeight", "png");
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);
verify(fileRepoMock, times(1)).save(any(File.class));
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());
// uploaded size more than income because convert from png to jpeg
assertTrue(fileSize < uploadedFileSize);
BufferedImage bufferedImage = ImageIO.read(uploadedFile.toFile());
assertEquals(CLIENT_IMAGE_HEIGHT, bufferedImage.getHeight());
}
use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceTest method saveJpegLargeHeightClient.
@Test
public void saveJpegLargeHeightClient() throws IOException {
// prepare
Long userId = 1L;
User rajeshClient = UserUtils.clientRajeshKoothrappali(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, rajeshClient);
verify(fileRepoMock, times(1)).save(any(File.class));
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());
// uploaded size less than income because convert from jpeg to jpeg with small resolution
assertTrue(fileSize > uploadedFileSize);
BufferedImage bufferedImage = ImageIO.read(uploadedFile.toFile());
assertEquals(CLIENT_IMAGE_HEIGHT, bufferedImage.getHeight());
}
use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class ModeratorServiceTest method getModeratorByIdSuccess.
@Test
public void getModeratorByIdSuccess() {
Long userId = 1L;
User user = new User();
user.setId(userId);
user.setFullName("Howard Joel Wolowitz");
user.setRole(Role.MODERATOR);
Moderator moderator = new Moderator();
moderator.setUser(user);
moderator.setWarehouseId(1L);
when(moderatorRepoMock.findById(userId)).thenReturn(Optional.of(moderator));
Moderator result = moderatorService.getModeratorById(userId);
verify(moderatorRepoMock, times(1)).findById(userId);
assertEquals(moderator, result);
}
use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class ModeratorServiceTest method getModeratorDTObyIDSuccess.
@Test
public void getModeratorDTObyIDSuccess() {
Long userId = 1L;
User user = new User();
user.setId(userId);
user.setFullName("Howard Joel Wolowitz");
user.setRole(Role.MODERATOR);
Moderator moderator = new Moderator();
moderator.setUser(user);
moderator.setWarehouseId(1L);
when(moderatorRepoMock.findById(userId)).thenReturn(Optional.of(moderator));
ModeratorInfoDTO resultModeratorDTO = moderatorService.getModeratorDTOById(userId);
ModeratorInfoDTO perfectModeratorDTO = createModeratorDTO(moderator);
verify(moderatorRepoMock, times(1)).findById(userId);
assertEquals(perfectModeratorDTO, resultModeratorDTO);
}
use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceTest method replaceCourierSuccessTest.
@Test
public void replaceCourierSuccessTest() {
User fakeUser = getFakeUserModerator();
Courier fakeCourier = getFakeCourier2();
Order fakeOrder = getFakeOrder();
Mockito.when(courierRepo.getWaitingCourierByWarehouse(1L)).thenReturn(fakeCourier);
orderService.replaceCourier(fakeOrder, fakeUser);
Assertions.assertEquals(fakeOrder.getCourier(), fakeCourier);
Mockito.verify(courierRepo, Mockito.times(1)).getWaitingCourierByWarehouse(1L);
}
Aggregations