Search in sources :

Example 6 with UserInfoDTO

use of com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO 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 7 with UserInfoDTO

use of com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO 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 8 with UserInfoDTO

use of com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO 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)

Example 9 with UserInfoDTO

use of com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method lockUserSuccess.

@Test
public void lockUserSuccess() {
    User penny = UserUtils.clientPennyTeller(1L);
    when(userRepoMock.save(any(User.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
    UserInfoDTO resultDTO = userService.lockUser(penny);
    assertTrue(resultDTO.getLockDate() != null);
    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) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with UserInfoDTO

use of com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method unlockUserAlsoUnlocked.

@Test
public void unlockUserAlsoUnlocked() {
    User penny = UserUtils.clientPennyTeller(1L);
    penny.setLockDate(null);
    UserInfoDTO resultDTO = userService.unlockUser(penny);
    assertEquals(null, 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) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

User (com.ncedu.fooddelivery.api.v1.entities.User)12 Test (org.junit.jupiter.api.Test)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 UserInfoDTO (com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO)9 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 Role (com.ncedu.fooddelivery.api.v1.entities.Role)2 PageImpl (org.springframework.data.domain.PageImpl)2 Pageable (org.springframework.data.domain.Pageable)2 EmailChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.EmailChangeDTO)1 PasswordChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO)1 File (com.ncedu.fooddelivery.api.v1.entities.File)1 AlreadyExistsException (com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException)1 PasswordsMismatchException (com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException)1 NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)1 UserRepo (com.ncedu.fooddelivery.api.v1.repos.UserRepo)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1