Search in sources :

Example 31 with User

use of com.laurentiuspilca.ssc6.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)

Example 32 with User

use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method searchUsersSuccess.

@Test
public void searchUsersSuccess() {
    User sheldonCooper = UserUtils.adminSheldonCooper(1L);
    List<User> users = new ArrayList<>();
    users.add(sheldonCooper);
    Page<User> userPage = new PageImpl<>(users);
    Pageable pageable = PageRequest.of(0, 2);
    String searchPhrase = "sh co";
    String resultSearchPhrase = "sh:* & co:*";
    when(userRepoMock.searchUsers(resultSearchPhrase, pageable)).thenReturn(userPage);
    List<UserInfoDTO> resultDTO = userService.searchUsers(searchPhrase, pageable);
    List<UserInfoDTO> perfectDTO = new ArrayList<>();
    perfectDTO.add(UserUtils.createUserDTO(sheldonCooper));
    assertEquals(perfectDTO, resultDTO);
    verify(userRepoMock, times(1)).searchUsers(resultSearchPhrase, pageable);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) User(com.ncedu.fooddelivery.api.v1.entities.User) Pageable(org.springframework.data.domain.Pageable) ArrayList(java.util.ArrayList) UserInfoDTO(com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 33 with User

use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method changePasswordNewPassNotSame.

@Test
public void changePasswordNewPassNotSame() {
    Long userId = 1L;
    User rajesh = UserUtils.clientRajeshKoothrappali(userId);
    String oldPass = "password";
    String newPass = "koothrappali";
    String newPass2 = "wrongNewPass";
    PasswordChangeDTO passwordDTO = new PasswordChangeDTO();
    passwordDTO.setNewPassword(newPass);
    passwordDTO.setNewPasswordConfirm(newPass2);
    passwordDTO.setOldPassword(oldPass);
    Exception exception = assertThrows(PasswordsMismatchException.class, () -> {
        userService.changePassword(rajesh, passwordDTO);
    });
    verify(userRepoMock, never()).save(any(User.class));
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) PasswordChangeDTO(com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO) AlreadyExistsException(com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException) PasswordsMismatchException(com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 34 with User

use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method deleteUserByIdSuccess.

@Test
public void deleteUserByIdSuccess() {
    Long userId = 1L;
    User rajesh = UserUtils.clientRajeshKoothrappali(userId);
    when(userRepoMock.findById(userId)).thenReturn(Optional.of(rajesh));
    doNothing().when(userRepoMock).delete(rajesh);
    boolean result = userService.deleteUserById(userId);
    assertTrue(result);
    verify(userRepoMock, times(1)).findById(userId);
    verify(userRepoMock, times(1)).delete(rajesh);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 35 with User

use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method getAllUsersSuccess.

@Test
public void getAllUsersSuccess() {
    User penny = UserUtils.clientPennyTeller(1L);
    User leonard = UserUtils.moderatorLeonardHofstadter(2L);
    List<User> users = new ArrayList<>();
    users.add(penny);
    users.add(leonard);
    Page<User> userPage = new PageImpl<>(users);
    Pageable pageable = PageRequest.of(0, 2);
    when(userRepoMock.findAll(pageable)).thenReturn(userPage);
    List<UserInfoDTO> resultDTO = userService.getAllUsers(pageable);
    List<UserInfoDTO> perfectDTO = users.stream().map(user -> UserUtils.createUserDTO(user)).collect(Collectors.toList());
    assertEquals(perfectDTO, resultDTO);
    verify(userRepoMock, times(1)).findAll(pageable);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) AlreadyExistsException(com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException) User(com.ncedu.fooddelivery.api.v1.entities.User) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayList(java.util.ArrayList) PasswordsMismatchException(com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException) NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) Role(com.ncedu.fooddelivery.api.v1.entities.Role) Pageable(org.springframework.data.domain.Pageable) MockBean(org.springframework.boot.test.mock.mockito.MockBean) UserInfoDTO(com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO) Timestamp(java.sql.Timestamp) EmailChangeDTO(com.ncedu.fooddelivery.api.v1.dto.user.EmailChangeDTO) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) UserRepo(com.ncedu.fooddelivery.api.v1.repos.UserRepo) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) PasswordChangeDTO(com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) PageImpl(org.springframework.data.domain.PageImpl) User(com.ncedu.fooddelivery.api.v1.entities.User) Pageable(org.springframework.data.domain.Pageable) ArrayList(java.util.ArrayList) UserInfoDTO(com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO) 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)49 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)49 File (com.ncedu.fooddelivery.api.v1.entities.File)18 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)18 MultipartFile (org.springframework.web.multipart.MultipartFile)18 Path (java.nio.file.Path)16 FileLinkDTO (com.ncedu.fooddelivery.api.v1.dto.file.FileLinkDTO)12 UserInfoDTO (com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO)9 BufferedImage (java.awt.image.BufferedImage)8 CommitAfter (org.apache.tapestry5.jpa.annotations.CommitAfter)7 AlreadyExistsException (com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException)6 PasswordsMismatchException (com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException)6 PersistenceContext (javax.persistence.PersistenceContext)6 User (org.example.app0.entities.User)6 User (org.example.app1.entities.User)6 User (org.example.app6.entities.User)5 EmailChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.EmailChangeDTO)4 PasswordChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO)4 IOException (java.io.IOException)4