Search in sources :

Example 16 with User

use of com.laurentiuspilca.ssc6.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 17 with User

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

Example 18 with User

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

the class UserServiceTest method getUserDTOByIdSuccess.

@Test
public void getUserDTOByIdSuccess() {
    Long userId = 1L;
    User sheldonCooper = UserUtils.adminSheldonCooper(userId);
    when(userRepoMock.findById(userId)).thenReturn(Optional.of(sheldonCooper));
    UserInfoDTO resultDTO = userService.getUserDTOById(userId);
    UserInfoDTO perfectDTO = UserUtils.createUserDTO(sheldonCooper);
    assertEquals(perfectDTO, resultDTO);
    verify(userRepoMock, times(1)).findById(userId);
}
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 19 with User

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

the class UserServiceTest method changePasswordSuccess.

@Test
public void changePasswordSuccess() {
    Long userId = 1L;
    User rajesh = UserUtils.clientRajeshKoothrappali(userId);
    String oldPass = "password";
    String newPass = "koothrappali";
    PasswordChangeDTO passwordDTO = new PasswordChangeDTO();
    passwordDTO.setNewPassword(newPass);
    passwordDTO.setNewPasswordConfirm(newPass);
    passwordDTO.setOldPassword(oldPass);
    when(userRepoMock.save(any(User.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
    boolean result = userService.changePassword(rajesh, passwordDTO);
    assertTrue(result);
    verify(userRepoMock, times(1)).save(any(User.class));
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) PasswordChangeDTO(com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with User

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

the class UserServiceImpl method deleteUserById.

@Override
public boolean deleteUserById(Long id) {
    User userForDelete = getUserById(id);
    userRepo.delete(userForDelete);
    return true;
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User)

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