[BAEL-6318] fix indentation

This commit is contained in:
uzma 2023-07-17 14:02:35 +01:00
parent b6966054b4
commit 09e416abd8
4 changed files with 44 additions and 43 deletions

View File

@ -14,12 +14,13 @@ import com.fasterxml.jackson.databind.JsonNode;
@JsonIgnoreProperties(ignoreUnknown = true)
public class CustomPageImpl<T> extends PageImpl<T> {
@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,
@JsonProperty("last") boolean last, @JsonProperty("totalPages") int totalPages, @JsonProperty("sort") JsonNode sort, @JsonProperty("numberOfElements") int numberOfElements) {
public CustomPageImpl(@JsonProperty("content") List<T> content, @JsonProperty("number") int number,
@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);
}
public CustomPageImpl(List<T> content, Pageable pageable, long total) {

View File

@ -24,8 +24,9 @@ public class EmployeeClient {
.queryParam("page", pageable.getPageNumber())
.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();
}

View File

@ -30,7 +30,8 @@ public class EmployeeController {
}
@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();
int totalSize = empList.size();

View File

@ -1,8 +1,10 @@
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 org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
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.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
public class EmployeeControllerIntegrationTest {
@LocalServerPort
private int port;
@LocalServerPort
private int port;
@Autowired
private TestRestTemplate restTemplate;
@Autowired
private TestRestTemplate restTemplate;
@Test
void givenGetData_whenRestTemplateExchange_thenReturnsPageOfEmployee() {
ResponseEntity<CustomPageImpl<EmployeeDto>> responseEntity = restTemplate.exchange(
"http://localhost:" + port + "/organisation/data",
HttpMethod.GET,
null,
new ParameterizedTypeReference<CustomPageImpl<EmployeeDto>>() {}
);
@Test
void givenGetData_whenRestTemplateExchange_thenReturnsPageOfEmployee() {
ResponseEntity<CustomPageImpl<EmployeeDto>> responseEntity = restTemplate.exchange(
"http://localhost:" + port + "/organisation/data", HttpMethod.GET, null,
new ParameterizedTypeReference<CustomPageImpl<EmployeeDto>>() {
});
assertEquals(200, responseEntity.getStatusCodeValue());
PageImpl<EmployeeDto> restPage = responseEntity.getBody();
assertNotNull(restPage);
assertEquals(200, responseEntity.getStatusCodeValue());
PageImpl<EmployeeDto> restPage = responseEntity.getBody();
assertNotNull(restPage);
assertEquals(10, restPage.getTotalElements());
assertEquals(10, restPage.getTotalElements());
List<EmployeeDto> content = restPage.getContent();
assertNotNull(content);
assertEquals(3, content.size());
List<EmployeeDto> content = restPage.getContent();
assertNotNull(content);
assertEquals(3, content.size());
EmployeeDto employee1 = content.get(0);
assertEquals("Jane", employee1.getName());
assertEquals("Finance", employee1.getDept());
assertEquals(50000, employee1.getSalary());
EmployeeDto employee1 = content.get(0);
assertEquals("Jane", employee1.getName());
assertEquals("Finance", employee1.getDept());
assertEquals(50000, employee1.getSalary());
EmployeeDto employee2 = content.get(1);
assertEquals("Sarah", employee2.getName());
assertEquals("IT", employee2.getDept());
assertEquals(70000, employee2.getSalary());
EmployeeDto employee2 = content.get(1);
assertEquals("Sarah", employee2.getName());
assertEquals("IT", employee2.getDept());
assertEquals(70000, employee2.getSalary());
EmployeeDto employee3 = content.get(2);
assertEquals("John", employee3.getName());
assertEquals("IT", employee3.getDept());
assertEquals(90000, employee3.getSalary());
}
EmployeeDto employee3 = content.get(2);
assertEquals("John", employee3.getName());
assertEquals("IT", employee3.getDept());
assertEquals(90000, employee3.getSalary());
}
}