Search in sources :

Example 16 with User

use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class OrderServiceTest method replaceCourierReplaceExTest.

@Test
public void replaceCourierReplaceExTest() {
    User fakeUser = getFakeUserModerator();
    Courier mockCourier = Mockito.mock(Courier.class);
    Order fakeOrder = getFakeOrder();
    fakeOrder.setStatus(OrderStatus.DELIVERED);
    Assertions.assertThrows(CourierReplaceException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            orderService.replaceCourier(fakeOrder, fakeUser);
        }
    });
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with User

use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class OrderServiceTest method changeCourierRatingCourierNotSetTest.

@Test
public void changeCourierRatingCourierNotSetTest() {
    User fakeUser = getFakeUserClient();
    ChangeRatingDTO fakeDto = new ChangeRatingDTO();
    Order fakeOrder = getFakeOrder();
    fakeOrder.setCourier(null);
    Assertions.assertThrows(CourierNotSetException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            orderService.changeDeliveryRating(fakeOrder, fakeDto, fakeUser);
        }
    });
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) ChangeRatingDTO(com.ncedu.fooddelivery.api.v1.dto.order.ChangeRatingDTO) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with User

use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class OrderServiceTest method changeCourierRatingSuccessTest.

@Test
public void changeCourierRatingSuccessTest() {
    User fakeUser = getFakeUserClient();
    ChangeRatingDTO fakeDto = new ChangeRatingDTO();
    fakeDto.setRating(new BigDecimal(4.5));
    Order fakeOrder = getFakeOrder();
    Mockito.when(orderRepo.save(Mockito.any(Order.class))).thenReturn(fakeOrder);
    orderService.changeDeliveryRating(fakeOrder, fakeDto, fakeUser);
    Assertions.assertTrue(fakeOrder.getDeliveryRating().equals(new BigDecimal(4.5)));
    Mockito.verify(orderRepo, Mockito.times(1)).save(fakeOrder);
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) ChangeRatingDTO(com.ncedu.fooddelivery.api.v1.dto.order.ChangeRatingDTO) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with User

use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method getUserByIdSuccess.

@Test
public void getUserByIdSuccess() {
    Long userId = 1L;
    User sheldonCooper = UserUtils.adminSheldonCooper(userId);
    when(userRepoMock.findById(userId)).thenReturn(Optional.of(sheldonCooper));
    User result = userService.getUserById(userId);
    assertEquals(sheldonCooper, result);
    verify(userRepoMock, times(1)).findById(userId);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with User

use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method unlockUserSuccess.

@Test
public void unlockUserSuccess() {
    User penny = UserUtils.clientPennyTeller(1L);
    Timestamp current = new Timestamp(System.currentTimeMillis());
    penny.setLockDate(current);
    UserInfoDTO resultDTO = userService.unlockUser(penny);
    assertEquals(null, resultDTO.getLockDate());
    verify(userRepoMock, times(1)).save(any(User.class));
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) UserInfoDTO(com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO) Timestamp(java.sql.Timestamp) 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