Search in sources :

Example 46 with User

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

the class UserServiceImplTest method testCreateUser_whitebox_expectDuplicateUserException.

@Test(expected = FieldValidationException.class)
public void testCreateUser_whitebox_expectDuplicateUserException() throws Exception {
    UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
    User user = UserFactory.createNewUserTemplate();
    doThrow(new DuplicateKeyException("duplicate user")).when(fixture.getUserDao()).createUser(any(User.class));
    fixture.createUser(user);
    fail();
}
Also used : User(org.summerb.users.api.dto.User) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) Test(org.junit.Test)

Example 47 with User

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

the class UserServiceImplTest method testCreateUser_blackbox_expectAllFieldsEqualsForCreatedUser.

@Test
public void testCreateUser_blackbox_expectAllFieldsEqualsForCreatedUser() throws Exception {
    UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
    User user = UserFactory.createNewUserTemplate();
    User createdUser = fixture.createUser(user);
    // add additional test code here
    assertNotNull(createdUser);
    assertEquals(createdUser.getDisplayName(), user.getDisplayName());
    assertEquals(createdUser.getEmail(), user.getEmail());
    assertEquals(createdUser.getIntegrationData(), user.getIntegrationData());
    assertEquals(createdUser.getIsBlocked(), user.getIsBlocked());
    assertEquals(createdUser.getLocale(), user.getLocale());
    assertEquals(createdUser.getRegisteredAt(), user.getRegisteredAt());
    assertEquals(createdUser.getTimeZone(), user.getTimeZone());
}
Also used : User(org.summerb.users.api.dto.User) Test(org.junit.Test)

Example 48 with User

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

the class UserCachedTest method testGetUserByUuid_expectReferencesEqualityForReturnedDtos.

@Test
public void testGetUserByUuid_expectReferencesEqualityForReturnedDtos() throws Exception {
    User userToCreate = UserFactory.createNewUserTemplate();
    userToCreate = userService.createUser(userToCreate);
    User foundUser = userService.getUserByUuid(userToCreate.getUuid());
    User foundUserCached = userService.getUserByUuid(userToCreate.getUuid());
    assertTrue(foundUser == foundUserCached);
}
Also used : User(org.summerb.users.api.dto.User) Test(org.junit.Test)

Example 49 with User

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

the class PasswordDaoImplTest method testSetUserPassword_expectDuplicateWillBeRewrittenWithoutErrors.

@Test
public void testSetUserPassword_expectDuplicateWillBeRewrittenWithoutErrors() throws Exception {
    User createdUser = userService.createUser(UserFactory.createNewUserTemplate());
    String pwd1 = "aaaa";
    passwordService.setUserPassword(createdUser.getUuid(), pwd1);
    String pwd2 = "bbbb";
    passwordService.setUserPassword(createdUser.getUuid(), pwd2);
    boolean result = passwordService.isUserPasswordValid(createdUser.getUuid(), pwd2);
    assertTrue(result);
}
Also used : User(org.summerb.users.api.dto.User) Test(org.junit.Test)

Example 50 with User

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

the class PasswordDaoImplTest method testCreateRestorationToken_expectDuplicateWillBeRewrittenWithoutErrors.

@Test
public void testCreateRestorationToken_expectDuplicateWillBeRewrittenWithoutErrors() throws Exception {
    User createdUser = userService.createUser(UserFactory.createNewUserTemplate());
    String pwd1 = "aaaa";
    passwordService.setUserPassword(createdUser.getUuid(), pwd1);
    String restorationToken = passwordService.getNewRestorationTokenForUser(createdUser.getUuid());
    boolean result = passwordService.isRestorationTokenValid(createdUser.getUuid(), restorationToken);
    assertTrue(result);
    passwordService.deleteRestorationToken(createdUser.getUuid());
    result = passwordService.isRestorationTokenValid(createdUser.getUuid(), restorationToken);
    assertFalse(result);
}
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