Search in sources :

Example 51 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-websocket by jhipster.

the class UserServiceIntTest method assertThatResetKeyMustBeValid.

@Test
@Transactional
public void assertThatResetKeyMustBeValid() {
    Instant daysAgo = Instant.now().minus(25, ChronoUnit.HOURS);
    user.setActivated(true);
    user.setResetDate(daysAgo);
    user.setResetKey("1234");
    userRepository.saveAndFlush(user);
    Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());
    assertThat(maybeUser).isNotPresent();
    userRepository.delete(user);
}
Also used : User(io.github.jhipster.sample.domain.User) Instant(java.time.Instant) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-websocket by jhipster.

the class UserServiceIntTest method assertThatUserCanResetPassword.

@Test
@Transactional
public void assertThatUserCanResetPassword() {
    String oldPassword = user.getPassword();
    Instant daysAgo = Instant.now().minus(2, ChronoUnit.HOURS);
    String resetKey = RandomUtil.generateResetKey();
    user.setActivated(true);
    user.setResetDate(daysAgo);
    user.setResetKey(resetKey);
    userRepository.saveAndFlush(user);
    Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());
    assertThat(maybeUser).isPresent();
    assertThat(maybeUser.orElse(null).getResetDate()).isNull();
    assertThat(maybeUser.orElse(null).getResetKey()).isNull();
    assertThat(maybeUser.orElse(null).getPassword()).isNotEqualTo(oldPassword);
    userRepository.delete(user);
}
Also used : User(io.github.jhipster.sample.domain.User) Instant(java.time.Instant) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-websocket by jhipster.

the class UserResourceIntTest method createUser.

