Search in sources :

Example 26 with User

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

the class UserResourceIntTest method createUserWithExistingId.

@Test
@Transactional
public void createUserWithExistingId() throws Exception {
    int databaseSizeBeforeCreate = userRepository.findAll().size();
    ManagedUserVM managedUserVM = new ManagedUserVM();
    managedUserVM.setId(1L);
    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));
    // An entity with an existing ID cannot be created, so this API call must fail
    restUserMockMvc.perform(post("/api/users").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isBadRequest());
    // Validate the User in the database
    List<User> userList = userRepository.findAll();
    assertThat(userList).hasSize(databaseSizeBeforeCreate);
}
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 27 with User

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

the class UserResourceIntTest method updateUserLogin.

@Test
@Transactional
public void updateUserLogin() throws Exception {
    // Initialize the database
    userRepository.saveAndFlush(user);
    int databaseSizeBeforeUpdate = userRepository.findAll().size();
    // Update the user
    User updatedUser = userRepository.findById(user.getId()).get();
    ManagedUserVM managedUserVM = new ManagedUserVM();
    managedUserVM.setId(updatedUser.getId());
    managedUserVM.setLogin(UPDATED_LOGIN);
    managedUserVM.setPassword(UPDATED_PASSWORD);
    managedUserVM.setFirstName(UPDATED_FIRSTNAME);
    managedUserVM.setLastName(UPDATED_LASTNAME);
    managedUserVM.setEmail(UPDATED_EMAIL);
    managedUserVM.setActivated(updatedUser.getActivated());
    managedUserVM.setImageUrl(UPDATED_IMAGEURL);
    managedUserVM.setLangKey(UPDATED_LANGKEY);
    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().isOk());
    // Validate the User in the database
    List<User> userList = userRepository.findAll();
    assertThat(userList).hasSize(databaseSizeBeforeUpdate);
    User testUser = userList.get(userList.size() - 1);
    assertThat(testUser.getLogin()).isEqualTo(UPDATED_LOGIN);
    assertThat(testUser.getFirstName()).isEqualTo(UPDATED_FIRSTNAME);
    assertThat(testUser.getLastName()).isEqualTo(UPDATED_LASTNAME);
    assertThat(testUser.getEmail()).isEqualTo(UPDATED_EMAIL);
    assertThat(testUser.getImageUrl()).isEqualTo(UPDATED_IMAGEURL);
    assertThat(testUser.getLangKey()).isEqualTo(UPDATED_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 28 with User

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

the class UserService method getToken.

private static UsernamePasswordAuthenticationToken getToken(Map<String, Object> details, User user, Set<GrantedAuthority> grantedAuthorities) {
    // create UserDetails so #{principal.username} works
    UserDetails userDetails = new org.springframework.security.core.userdetails.User(user.getLogin(), "N/A", grantedAuthorities);
    // update Spring Security Authorities to match groups claim from IdP
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userDetails, "N/A", grantedAuthorities);
    token.setDetails(details);
    return token;
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) User(io.github.jhipster.sample.domain.User) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 29 with User

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

the class UserServiceIntTest method init.

@Before
public void init() {
    user = new User();
    user.setLogin("johndoe");
    user.setActivated(true);
    user.setEmail("johndoe@localhost");
    user.setFirstName("john");
    user.setLastName("doe");
    user.setImageUrl("http://placehold.it/50x50");
    user.setLangKey("en");
}
Also used : User(io.github.jhipster.sample.domain.User) Before(org.junit.Before)

Example 30 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-oauth2 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)

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