Search in sources :

Example 86 with User

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());
}
Also used : Path(java.nio.file.Path) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) User(com.ncedu.fooddelivery.api.v1.entities.User) File(com.ncedu.fooddelivery.api.v1.entities.File) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) FileLinkDTO(com.ncedu.fooddelivery.api.v1.dto.file.FileLinkDTO) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 87 with User

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());
}
Also used : Path(java.nio.file.Path) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) User(com.ncedu.fooddelivery.api.v1.entities.User) File(com.ncedu.fooddelivery.api.v1.entities.File) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) FileLinkDTO(com.ncedu.fooddelivery.api.v1.dto.file.FileLinkDTO) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 88 with User

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);
}
Also used : Moderator(com.ncedu.fooddelivery.api.v1.entities.Moderator) User(com.ncedu.fooddelivery.api.v1.entities.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 89 with User

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);
}
Also used : Moderator(com.ncedu.fooddelivery.api.v1.entities.Moderator) User(com.ncedu.fooddelivery.api.v1.entities.User) ModeratorInfoDTO(com.ncedu.fooddelivery.api.v1.dto.user.ModeratorInfoDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 90 with User

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);
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

User (com.ncedu.fooddelivery.api.v1.entities.User)58 Test (org.junit.jupiter.api.Test)55 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)55 File (com.ncedu.fooddelivery.api.v1.entities.File)21 Path (java.nio.file.Path)19 MultipartFile (org.springframework.web.multipart.MultipartFile)19 CustomAccessDeniedException (com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)18 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)18 FileLinkDTO (com.ncedu.fooddelivery.api.v1.dto.file.FileLinkDTO)15 Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)14 BufferedImage (java.awt.image.BufferedImage)10 UserInfoDTO (com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO)9 Role (com.ncedu.fooddelivery.api.v1.entities.Role)7 NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)7 IOException (java.io.IOException)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 ProductPosition (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition)6 AlreadyExistsException (com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException)6 PasswordsMismatchException (com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException)6 CommitAfter (org.apache.tapestry5.jpa.annotations.CommitAfter)6