Search in sources :

Example 1 with UserDTO

use of com.baeldung.service.dto.UserDTO in project tutorials by eugenp.

the class UserServiceIntegrationTest method assertThatAnonymousUserIsNotGet.

@Test
public void assertThatAnonymousUserIsNotGet() {
    final PageRequest pageable = new PageRequest(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(com.baeldung.service.dto.UserDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with UserDTO

use of com.baeldung.service.dto.UserDTO in project tutorials by eugenp.

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(@ApiParam 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(com.baeldung.service.dto.UserDTO) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with UserDTO

use of com.baeldung.service.dto.UserDTO 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();
}
Also used : User(com.baeldung.domain.User) UserDTO(com.baeldung.service.dto.UserDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserDTO (com.baeldung.service.dto.UserDTO)3 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 User (com.baeldung.domain.User)1 Timed (com.codahale.metrics.annotation.Timed)1 PageRequest (org.springframework.data.domain.PageRequest)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1 Transactional (org.springframework.transaction.annotation.Transactional)1