Search in sources :

Example 36 with User

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

the class ProfileControllerTest method changeEmail.

@Test
public void changeEmail() {
    EmailChangeDTO emailChangeDTO = new EmailChangeDTO();
    emailChangeDTO.setEmail("wolowitz@bigbang.theory");
    emailChangeDTO.setPassword("bigBangTheory");
    User user = new User();
    user.setId(1L);
    when(userServiceMock.changeEmail(user, emailChangeDTO)).thenReturn(true);
    ResponseEntity<?> resultResponse = profileController.changeUserEmail(emailChangeDTO, user);
    ResponseEntity<?> perfectResponse = createModifyResponse(true);
    assertEquals(perfectResponse, resultResponse);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 37 with User

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

the class ProfileControllerTest method getAdminProfile.

@Test
public void getAdminProfile() {
    UserInfoDTO userInfoDTO = new UserInfoDTO(1L, "ADMIN", "admin@mail.ru");
    when(userServiceMock.getUserDTOById(1L)).thenReturn(userInfoDTO);
    User user = new User();
    user.setId(1L);
    user.setRole(Role.ADMIN);
    UserInfoDTO resultUserDTO = profileController.getProfile(user);
    assertEquals(userInfoDTO, resultUserDTO);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 38 with User

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

the class ProfileControllerTest method changePasswordMismatchError.

@Test
public void changePasswordMismatchError() {
    PasswordChangeDTO pwdChangeDTO = new PasswordChangeDTO();
    pwdChangeDTO.setOldPassword("password");
    pwdChangeDTO.setNewPassword("qwerty123");
    pwdChangeDTO.setNewPasswordConfirm("INCORRECT");
    User user = new User();
    user.setId(1L);
    when(userServiceMock.changePassword(user, pwdChangeDTO)).thenThrow(new PasswordsMismatchException());
    Exception exception = assertThrows(PasswordsMismatchException.class, () -> {
        profileController.changeUserPassword(pwdChangeDTO, user);
    });
    String resultMessage = exception.getMessage();
    String perfectMessage = new PasswordsMismatchException().getMessage();
    verify(userServiceMock, times(1)).changePassword(user, pwdChangeDTO);
    assertEquals(perfectMessage, resultMessage);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) PasswordsMismatchException(com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException) PasswordsMismatchException(com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 39 with User

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

the class ClientUtils method createClient.

private static Client createClient(Long userId, String fullName, String email, String phoneNumber) {
    User user = new User();
    user.setId(userId);
    user.setFullName(fullName);
    user.setEmail(email);
    user.setRole(Role.CLIENT);
    Client client = new Client();
    client.setPhoneNumber(phoneNumber);
    client.setUser(user);
    return client;
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Client(com.ncedu.fooddelivery.api.v1.entities.Client)

Example 40 with User

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

the class UserServiceTest method lockUserAlsoLocked.

@Test
public void lockUserAlsoLocked() {
    User penny = UserUtils.clientPennyTeller(1L);
    Timestamp current = new Timestamp(System.currentTimeMillis());
    penny.setLockDate(current);
    UserInfoDTO resultDTO = userService.lockUser(penny);
    assertEquals(current, resultDTO.getLockDate());
    verify(userRepoMock, never()).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