Merge remote-tracking branch 'origin/2.2.x'

# Conflicts:
#	spring-cloud-openfeign-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json
#	spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java
This commit is contained in:
Olga Maciaszek-Sharma
2021-02-08 18:40:33 +01:00
3 changed files with 67 additions and 1 deletions

View File

@@ -116,7 +116,7 @@ public class PageableSpringEncoder implements Encoder {
}
}
for (Sort.Order order : sort) {
sortQueries.add(order.getProperty() + "," + order.getDirection());
sortQueries.add(order.getProperty() + "%2C" + order.getDirection());
}
if (!sortQueries.isEmpty()) {
template.query(sortParameter, sortQueries);

View File

@@ -2,6 +2,12 @@
"groups": [
],
"properties": [
{
"name": "feign.autoconfiguration.jackson.enabled",
"type": "java.lang.Boolean",
"description": "If true, PageJacksonModule and SortJacksonModule bean will be provided for Jackson page decoding.",
"defaultValue": "false"
},
{
"name": "feign.circuitbreaker.enabled",
"type": "java.lang.Boolean",

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.openfeign.encoding;
import java.util.List;
import java.util.Optional;
import org.junit.Test;
@@ -53,6 +54,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
* Tests the pagination encoding.
*
* @author Charlie Mordant.
* @author Hyeonmin Park
*/
@SpringBootTest(classes = FeignPageableEncodingTests.Application.class, webEnvironment = RANDOM_PORT,
value = { "feign.compression.request.enabled=true", "feign.autoconfiguration.jackson.enabled=true" })
@@ -86,6 +88,64 @@ public class FeignPageableEncodingTests {
}
@Test
public void testPageableWithDescDirection() {
// given
Pageable pageable = PageRequest.of(0, 10, Sort.Direction.DESC, "sortProperty");
// when
final ResponseEntity<Page<Invoice>> response = this.invoiceClient.getInvoicesPaged(pageable);
// then
assertThat(response).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).isNotNull();
assertThat(pageable.getPageSize()).isEqualTo(response.getBody().getSize());
Sort sort = response.getBody().getPageable().getSort();
assertThat(sort).hasSize(1);
assertThat(sort.get()).hasSize(1);
Optional<Sort.Order> optionalOrder = sort.get().findFirst();
assertThat(optionalOrder.isPresent()).isTrue();
Sort.Order order = optionalOrder.get();
assertThat(order.getDirection()).isEqualTo(Sort.Direction.DESC);
assertThat(order.getProperty()).isEqualTo("sortProperty");
}
@Test
public void testPageableWithMultipleSort() {
// given
Pageable pageable = PageRequest.of(0, 10,
Sort.by(Sort.Order.desc("sortProperty1"), Sort.Order.asc("sortProperty2")));
// when
final ResponseEntity<Page<Invoice>> response = this.invoiceClient.getInvoicesPaged(pageable);
// then
assertThat(response).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).isNotNull();
assertThat(pageable.getPageSize()).isEqualTo(response.getBody().getSize());
Sort sort = response.getBody().getPageable().getSort();
assertThat(sort).hasSize(2);
List<Sort.Order> orderList = sort.toList();
assertThat(orderList).hasSize(2);
Sort.Order firstOrder = orderList.get(0);
assertThat(firstOrder.getDirection()).isEqualTo(Sort.Direction.DESC);
assertThat(firstOrder.getProperty()).isEqualTo("sortProperty1");
Sort.Order secondOrder = orderList.get(1);
assertThat(secondOrder.getDirection()).isEqualTo(Sort.Direction.ASC);
assertThat(secondOrder.getProperty()).isEqualTo("sortProperty2");
}
@EnableFeignClients(clients = InvoiceClient.class)
@LoadBalancerClient(name = "local", configuration = LocalClientConfiguration.class)
@SpringBootApplication(scanBasePackages = "org.springframework.cloud.openfeign.encoding.app",