89.2. Test list - pagination. return page (#10)
This commit is contained in:
@ -8,6 +8,7 @@ import net.shyshkin.study.fullstack.supportportal.backend.domain.User;
|
|||||||
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.UserDto;
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.UserDto;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.service.UserService;
|
import net.shyshkin.study.fullstack.supportportal.backend.service.UserService;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.utility.JwtTokenProvider;
|
import net.shyshkin.study.fullstack.supportportal.backend.utility.JwtTokenProvider;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -20,7 +21,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ public class UserResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public List<User> getAllUsers(Pageable pageable) {
|
public Page<User> getAllUsers(Pageable pageable) {
|
||||||
return userService.findAll(pageable);
|
return userService.findAll(pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,18 +2,18 @@ package net.shyshkin.study.fullstack.supportportal.backend.service;
|
|||||||
|
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.domain.User;
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.User;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.UserDto;
|
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.UserDto;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface UserService extends UserDetailsService {
|
public interface UserService extends UserDetailsService {
|
||||||
|
|
||||||
User register(String firstName, String lastName, String username, String email);
|
User register(String firstName, String lastName, String username, String email);
|
||||||
|
|
||||||
List<User> findAll(Pageable pageable);
|
Page<User> findAll(Pageable pageable);
|
||||||
|
|
||||||
User findByUsername(String username);
|
User findByUsername(String username);
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import net.shyshkin.study.fullstack.supportportal.backend.repository.UserReposit
|
|||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||||
import org.springframework.core.ParameterizedTypeReference;
|
import org.springframework.core.ParameterizedTypeReference;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.RequestEntity;
|
import org.springframework.http.RequestEntity;
|
||||||
@ -33,7 +34,6 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -127,8 +127,8 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<User> findAll(Pageable pageable) {
|
public Page<User> findAll(Pageable pageable) {
|
||||||
return userRepository.findAll(pageable).getContent();
|
return userRepository.findAll(pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
package net.shyshkin.study.fullstack.supportportal.backend.controller;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.common.BaseUserTest;
|
import net.shyshkin.study.fullstack.supportportal.backend.common.BaseUserTest;
|
||||||
import net.shyshkin.study.fullstack.supportportal.backend.constant.FileConstant;
|
import net.shyshkin.study.fullstack.supportportal.backend.constant.FileConstant;
|
||||||
@ -490,18 +491,30 @@ class UserResourceUnSecureTest extends BaseUserTest {
|
|||||||
void getAllUsers() {
|
void getAllUsers() {
|
||||||
|
|
||||||
//when
|
//when
|
||||||
var responseEntity = restTemplate.exchange("/user", HttpMethod.GET, null, new ParameterizedTypeReference<List<User>>() {
|
var responseEntity = restTemplate.exchange("/user", HttpMethod.GET, null, UserPage.class);
|
||||||
});
|
|
||||||
|
|
||||||
//then
|
//then
|
||||||
log.debug("Response Entity: {}", responseEntity);
|
log.debug("Response Entity: {}", responseEntity);
|
||||||
assertThat(responseEntity.getStatusCode()).isEqualTo(OK);
|
assertThat(responseEntity.getStatusCode()).isEqualTo(OK);
|
||||||
assertThat(responseEntity.getBody())
|
assertThat(responseEntity.getBody())
|
||||||
.isNotNull()
|
.isNotNull();
|
||||||
|
assertThat(responseEntity.getBody().getContent())
|
||||||
.hasSizeGreaterThan(2);
|
.hasSizeGreaterThan(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
static class UserPage {
|
||||||
|
private List<User> content;
|
||||||
|
private boolean last;
|
||||||
|
private boolean first;
|
||||||
|
private int totalElements;
|
||||||
|
private int size;
|
||||||
|
private int numberOfElements;
|
||||||
|
private int number;
|
||||||
|
private boolean empty;
|
||||||
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
class ResetPasswordTests {
|
class ResetPasswordTests {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user