use of com.laurentiuspilca.ssc6.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.laurentiuspilca.ssc6.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.laurentiuspilca.ssc6.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.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method changeEmailSuccess.
@Test
public void changeEmailSuccess() {
Long userId = 1L;
User howard = UserUtils.courierHowardWolowitz(userId);
String newEmail = "happy-howard@bigbang.theory";
User howardWithNewEmail = UserUtils.courierHowardWolowitz(userId);
howardWithNewEmail.setEmail(newEmail);
when(userRepoMock.findByEmail(newEmail)).thenReturn(null);
when(userRepoMock.save(howardWithNewEmail)).thenReturn(howardWithNewEmail);
String password = "password";
EmailChangeDTO changeDTO = new EmailChangeDTO();
changeDTO.setEmail(newEmail);
changeDTO.setPassword(password);
boolean result = userService.changeEmail(howard, changeDTO);
assertTrue(result);
verify(userRepoMock, times(1)).findByEmail(newEmail);
verify(userRepoMock, times(1)).save(howardWithNewEmail);
}
use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method changeFullNameSuccess.
@Test
public void changeFullNameSuccess() {
Long userId = 1L;
User penny = UserUtils.clientPennyTeller(userId);
String newFullName = "Penny Hofstadter";
User pennyWithNewFullName = UserUtils.clientPennyTeller(userId);
pennyWithNewFullName.setFullName(newFullName);
when(userRepoMock.findById(userId)).thenReturn(Optional.of(penny));
when(userRepoMock.save(pennyWithNewFullName)).thenReturn(pennyWithNewFullName);
boolean result = userService.changeFullName(userId, newFullName);
assertTrue(result);
verify(userRepoMock, times(1)).findById(userId);
verify(userRepoMock, times(1)).save(pennyWithNewFullName);
}
Aggregations