Search in sources :

Example 36 with User

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

the class UserServiceTest method changeFullNameBad.

@Test
public void changeFullNameBad() {
    Long userId = 1L;
    User leonard = UserUtils.moderatorLeonardHofstadter(userId);
    when(userRepoMock.findById(userId)).thenReturn(Optional.of(leonard));
    boolean result = userService.changeFullName(userId, null);
    assertFalse(result);
    verify(userRepoMock, times(1)).findById(userId);
    verify(userRepoMock, never()).save(leonard);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 37 with User

use of com.laurentiuspilca.springsecurityc2.entities.User 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 38 with User

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

the class UserServiceTest method changeEmailPasswordMismatch.

@Test
public void changeEmailPasswordMismatch() {
    Long userId = 1L;
    User howard = UserUtils.courierHowardWolowitz(userId);
    String newEmail = "happy-howard@bigbang.theory";
    when(userRepoMock.findByEmail(newEmail)).thenReturn(null);
    String password = "wrong-password";
    EmailChangeDTO changeDTO = new EmailChangeDTO();
    changeDTO.setEmail(newEmail);
    changeDTO.setPassword(password);
    assertThrows(PasswordsMismatchException.class, () -> {
        userService.changeEmail(howard, changeDTO);
    });
    verify(userRepoMock, times(1)).findByEmail(newEmail);
    verify(userRepoMock, never()).save(any(User.class));
}
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 39 with User

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

the class ClientServiceImpl method changeClientInfo.

@Override
public boolean changeClientInfo(Long id, UserChangeInfoDTO newUserInfo) {
    Client client = getClientById(id);
    String newFullName = newUserInfo.getFullName();
    if (newFullName != null) {
        User user = client.getUser();
        user.setFullName(newFullName);
        client.setUser(user);
    }
    String newPhoneNumber = newUserInfo.getPhoneNumber();
    if (newPhoneNumber != null) {
        Client clientWithNewNumber = clientRepo.findByPhoneNumber(newPhoneNumber);
        if (clientWithNewNumber != null) {
            throw new AlreadyExistsException(newPhoneNumber);
        }
        client.setPhoneNumber(newPhoneNumber);
    }
    clientRepo.save(client);
    return true;
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) AlreadyExistsException(com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException) Client(com.ncedu.fooddelivery.api.v1.entities.Client)

Example 40 with User

use of com.laurentiuspilca.springsecurityc2.entities.User in project tapestry-5 by apache.

the class CachedForm method onSuccess.

@CommitAfter
void onSuccess() {
    User user = new User();
    user.setFirstName(name);
    session.save(user);
}
Also used : User(org.example.app0.entities.User) CommitAfter(org.apache.tapestry5.hibernate.annotations.CommitAfter)

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