use of com.baeldung.domain.User in project tutorials by eugenp.
the class UserServiceIntegrationTest method testFindNotActivatedUsersByCreationDateBefore.
@Test
public void testFindNotActivatedUsersByCreationDateBefore() {
userService.removeNotActivatedUsers();
ZonedDateTime now = ZonedDateTime.now();
List<User> users = userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(now.minusDays(3));
assertThat(users).isEmpty();
}
use of com.baeldung.domain.User in project tutorials by eugenp.
the class UserServiceIntegrationTest method assertThatUserCanResetPassword.
@Test
public void assertThatUserCanResetPassword() {
User user = userService.createUser("johndoe", "johndoe", "John", "Doe", "john.doe@localhost", "http://placehold.it/50x50", "en-US");
String oldPassword = user.getPassword();
ZonedDateTime daysAgo = ZonedDateTime.now().minusHours(2);
String resetKey = RandomUtil.generateResetKey();
user.setActivated(true);
user.setResetDate(daysAgo);
user.setResetKey(resetKey);
userRepository.save(user);
Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());
assertThat(maybeUser.isPresent()).isTrue();
assertThat(maybeUser.get().getResetDate()).isNull();
assertThat(maybeUser.get().getResetKey()).isNull();
assertThat(maybeUser.get().getPassword()).isNotEqualTo(oldPassword);
userRepository.delete(user);
}
use of com.baeldung.domain.User in project tutorials by eugenp.
the class AccountResourceIntegrationTest method testRegisterAdminIsIgnored.
@Test
@Transactional
public void testRegisterAdminIsIgnored() throws Exception {
ManagedUserVM validUser = new ManagedUserVM(// id
null, // login
"badguy", // password
"password", // firstName
"Bad", // lastName
"Guy", // e-mail
"badguy@example.com", // activated
true, // imageUrl
"http://placehold.it/50x50", // langKey
"en", // createdBy
null, // createdDate
null, // lastModifiedBy
null, // lastModifiedDate
null, new HashSet<>(Arrays.asList(AuthoritiesConstants.ADMIN)));
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(validUser))).andExpect(status().isCreated());
Optional<User> userDup = userRepository.findOneByLogin("badguy");
assertThat(userDup.isPresent()).isTrue();
assertThat(userDup.get().getAuthorities()).hasSize(1).containsExactly(authorityRepository.findOne(AuthoritiesConstants.USER));
}
use of com.baeldung.domain.User in project tutorials by eugenp.
the class AccountResourceIntegrationTest method testRegisterInvalidEmail.
@Test
@Transactional
public void testRegisterInvalidEmail() throws Exception {
ManagedUserVM invalidUser = new ManagedUserVM(// id
null, // login
"bob", // password
"password", // firstName
"Bob", // lastName
"Green", // e-mail <-- invalid
"invalid", // activated
true, // imageUrl
"http://placehold.it/50x50", // langKey
"en", // createdBy
null, // createdDate
null, // lastModifiedBy
null, // lastModifiedDate
null, new HashSet<>(Arrays.asList(AuthoritiesConstants.USER)));
restUserMockMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(invalidUser))).andExpect(status().isBadRequest());
Optional<User> user = userRepository.findOneByLogin("bob");
assertThat(user.isPresent()).isFalse();
}
use of com.baeldung.domain.User in project tutorials by eugenp.
the class AccountResourceIntegrationTest method testRegisterInvalidLogin.
@Test
@Transactional
public void testRegisterInvalidLogin() throws Exception {
ManagedUserVM invalidUser = new ManagedUserVM(// id
null, // login <-- invalid
"funky-log!n", // password
"password", // firstName
"Funky", // lastName
"One", // e-mail
"funky@example.com", // activated
true, // imageUrl
"http://placehold.it/50x50", // langKey
"en", // createdBy
null, // createdDate
null, // lastModifiedBy
null, // lastModifiedDate
null, new HashSet<>(Arrays.asList(AuthoritiesConstants.USER)));
restUserMockMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(invalidUser))).andExpect(status().isBadRequest());
Optional<User> user = userRepository.findOneByEmail("funky@example.com");
assertThat(user.isPresent()).isFalse();
}
Aggregations