Search in sources :

Example 61 with User

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

the class ModeratorServiceTest method getModeratorByIdSuccess.

@Test
public void getModeratorByIdSuccess() {
    Long userId = 1L;
    User user = new User();
    user.setId(userId);
    user.setFullName("Howard Joel Wolowitz");
    user.setRole(Role.MODERATOR);
    Moderator moderator = new Moderator();
    moderator.setUser(user);
    moderator.setWarehouseId(1L);
    when(moderatorRepoMock.findById(userId)).thenReturn(Optional.of(moderator));
    Moderator result = moderatorService.getModeratorById(userId);
    verify(moderatorRepoMock, times(1)).findById(userId);
    assertEquals(moderator, result);
}
Also used : Moderator(com.ncedu.fooddelivery.api.v1.entities.Moderator) User(com.ncedu.fooddelivery.api.v1.entities.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 62 with User

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

the class ModeratorServiceTest method getModeratorDTObyIDSuccess.

@Test
public void getModeratorDTObyIDSuccess() {
    Long userId = 1L;
    User user = new User();
    user.setId(userId);
    user.setFullName("Howard Joel Wolowitz");
    user.setRole(Role.MODERATOR);
    Moderator moderator = new Moderator();
    moderator.setUser(user);
    moderator.setWarehouseId(1L);
    when(moderatorRepoMock.findById(userId)).thenReturn(Optional.of(moderator));
    ModeratorInfoDTO resultModeratorDTO = moderatorService.getModeratorDTOById(userId);
    ModeratorInfoDTO perfectModeratorDTO = createModeratorDTO(moderator);
    verify(moderatorRepoMock, times(1)).findById(userId);
    assertEquals(perfectModeratorDTO, resultModeratorDTO);
}
Also used : Moderator(com.ncedu.fooddelivery.api.v1.entities.Moderator) User(com.ncedu.fooddelivery.api.v1.entities.User) ModeratorInfoDTO(com.ncedu.fooddelivery.api.v1.dto.user.ModeratorInfoDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 63 with User

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

the class UserServiceTest method changeEmailSuccess.

@Test
public void changeEmailSuccess() {
    Long userId = 1L;
    User howard = UserUtils.courierHowardWolowitz(userId);
    String newEmail = "happy-howard@bigbang.theory";
    User howardWithNewEmail = UserUtils.courierHowardWolowitz(userId);
    howardWithNewEmail.setEmail(newEmail);
    when(userRepoMock.findByEmail(newEmail)).thenReturn(null);
    when(userRepoMock.save(howardWithNewEmail)).thenReturn(howardWithNewEmail);
    String password = "password";
    EmailChangeDTO changeDTO = new EmailChangeDTO();
    changeDTO.setEmail(newEmail);
    changeDTO.setPassword(password);
    boolean result = userService.changeEmail(howard, changeDTO);
    assertTrue(result);
    verify(userRepoMock, times(1)).findByEmail(newEmail);
    verify(userRepoMock, times(1)).save(howardWithNewEmail);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) EmailChangeDTO(com.ncedu.fooddelivery.api.v1.dto.user.EmailChangeDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 64 with User

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

the class UserServiceTest method changeFullNameSuccess.

@Test
public void changeFullNameSuccess() {
    Long userId = 1L;
    User penny = UserUtils.clientPennyTeller(userId);
    String newFullName = "Penny Hofstadter";
    User pennyWithNewFullName = UserUtils.clientPennyTeller(userId);
    pennyWithNewFullName.setFullName(newFullName);
    when(userRepoMock.findById(userId)).thenReturn(Optional.of(penny));
    when(userRepoMock.save(pennyWithNewFullName)).thenReturn(pennyWithNewFullName);
    boolean result = userService.changeFullName(userId, newFullName);
    assertTrue(result);
    verify(userRepoMock, times(1)).findById(userId);
    verify(userRepoMock, times(1)).save(pennyWithNewFullName);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 65 with User

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

the class UserServiceTest method setLastSigninSuccess.

@Test
public void setLastSigninSuccess() {
    User howard = UserUtils.courierHowardWolowitz(1L);
    Timestamp current = new Timestamp(System.currentTimeMillis());
    howard.setLastSigninDate(current);
    when(userRepoMock.save(any(User.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
    userService.setLastSigninFromNow(howard);
    assertTrue(current.before(howard.getLastSigninDate()));
    verify(userRepoMock, times(1)).save(any());
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) 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)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