use of com.baeldung.domain.User in project tutorials by eugenp.
the class UserServiceIntegrationTest method assertThatOnlyActivatedUserCanRequestPasswordReset.
@Test
public void assertThatOnlyActivatedUserCanRequestPasswordReset() {
User user = userService.createUser("johndoe", "johndoe", "John", "Doe", "john.doe@localhost", "http://placehold.it/50x50", "en-US");
Optional<User> maybeUser = userService.requestPasswordReset("john.doe@localhost");
assertThat(maybeUser.isPresent()).isFalse();
userRepository.delete(user);
}
use of com.baeldung.domain.User in project tutorials by eugenp.
the class UserServiceIntegrationTest method assertThatResetKeyMustNotBeOlderThan24Hours.
@Test
public void assertThatResetKeyMustNotBeOlderThan24Hours() {
User user = userService.createUser("johndoe", "johndoe", "John", "Doe", "john.doe@localhost", "http://placehold.it/50x50", "en-US");
ZonedDateTime daysAgo = ZonedDateTime.now().minusHours(25);
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()).isFalse();
userRepository.delete(user);
}
use of com.baeldung.domain.User in project tutorials by eugenp.
the class AccountResourceIntegrationTest method testGetExistingAccount.
@Test
public void testGetExistingAccount() throws Exception {
Set<Authority> authorities = new HashSet<>();
Authority authority = new Authority();
authority.setName(AuthoritiesConstants.ADMIN);
authorities.add(authority);
User user = new User();
user.setLogin("test");
user.setFirstName("john");
user.setLastName("doe");
user.setEmail("john.doe@jhipster.com");
user.setImageUrl("http://placehold.it/50x50");
user.setAuthorities(authorities);
when(mockUserService.getUserWithAuthorities()).thenReturn(user);
restUserMockMvc.perform(get("/api/account").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.login").value("test")).andExpect(jsonPath("$.firstName").value("john")).andExpect(jsonPath("$.lastName").value("doe")).andExpect(jsonPath("$.email").value("john.doe@jhipster.com")).andExpect(jsonPath("$.imageUrl").value("http://placehold.it/50x50")).andExpect(jsonPath("$.authorities").value(AuthoritiesConstants.ADMIN));
}
use of com.baeldung.domain.User in project tutorials by eugenp.
the class AccountResourceIntegrationTest method testRegisterDuplicateLogin.
@Test
@Transactional
public void testRegisterDuplicateLogin() throws Exception {
// Good
ManagedUserVM validUser = new ManagedUserVM(// id
null, // login
"alice", // password
"password", // firstName
"Alice", // lastName
"Something", // e-mail
"alice@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)));
// Duplicate login, different e-mail
ManagedUserVM duplicatedUser = new ManagedUserVM(validUser.getId(), validUser.getLogin(), validUser.getPassword(), validUser.getLogin(), validUser.getLastName(), "alicejr@example.com", true, validUser.getImageUrl(), validUser.getLangKey(), validUser.getCreatedBy(), validUser.getCreatedDate(), validUser.getLastModifiedBy(), validUser.getLastModifiedDate(), validUser.getAuthorities());
// Good user
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(validUser))).andExpect(status().isCreated());
// Duplicate login
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(duplicatedUser))).andExpect(status().is4xxClientError());
Optional<User> userDup = userRepository.findOneByEmail("alicejr@example.com");
assertThat(userDup.isPresent()).isFalse();
}
use of com.baeldung.domain.User in project tutorials by eugenp.
the class AccountResourceIntegrationTest method testSaveInvalidLogin.
@Test
@Transactional
public void testSaveInvalidLogin() throws Exception {
UserDTO invalidUser = new UserDTO(// id
null, // login <-- invalid
"funky-log!n", // 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/account").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