use of org.summerb.microservices.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();
}
use of org.summerb.microservices.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);
}
use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.
the class UserServiceImplTest method testCreateUser_blackbox_expectGuidWillBeCreatedForTheUser.
@Test
public void testCreateUser_blackbox_expectGuidWillBeCreatedForTheUser() throws Exception {
UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
User result = fixture.createUser(UserFactory.createNewUserTemplate());
// add additional test code here
assertNotNull(result);
assertNotNull(result.getUuid());
}
use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.
the class AuthTokenServiceImpl method createAuthToken.
@Override
@Transactional(rollbackFor = Throwable.class)
public AuthToken createAuthToken(String userEmail, String clientIp, String tokenUuid, String tokenValueUuid) throws UserNotFoundException, FieldValidationException {
Preconditions.checkArgument(userEmail != null);
Preconditions.checkArgument(clientIp != null);
Preconditions.checkArgument(StringUtils.hasText(tokenUuid));
Preconditions.checkArgument(StringUtils.hasText(tokenValueUuid));
try {
User user = userService.getUserByEmail(userEmail);
AuthToken authToken = buildNewAuthToken(user, clientIp, tokenUuid, tokenValueUuid);
authTokenDao.createAuthToken(authToken);
return authToken;
} catch (Throwable t) {
Throwables.throwIfInstanceOf(t, UserNotFoundException.class);
Throwables.throwIfInstanceOf(t, FieldValidationException.class);
String msg = String.format("Failed to create auth otken for user '%s'", userEmail);
throw new UserServiceUnexpectedException(msg, t);
}
}
use of org.summerb.microservices.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);
}
}
Aggregations