diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageableSpringEncoder.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageableSpringEncoder.java index 4ee10f03..bdc9fb53 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageableSpringEncoder.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageableSpringEncoder.java @@ -120,7 +120,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); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java index 7e7a2b3b..40f530a3 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java @@ -17,6 +17,7 @@ package org.springframework.cloud.openfeign.encoding; import java.util.Collections; +import java.util.List; import java.util.Optional; import com.netflix.loadbalancer.BaseLoadBalancer; @@ -54,6 +55,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, @@ -93,6 +95,64 @@ public class FeignPageableEncodingTests { } + @Test + public void testPageableWithDescDirection() { + // given + Pageable pageable = PageRequest.of(0, 10, Sort.Direction.DESC, "sortProperty"); + + // when + final ResponseEntity> 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 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> 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 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) @RibbonClient(name = "local", configuration = LocalRibbonClientConfiguration.class) @SpringBootApplication(