Search in sources :

Example 16 with UserDTO

use of io.github.jhipster.sample.service.dto.UserDTO in project jhipster-sample-app-cassandra by jhipster.

the class AccountResourceIntTest method testSaveExistingEmailAndLogin.

@Test
@WithMockUser("save-existing-email-and-login")
public void testSaveExistingEmailAndLogin() throws Exception {
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    user.setLogin("save-existing-email-and-login");
    user.setEmail("save-existing-email-and-login@example.com");
    user.setPassword(RandomStringUtils.random(60));
    user.setActivated(true);
    userRepository.save(user);
    UserDTO userDTO = new UserDTO();
    userDTO.setLogin("not-used");
    userDTO.setFirstName("firstname");
    userDTO.setLastName("lastname");
    userDTO.setEmail("save-existing-email-and-login@example.com");
    userDTO.setActivated(false);
    userDTO.setLangKey(Constants.DEFAULT_LANGUAGE);
    userDTO.setAuthorities(Collections.singleton(AuthoritiesConstants.ADMIN));
    restMvc.perform(post("/api/account").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(userDTO))).andExpect(status().isOk());
    User updatedUser = userRepository.findOneByLogin("save-existing-email-and-login").orElse(null);
    assertThat(updatedUser.getEmail()).isEqualTo("save-existing-email-and-login@example.com");
}
Also used : User(io.github.jhipster.sample.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) UserDTO(io.github.jhipster.sample.service.dto.UserDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with UserDTO

use of io.github.jhipster.sample.service.dto.UserDTO in project jhipster-sample-app-cassandra 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.setLangKey(DEFAULT_LANGKEY);
    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.getLangKey()).isEqualTo(DEFAULT_LANGKEY);
    assertThat(user.getAuthorities()).containsExactly(AuthoritiesConstants.USER);
}
Also used : User(io.github.jhipster.sample.domain.User) UserDTO(io.github.jhipster.sample.service.dto.UserDTO) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with UserDTO

use of io.github.jhipster.sample.service.dto.UserDTO in project jhipster-sample-app-cassandra by jhipster.

the class UserResourceIntTest method testUserToUserDTO.

@Test
public void testUserToUserDTO() {
    user.setId(DEFAULT_ID);
    user.setAuthorities(Stream.of(AuthoritiesConstants.USER).collect(Collectors.toSet()));
    UserDTO userDTO = userMapper.userToUserDTO(user);
    assertThat(userDTO.getId()).isEqualTo(DEFAULT_ID);
    assertThat(userDTO.getLogin()).isEqualTo(DEFAULT_LOGIN);
    assertThat(userDTO.getFirstName()).isEqualTo(DEFAULT_FIRSTNAME);
    assertThat(userDTO.getLastName()).isEqualTo(DEFAULT_LASTNAME);
    assertThat(userDTO.getEmail()).isEqualTo(DEFAULT_EMAIL);
    assertThat(userDTO.isActivated()).isEqualTo(true);
    assertThat(userDTO.getLangKey()).isEqualTo(DEFAULT_LANGKEY);
    assertThat(userDTO.getAuthorities()).containsExactly(AuthoritiesConstants.USER);
    assertThat(userDTO.toString()).isNotNull();
}
Also used : UserDTO(io.github.jhipster.sample.service.dto.UserDTO) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with UserDTO

use of io.github.jhipster.sample.service.dto.UserDTO in project jhipster-sample-app-mongodb by jhipster.

the class UserResource method getAllUsers.

/**
 * GET /users : get all users.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and with body all users
 */
@GetMapping("/users")
@Timed
public ResponseEntity<List<UserDTO>> getAllUsers(Pageable pageable) {
    final Page<UserDTO> page = userService.getAllManagedUsers(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/users");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) UserDTO(io.github.jhipster.sample.service.dto.UserDTO) Timed(com.codahale.metrics.annotation.Timed)

Example 20 with UserDTO

use of io.github.jhipster.sample.service.dto.UserDTO in project jhipster-sample-app-mongodb by jhipster.

the class UserServiceIntTest method assertThatAnonymousUserIsNotGet.

@Test
public void assertThatAnonymousUserIsNotGet() {
    user.setLogin(Constants.ANONYMOUS_USER);
    if (!userRepository.findOneByLogin(Constants.ANONYMOUS_USER).isPresent()) {
        userRepository.save(user);
    }
    final PageRequest pageable = PageRequest.of(0, (int) userRepository.count());
    final Page<UserDTO> allManagedUsers = userService.getAllManagedUsers(pageable);
    assertThat(allManagedUsers.getContent().stream().noneMatch(user -> Constants.ANONYMOUS_USER.equals(user.getLogin()))).isTrue();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) UserDTO(io.github.jhipster.sample.service.dto.UserDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

UserDTO (io.github.jhipster.sample.service.dto.UserDTO)51 Test (org.junit.Test)44 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)44 User (io.github.jhipster.sample.domain.User)32 WithMockUser (org.springframework.security.test.context.support.WithMockUser)24 Transactional (org.springframework.transaction.annotation.Transactional)21 Authority (io.github.jhipster.sample.domain.Authority)7 Timed (com.codahale.metrics.annotation.Timed)6 AbstractCassandraTest (io.github.jhipster.sample.AbstractCassandraTest)6 PageRequest (org.springframework.data.domain.PageRequest)6 HttpHeaders (org.springframework.http.HttpHeaders)6 ResponseEntity (org.springframework.http.ResponseEntity)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1