@Test
@Transactional
public void createUser() throws Exception {
    int databaseSizeBeforeCreate = userRepository.findAll().size();
    // Create the User
    ManagedUserVM managedUserVM = new ManagedUserVM();
    managedUserVM.setLogin(DEFAULT_LOGIN);
    managedUserVM.setPassword(DEFAULT_PASSWORD);
    managedUserVM.setFirstName(DEFAULT_FIRSTNAME);
    managedUserVM.setLastName(DEFAULT_LASTNAME);
    managedUserVM.setEmail(DEFAULT_EMAIL);
    managedUserVM.setActivated(true);
    managedUserVM.setImageUrl(DEFAULT_IMAGEURL);
    managedUserVM.setLangKey(DEFAULT_LANGKEY);
    managedUserVM.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
    restUserMockMvc.perform(post("/api/users").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isCreated());
    // Validate the User in the database
    List<User> userList = userRepository.findAll();
    assertThat(userList).hasSize(databaseSizeBeforeCreate + 1);
    User testUser = userList.get(userList.size() - 1);
    assertThat(testUser.getLogin()).isEqualTo(DEFAULT_LOGIN);
    assertThat(testUser.getFirstName()).isEqualTo(DEFAULT_FIRSTNAME);
    assertThat(testUser.getLastName()).isEqualTo(DEFAULT_LASTNAME);
    assertThat(testUser.getEmail()).isEqualTo(DEFAULT_EMAIL);
    assertThat(testUser.getImageUrl()).isEqualTo(DEFAULT_IMAGEURL);
    assertThat(testUser.getLangKey()).isEqualTo(DEFAULT_LANGKEY);
}
Also used : User(io.github.jhipster.sample.domain.User) ManagedUserVM(io.github.jhipster.sample.web.rest.vm.ManagedUserVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 54 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-websocket by jhipster.

the class UserResourceIntTest method testUserDTOtoUser.

@Test
public void testUserDTOtoUser() {
    UserDTO userDTO = new UserDTO();
    userDTO.setId(DEFAULT_ID);
    userDTO.setLogin(DEFAULT_LOGIN);
    userDTO.setFirstName(DEFAULT_FIRSTNAME);
    userDTO.setLastName(DEFAULT_LASTNAME);
    userDTO.setEmail(DEFAULT_EMAIL);
    userDTO.setActivated(true);
    userDTO.setImageUrl(DEFAULT_IMAGEURL);
    userDTO.setLangKey(DEFAULT_LANGKEY);
    userDTO.setCreatedBy(DEFAULT_LOGIN);
    userDTO.setLastModifiedBy(DEFAULT_LOGIN);
    userDTO.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
    User user = userMapper.userDTOToUser(userDTO);
    assertThat(user.getId()).isEqualTo(DEFAULT_ID);
    assertThat(user.getLogin()).isEqualTo(DEFAULT_LOGIN);
    assertThat(user.getFirstName()).isEqualTo(DEFAULT_FIRSTNAME);
    assertThat(user.getLastName()).isEqualTo(DEFAULT_LASTNAME);
    assertThat(user.getEmail()).isEqualTo(DEFAULT_EMAIL);
    assertThat(user.getActivated()).isEqualTo(true);
    assertThat(user.getImageUrl()).isEqualTo(DEFAULT_IMAGEURL);
    assertThat(user.getLangKey()).isEqualTo(DEFAULT_LANGKEY);
    assertThat(user.getCreatedBy()).isNull();
    assertThat(user.getCreatedDate()).isNotNull();
    assertThat(user.getLastModifiedBy()).isNull();
    assertThat(user.getLastModifiedDate()).isNotNull();
    assertThat(user.getAuthorities()).extracting("name").containsExactly(AuthoritiesConstants.USER);
}
Also used : User(io.github.jhipster.sample.domain.User) UserDTO(io.github.jhipster.sample.service.dto.UserDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 55 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-websocket by jhipster.

the class UserResourceIntTest method updateUserExistingEmail.

@Test
@Transactional
public void updateUserExistingEmail() throws Exception {
    // Initialize the database with 2 users
    userRepository.saveAndFlush(user);
    User anotherUser = new User();
    anotherUser.setLogin("jhipster");
    anotherUser.setPassword(RandomStringUtils.random(60));
    anotherUser.setActivated(true);
    anotherUser.setEmail("jhipster@localhost");
    anotherUser.setFirstName("java");
    anotherUser.setLastName("hipster");
    anotherUser.setImageUrl("");
    anotherUser.setLangKey("en");
    userRepository.saveAndFlush(anotherUser);
    // Update the user
    User updatedUser = userRepository.findById(user.getId()).get();
    ManagedUserVM managedUserVM = new ManagedUserVM();
    managedUserVM.setId(updatedUser.getId());
    managedUserVM.setLogin(updatedUser.getLogin());
    managedUserVM.setPassword(updatedUser.getPassword());
    managedUserVM.setFirstName(updatedUser.getFirstName());
    managedUserVM.setLastName(updatedUser.getLastName());
    // this email should already be used by anotherUser
    managedUserVM.setEmail("jhipster@localhost");
    managedUserVM.setActivated(updatedUser.getActivated());
    managedUserVM.setImageUrl(updatedUser.getImageUrl());
    managedUserVM.setLangKey(updatedUser.getLangKey());
    managedUserVM.setCreatedBy(updatedUser.getCreatedBy());
    managedUserVM.setCreatedDate(updatedUser.getCreatedDate());
    managedUserVM.setLastModifiedBy(updatedUser.getLastModifiedBy());
    managedUserVM.setLastModifiedDate(updatedUser.getLastModifiedDate());
    managedUserVM.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
    restUserMockMvc.perform(put("/api/users").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isBadRequest());
}
Also used : User(io.github.jhipster.sample.domain.User) ManagedUserVM(io.github.jhipster.sample.web.rest.vm.ManagedUserVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (io.github.jhipster.sample.domain.User)329 Test (org.junit.Test)251 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)251 Transactional (org.springframework.transaction.annotation.Transactional)150 WithMockUser (org.springframework.security.test.context.support.WithMockUser)138 ManagedUserVM (io.github.jhipster.sample.web.rest.vm.ManagedUserVM)90 AbstractCassandraTest (io.github.jhipster.sample.AbstractCassandraTest)38 UserDTO (io.github.jhipster.sample.service.dto.UserDTO)32 Authority (io.github.jhipster.sample.domain.Authority)24 PasswordChangeDTO (io.github.jhipster.sample.service.dto.PasswordChangeDTO)24 MimeMessage (javax.mail.internet.MimeMessage)24 Instant (java.time.Instant)21 Before (org.junit.Before)13 Timed (com.codahale.metrics.annotation.Timed)12 KeyAndPasswordVM (io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM)12 Scheduled (org.springframework.scheduling.annotation.Scheduled)8 GrantedAuthority (org.springframework.security.core.GrantedAuthority)7 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)7 UserDetails (org.springframework.security.core.userdetails.UserDetails)7 PersistentToken (io.github.jhipster.sample.domain.PersistentToken)6