Search in sources :

Example 96 with User

use of com.ncedu.fooddelivery.api.v1.entities.User 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)

Example 97 with User

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

the class UserServiceImpl method deleteAvatar.

@Override
public void deleteAvatar(User user) {
    UUID avatarId = user.getAvatarId();
    if (avatarId == null) {
        return;
    }
    user.setAvatarId(null);
    userRepo.save(user);
    File avatar = fileService.getFile(avatarId);
    if (avatar != null) {
        fileService.delete(avatar, user);
    }
}
Also used : File(com.ncedu.fooddelivery.api.v1.entities.File)

Example 98 with User

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

the class ProfileControllerTest method changeClientName.

@Test
public void changeClientName() {
    UserChangeInfoDTO userChangeInfoDTO = new UserChangeInfoDTO();
    userChangeInfoDTO.setFullName("Sheldon Lee Cooper");
    Long authedUserId = 1L;
    when(clientServiceMock.changeClientInfo(authedUserId, userChangeInfoDTO)).thenReturn(true);
    User user = new User();
    user.setId(authedUserId);
    user.setRole(Role.CLIENT);
    ResponseEntity<?> resultResponse = profileController.changeUserInfo(userChangeInfoDTO, 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 99 with User

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

the class ProfileControllerTest method changePasswordSuccess.

@Test
public void changePasswordSuccess() {
    PasswordChangeDTO pwdChangeDTO = new PasswordChangeDTO();
    pwdChangeDTO.setOldPassword("password");
    pwdChangeDTO.setNewPassword("qwerty123");
    pwdChangeDTO.setNewPasswordConfirm("qwerty123");
    User user = new User();
    user.setId(1L);
    when(userServiceMock.changePassword(user, pwdChangeDTO)).thenReturn(true);
    ResponseEntity<?> resultResponse = profileController.changeUserPassword(pwdChangeDTO, user);
    ResponseEntity<?> perfectResponse = createModifyResponse(true);
    verify(userServiceMock, times(1)).changePassword(user, pwdChangeDTO);
    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 100 with User

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

the class AuthServiceImpl method signIn.

@Override
public JwtResponseDTO signIn(JwtRequestDTO authInfo, String userAgent) {
    Authentication auth = authenticate(authInfo.getLogin(), authInfo.getPassword());
    // User implements UserDetails
    User user = (User) auth.getPrincipal();
    userService.setLastSigninFromNow(user);
    log.debug("USER: " + user.getUsername() + user.getLastSigninDate());
    final String accessToken = jwtUtil.createToken(user);
    final String refreshToken = userRefreshTokenService.createRefreshToken(user, userAgent);
    return new JwtResponseDTO(accessToken, refreshToken, createUserDTO(user));
}
Also used : Authentication(org.springframework.security.core.Authentication) JwtResponseDTO(com.ncedu.fooddelivery.api.v1.dto.jwt.JwtResponseDTO)

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