[BAEL-6318] fix indentation
This commit is contained in:
parent
b6966054b4
commit
09e416abd8
|
@ -14,12 +14,13 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class CustomPageImpl<T> extends PageImpl<T> {
|
public class CustomPageImpl<T> extends PageImpl<T> {
|
||||||
|
|
||||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||||
public CustomPageImpl(@JsonProperty("content") List<T> content, @JsonProperty("number") int number, @JsonProperty("size") int size, @JsonProperty("totalElements") Long totalElements, @JsonProperty("pageable") JsonNode pageable,
|
public CustomPageImpl(@JsonProperty("content") List<T> content, @JsonProperty("number") int number,
|
||||||
@JsonProperty("last") boolean last, @JsonProperty("totalPages") int totalPages, @JsonProperty("sort") JsonNode sort, @JsonProperty("numberOfElements") int numberOfElements) {
|
@JsonProperty("size") int size, @JsonProperty("totalElements") Long totalElements,
|
||||||
|
@JsonProperty("pageable") JsonNode pageable, @JsonProperty("last") boolean last,
|
||||||
|
@JsonProperty("totalPages") int totalPages, @JsonProperty("sort") JsonNode sort,
|
||||||
|
@JsonProperty("numberOfElements") int numberOfElements) {
|
||||||
super(content, PageRequest.of(number, 1), 10);
|
super(content, PageRequest.of(number, 1), 10);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomPageImpl(List<T> content, Pageable pageable, long total) {
|
public CustomPageImpl(List<T> content, Pageable pageable, long total) {
|
||||||
|
|
|
@ -24,8 +24,9 @@ public class EmployeeClient {
|
||||||
.queryParam("page", pageable.getPageNumber())
|
.queryParam("page", pageable.getPageNumber())
|
||||||
.queryParam("size", pageable.getPageSize());
|
.queryParam("size", pageable.getPageSize());
|
||||||
|
|
||||||
ResponseEntity<CustomPageImpl<EmployeeDto>> responseEntity = restTemplate.exchange(uriBuilder.toUriString(), HttpMethod.GET, null, new ParameterizedTypeReference<CustomPageImpl<EmployeeDto>>() {
|
ResponseEntity<CustomPageImpl<EmployeeDto>> responseEntity = restTemplate.exchange(uriBuilder.toUriString(),
|
||||||
});
|
HttpMethod.GET, null, new ParameterizedTypeReference<CustomPageImpl<EmployeeDto>>() {
|
||||||
|
});
|
||||||
|
|
||||||
return responseEntity.getBody();
|
return responseEntity.getBody();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,8 @@ public class EmployeeController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/data")
|
@GetMapping("/data")
|
||||||
public ResponseEntity<Page<EmployeeDto>> getData(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
|
public ResponseEntity<Page<EmployeeDto>> getData(@RequestParam(defaultValue = "0") int page,
|
||||||
|
@RequestParam(defaultValue = "10") int size) {
|
||||||
List<EmployeeDto> empList = listImplementation();
|
List<EmployeeDto> empList = listImplementation();
|
||||||
|
|
||||||
int totalSize = empList.size();
|
int totalSize = empList.size();
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package com.baeldung.pageentityresponse;
|
package com.baeldung.pageentityresponse;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
|
@ -14,51 +16,47 @@ import org.springframework.data.domain.PageImpl;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
@SpringBootTest(classes = PageEntityResponseApp.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
|
|
||||||
@SpringBootTest(classes = PageEntityResponseApp.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
public class EmployeeControllerIntegrationTest {
|
public class EmployeeControllerIntegrationTest {
|
||||||
|
|
||||||
@LocalServerPort
|
@LocalServerPort
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TestRestTemplate restTemplate;
|
private TestRestTemplate restTemplate;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenGetData_whenRestTemplateExchange_thenReturnsPageOfEmployee() {
|
void givenGetData_whenRestTemplateExchange_thenReturnsPageOfEmployee() {
|
||||||
ResponseEntity<CustomPageImpl<EmployeeDto>> responseEntity = restTemplate.exchange(
|
ResponseEntity<CustomPageImpl<EmployeeDto>> responseEntity = restTemplate.exchange(
|
||||||
"http://localhost:" + port + "/organisation/data",
|
"http://localhost:" + port + "/organisation/data", HttpMethod.GET, null,
|
||||||
HttpMethod.GET,
|
new ParameterizedTypeReference<CustomPageImpl<EmployeeDto>>() {
|
||||||
null,
|
});
|
||||||
new ParameterizedTypeReference<CustomPageImpl<EmployeeDto>>() {}
|
|
||||||
);
|
|
||||||
|
|
||||||
assertEquals(200, responseEntity.getStatusCodeValue());
|
assertEquals(200, responseEntity.getStatusCodeValue());
|
||||||
PageImpl<EmployeeDto> restPage = responseEntity.getBody();
|
PageImpl<EmployeeDto> restPage = responseEntity.getBody();
|
||||||
assertNotNull(restPage);
|
assertNotNull(restPage);
|
||||||
|
|
||||||
assertEquals(10, restPage.getTotalElements());
|
assertEquals(10, restPage.getTotalElements());
|
||||||
|
|
||||||
List<EmployeeDto> content = restPage.getContent();
|
List<EmployeeDto> content = restPage.getContent();
|
||||||
assertNotNull(content);
|
assertNotNull(content);
|
||||||
assertEquals(3, content.size());
|
assertEquals(3, content.size());
|
||||||
|
|
||||||
EmployeeDto employee1 = content.get(0);
|
EmployeeDto employee1 = content.get(0);
|
||||||
assertEquals("Jane", employee1.getName());
|
assertEquals("Jane", employee1.getName());
|
||||||
assertEquals("Finance", employee1.getDept());
|
assertEquals("Finance", employee1.getDept());
|
||||||
assertEquals(50000, employee1.getSalary());
|
assertEquals(50000, employee1.getSalary());
|
||||||
|
|
||||||
EmployeeDto employee2 = content.get(1);
|
EmployeeDto employee2 = content.get(1);
|
||||||
assertEquals("Sarah", employee2.getName());
|
assertEquals("Sarah", employee2.getName());
|
||||||
assertEquals("IT", employee2.getDept());
|
assertEquals("IT", employee2.getDept());
|
||||||
assertEquals(70000, employee2.getSalary());
|
assertEquals(70000, employee2.getSalary());
|
||||||
|
|
||||||
EmployeeDto employee3 = content.get(2);
|
EmployeeDto employee3 = content.get(2);
|
||||||
assertEquals("John", employee3.getName());
|
assertEquals("John", employee3.getName());
|
||||||
assertEquals("IT", employee3.getDept());
|
assertEquals("IT", employee3.getDept());
|
||||||
assertEquals(90000, employee3.getSalary());
|
assertEquals(90000, employee3.getSalary());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue