Search in sources :

Example 41 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class UserDaoImplTest method testFindUsersByDisplayNamePartial_expectCorrectSorting.

@Test
public // @Rollback(false)
void testFindUsersByDisplayNamePartial_expectCorrectSorting() throws Exception {
    User user = UserFactory.createNewUserTemplate();
    user.setDisplayName("ooUHapqoiwez");
    user.setEmail("email2@aaa.ru");
    userService.createUser(user);
    user = UserFactory.createNewUserTemplate();
    user.setDisplayName("oooUHapqoiwez");
    user.setEmail("email3@aaa.ru");
    userService.createUser(user);
    user = UserFactory.createNewUserTemplate();
    user.setDisplayName("oUHapqoiwez");
    user.setEmail("email1@aaa.ru");
    userService.createUser(user);
    PaginatedList<User> results = userService.findUsersByDisplayNamePartial("UHapqoiwez", new PagerParams());
    assertNotNull(results);
    List<User> items = results.getItems();
    assertNotNull(items);
    assertTrue(items.size() == 3);
    assertTrue(results.getTotalResults() == 3);
    assertEquals("email1@aaa.ru", items.get(0).getEmail());
    assertEquals("email2@aaa.ru", items.get(1).getEmail());
    assertEquals("email3@aaa.ru", items.get(2).getEmail());
}
Also used : User(org.summerb.users.api.dto.User) PagerParams(org.summerb.easycrud.api.dto.PagerParams) Test(org.junit.Test)

Example 42 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class AuthTokenServiceImpl method validateAndGetUser.

private User validateAndGetUser(String userEmail, String passwordPlain) throws UserNotFoundException, FieldValidationException, InvalidPasswordException {
    try {
        User user = userService.getUserByEmail(userEmail);
        boolean isPasswordValid = passwordService.isUserPasswordValid(user.getUuid(), passwordPlain);
        if (!isPasswordValid) {
            throw new InvalidPasswordException();
        }
        return user;
    } catch (Throwable t) {
        Throwables.throwIfInstanceOf(t, UserNotFoundException.class);
        Throwables.throwIfInstanceOf(t, FieldValidationException.class);
        Throwables.throwIfInstanceOf(t, InvalidPasswordException.class);
        String msg = String.format("Failed to validate user '%s' and password '%s'", userEmail, passwordPlain);
        throw new UserServiceUnexpectedException(msg, t);
    }
}
Also used : UserNotFoundException(org.summerb.users.api.exceptions.UserNotFoundException) FieldValidationException(org.summerb.validation.FieldValidationException) User(org.summerb.users.api.dto.User) UserServiceUnexpectedException(org.summerb.users.api.exceptions.UserServiceUnexpectedException) InvalidPasswordException(org.summerb.users.api.exceptions.InvalidPasswordException)

Example 43 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class UserServiceImplTest method testCreateUser_blackbox_expectValidationExceptionOnInvalidEmail.

@Test(expected = FieldValidationException.class)
public void testCreateUser_blackbox_expectValidationExceptionOnInvalidEmail() throws Exception {
    UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
    User user = UserFactory.createNewUserTemplate();
    user.setEmail("abara-cadabara");
    fixture.createUser(user);
    fail();
}
Also used : User(org.summerb.users.api.dto.User) Test(org.junit.Test)

Example 44 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class UserServiceImplTest method testCreateUser_blackbox_expectRegisteredAtWillBePopulated.

@Test
public void testCreateUser_blackbox_expectRegisteredAtWillBePopulated() throws Exception {
    UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
    User user = UserFactory.createNewUserTemplate();
    user.setRegisteredAt(0);
    User createdUser = fixture.createUser(user);
    // add additional test code here
    assertNotNull(createdUser);
    assertTrue(createdUser.getRegisteredAt() != 0L);
}
Also used : User(org.summerb.users.api.dto.User) Test(org.junit.Test)

Example 45 with User

use of org.summerb.users.api.dto.User in project summerb by skarpushin.

the class UserServiceImplTest method testUpdateUser_blackbox_fveOnFailedValidation.

@Test(expected = FieldValidationException.class)
public void testUpdateUser_blackbox_fveOnFailedValidation() throws Exception {
    UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
    User user = UserFactory.createExistingUser();
    user.setEmail("asdasd");
    when(fixture.getUserDao().updateUser(any(User.class))).thenReturn(true);
    fixture.updateUser(user);
    fail();
}
Also used : User(org.summerb.users.api.dto.User) Test(org.junit.Test)

Aggregations

User (org.summerb.users.api.dto.User)61 Test (org.junit.Test)33 UserNotFoundException (org.summerb.users.api.exceptions.UserNotFoundException)13 AuthToken (org.summerb.users.api.dto.AuthToken)11 UserServiceUnexpectedException (org.summerb.users.api.exceptions.UserServiceUnexpectedException)11 FieldValidationException (org.summerb.validation.FieldValidationException)11 Transactional (org.springframework.transaction.annotation.Transactional)8 Date (java.util.Date)4 PagerParams (org.summerb.easycrud.api.dto.PagerParams)4 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 InvalidPasswordException (org.summerb.users.api.exceptions.InvalidPasswordException)3 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 GenericException (org.summerb.utils.exceptions.GenericException)2 ValidationContext (org.summerb.validation.ValidationContext)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 EventBus (com.google.common.eventbus.EventBus)1 Locale (java.util.Locale)1 Secured (org.springframework.security.access.annotation.Secured)1 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)1