checkstyle rules applied to pageable support

This commit is contained in:
charliemordant
2019-02-10 18:53:59 +01:00
parent f8352de786
commit 6e0e63644b
12 changed files with 297 additions and 287 deletions

View File

@@ -25,8 +25,9 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
/**
* Scans for interfaces that declare they are feign clients (via {@link org.springframework.cloud.openfeign.FeignClient}
* <code>@FeignClient</code>). Configures component scanning directives for use with
* Scans for interfaces that declare they are feign clients (via
* {@link org.springframework.cloud.openfeign.FeignClient} <code>@FeignClient</code>).
* Configures component scanning directives for use with
* {@link org.springframework.context.annotation.Configuration}
* <code>@Configuration</code> classes.
*

View File

@@ -218,4 +218,5 @@ public class FeignAutoConfiguration {
}
}
}

View File

@@ -145,4 +145,5 @@ public class FeignClientsConfiguration {
}
}
}

View File

@@ -16,149 +16,156 @@
package org.springframework.cloud.openfeign.support;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.springframework.data.domain.*;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
/**
* This jackson module provides support to deserialize spring {Page<T>}
* objects.
* This jackson module provides support to deserialize spring {@link Page} objects.
*
* @author Pascal Büttiker
*/
public class PageJacksonModule extends Module {
@Override
public String getModuleName() {
return "PageJacksonModule";
}
@Override
public String getModuleName() {
return "PageJacksonModule";
}
@Override
public Version version() {
return new Version(0,1,0, "", null,null);
}
@Override
public Version version() {
return new Version(0, 1, 0, "", null, null);
}
@Override
public void setupModule(SetupContext context) {
context.setMixInAnnotations(Page.class, PageMixIn.class);
}
@Override
public void setupModule(SetupContext context) {
context.setMixInAnnotations(Page.class, PageMixIn.class);
}
@JsonDeserialize(as = SimplePageImpl.class)
private interface PageMixIn{ }
@JsonDeserialize(as = SimplePageImpl.class)
private interface PageMixIn {
}
static class SimplePageImpl<T> implements Page<T> {
static class SimplePageImpl<T> implements Page<T> {
private final Page<T> delegate;
private final Page<T> delegate;
public SimplePageImpl(
@JsonProperty("content") List<T> content,
@JsonProperty("page")int number,
@JsonProperty("size") int size,
@JsonProperty("totalElements") long totalElements){
delegate = new PageImpl<>(content, PageRequest.of(number, size), totalElements);
}
SimplePageImpl(@JsonProperty("content") List<T> content,
@JsonProperty("page") int number, @JsonProperty("size") int size,
@JsonProperty("totalElements") long totalElements) {
delegate = new PageImpl<>(content, PageRequest.of(number, size),
totalElements);
}
@JsonProperty
@Override
public int getTotalPages() {
return delegate.getTotalPages();
}
@JsonProperty
@Override
public int getTotalPages() {
return delegate.getTotalPages();
}
@JsonProperty
@Override
public long getTotalElements() {
return delegate.getTotalElements();
}
@JsonProperty
@Override
public long getTotalElements() {
return delegate.getTotalElements();
}
@JsonProperty("page")
@Override
public int getNumber() {
return delegate.getNumber();
}
@JsonProperty("page")
@Override
public int getNumber() {
return delegate.getNumber();
}
@JsonProperty
@Override
public int getSize() {
return delegate.getSize();
}
@JsonProperty
@Override
public int getSize() {
return delegate.getSize();
}
@JsonProperty
@Override
public int getNumberOfElements() {
return delegate.getNumberOfElements();
}
@JsonProperty
@Override
public int getNumberOfElements() {
return delegate.getNumberOfElements();
}
@JsonProperty
@Override
public List<T> getContent() {
return delegate.getContent();
}
@JsonProperty
@Override
public List<T> getContent() {
return delegate.getContent();
}
@JsonProperty
@Override
public boolean hasContent() {
return delegate.hasContent();
}
@JsonProperty
@Override
public boolean hasContent() {
return delegate.hasContent();
}
@JsonIgnore
@Override
public Sort getSort() {
return delegate.getSort();
}
@JsonIgnore
@Override
public Sort getSort() {
return delegate.getSort();
}
@JsonProperty
@Override
public boolean isFirst() {
return delegate.isFirst();
}
@JsonProperty
@Override
public boolean isFirst() {
return delegate.isFirst();
}
@JsonProperty
@Override
public boolean isLast() {
return delegate.isLast();
}
@JsonProperty
@Override
public boolean isLast() {
return delegate.isLast();
}
@JsonIgnore
@Override
public boolean hasNext() {
return delegate.hasNext();
}
@JsonIgnore
@Override
public boolean hasNext() {
return delegate.hasNext();
}
@JsonIgnore
@Override
public boolean hasPrevious() {
return delegate.hasPrevious();
}
@JsonIgnore
@Override
public boolean hasPrevious() {
return delegate.hasPrevious();
}
@JsonIgnore
@Override
public Pageable nextPageable() {
return delegate.nextPageable();
}
@JsonIgnore
@Override
public Pageable nextPageable() {
return delegate.nextPageable();
}
@JsonIgnore
@Override
public Pageable previousPageable() {
return delegate.previousPageable();
}
@JsonIgnore
@Override
public <S> Page<S> map(Function<? super T, ? extends S> converter) {
return delegate.map(converter);
}
@JsonIgnore
@Override
public Pageable previousPageable() {
return delegate.previousPageable();
}
@JsonIgnore
@Override
public Iterator<T> iterator() {
return delegate.iterator();
}
}
}
@JsonIgnore
@Override
public <S> Page<S> map(Function<? super T, ? extends S> converter) {
return delegate.map(converter);
}
@JsonIgnore
@Override
public Iterator<T> iterator() {
return delegate.iterator();
}
}
}

View File

@@ -21,13 +21,13 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import feign.RequestTemplate;
import feign.codec.EncodeException;
import feign.codec.Encoder;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
/**
* Provides support for encoding spring Pageable via composition.
*
@@ -35,54 +35,63 @@ import feign.codec.Encoder;
*/
public class PageableSpringEncoder implements Encoder {
private final Encoder delegate;
private final Encoder delegate;
/**
* Creates a new PageableSpringEncoder with the given delegate for fallback.
* If no delegate is provided and this encoder cant handle the request,
* an EncodeException is thrown.
* @param delegate The optional delegate.
*/
public PageableSpringEncoder(Encoder delegate){
this.delegate = delegate;
}
/**
* Creates a new PageableSpringEncoder with the given delegate for fallback. If no
* delegate is provided and this encoder cant handle the request, an EncodeException
* is thrown.
* @param delegate The optional delegate.
*/
public PageableSpringEncoder(Encoder delegate) {
this.delegate = delegate;
}
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template)
throws EncodeException {
if (supports(object)) {
if (object instanceof Pageable) {
Pageable pageable = (Pageable) object;
template.query("page", pageable.getPageNumber() + "");
template.query("size", pageable.getPageSize() + "");
if (pageable.getSort() != null) {
applySort(template, pageable.getSort());
}
} else if (object instanceof Sort) {
Sort sort = (Sort)object;
applySort(template, sort);
}
} else {
if (delegate != null) {
delegate.encode(object, bodyType, template);
} else {
throw new EncodeException("PageableSpringEncoder does not support the given object " + object.getClass() + " and no delegate was provided for fallback!");
}
}
}
if (supports(object)) {
if (object instanceof Pageable) {
Pageable pageable = (Pageable) object;
template.query("page", pageable.getPageNumber() + "");
template.query("size", pageable.getPageSize() + "");
if (pageable.getSort() != null) {
applySort(template, pageable.getSort());
}
}
else if (object instanceof Sort) {
Sort sort = (Sort) object;
applySort(template, sort);
}
}
else {
if (delegate != null) {
delegate.encode(object, bodyType, template);
}
else {
throw new EncodeException(
"PageableSpringEncoder does not support the given object "
+ object.getClass()
+ " and no delegate was provided for fallback!");
}
}
}
private void applySort(RequestTemplate template, Sort sort) {
Collection<String> existingSorts = template.queries().get("sort");
List<String> sortQueries = existingSorts != null ? new ArrayList<>(existingSorts) : new ArrayList<>();
for (Sort.Order order : sort) {
sortQueries.add(order.getProperty() + "," + order.getDirection());
}
if(!sortQueries.isEmpty()) {
template.query("sort", sortQueries);
}
}
private void applySort(RequestTemplate template, Sort sort) {
Collection<String> existingSorts = template.queries().get("sort");
List<String> sortQueries = existingSorts != null ? new ArrayList<>(existingSorts)
: new ArrayList<>();
for (Sort.Order order : sort) {
sortQueries.add(order.getProperty() + "," + order.getDirection());
}
if (!sortQueries.isEmpty()) {
template.query("sort", sortQueries);
}
}
protected boolean supports(Object object) {
return object instanceof Pageable || object instanceof Sort;
}
protected boolean supports(Object object) {
return object instanceof Pageable || object instanceof Sort;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,7 +12,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.springframework.cloud.openfeign;
@@ -20,6 +19,7 @@ package org.springframework.cloud.openfeign;
import feign.codec.Encoder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
@@ -44,13 +44,15 @@ public class EnableFeignClientsSpringDataTests {
@Test
public void encoderDefaultCorrect() {
PageableSpringEncoder.class.cast(this.feignContext.getInstance("foo", Encoder.class));
PageableSpringEncoder.class
.cast(this.feignContext.getInstance("foo", Encoder.class));
}
@Configuration
@Import({ PropertyPlaceholderAutoConfiguration.class, ArchaiusAutoConfiguration.class,
FeignAutoConfiguration.class })
protected static class PlainConfiguration {
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,6 @@
package org.springframework.cloud.openfeign;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import feign.Contract;
import feign.Feign;
import feign.Logger;
@@ -29,7 +23,13 @@ import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.optionals.OptionalDecoder;
import feign.slf4j.Slf4jLogger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.cloud.openfeign.support.SpringMvcContract;
@@ -43,7 +43,7 @@ import org.springframework.context.annotation.Import;
* @author Spencer Gibb
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({"spring-data-commons-*.jar"})
@ClassPathExclusions({ "spring-data-commons-*.jar" })
public class EnableFeignClientsTests {
private ConfigurableApplicationContext context;
@@ -57,16 +57,14 @@ public class EnableFeignClientsTests {
@After
public void tearDown() {
if(context != null) {
if (context != null) {
context.close();
}
}
@Test
public void decoderDefaultCorrect() {
OptionalDecoder.class
.cast(this.context.getBeansOfType(Decoder.class).get(0));
OptionalDecoder.class.cast(this.context.getBeansOfType(Decoder.class).get(0));
}
@Test
@@ -76,24 +74,21 @@ public class EnableFeignClientsTests {
@Test
public void loggerDefaultCorrect() {
Slf4jLogger.class.cast(this.context.getBeansOfType( Logger.class).get(0));
Slf4jLogger.class.cast(this.context.getBeansOfType(Logger.class).get(0));
}
@Test
public void contractDefaultCorrect() {
SpringMvcContract.class
.cast(this.context.getBeansOfType(Contract.class).get(0));
SpringMvcContract.class.cast(this.context.getBeansOfType(Contract.class).get(0));
}
@Test
public void builderDefaultCorrect() {
Feign.Builder.class
.cast(this.context.getBeansOfType(Feign.Builder.class).get(0));
Feign.Builder.class.cast(this.context.getBeansOfType(Feign.Builder.class).get(0));
}
@Configuration
@Import({ ArchaiusAutoConfiguration.class,
FeignAutoConfiguration.class })
@Import({ ArchaiusAutoConfiguration.class, FeignAutoConfiguration.class })
protected static class PlainConfiguration {
}

View File

@@ -16,11 +16,14 @@
package org.springframework.cloud.openfeign.encoding;
import java.util.Collections;
import com.netflix.loadbalancer.BaseLoadBalancer;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -44,17 +47,15 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests the pagination encoding.
*
* @author Charlie Mordant.
*/
@SpringBootTest(classes = FeignPageableEncodingTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
@SpringBootTest(classes = FeignPageableEncodingTests.Application.class,
webEnvironment = WebEnvironment.RANDOM_PORT, value = {
"feign.compression.request.enabled=true",
"hystrix.command.default.execution.isolation.strategy=SEMAPHORE",
"ribbon.OkToRetryOnAllOperations=false" })
@@ -68,17 +69,17 @@ public class FeignPageableEncodingTests {
public void testPageable() {
// given
Pageable pageable = PageRequest.of(0,10, Sort.Direction.ASC, "sortProperty");
Pageable pageable = PageRequest.of(0, 10, Sort.Direction.ASC, "sortProperty");
// when
final ResponseEntity<Page<Invoice>> response = this.invoiceClient
.getInvoicesPaged(pageable);
// then
assertNotNull(response);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertNotNull(response.getBody());
assertEquals(pageable.getPageSize(), response.getBody().getSize());
assertThat(response).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).isNotNull();
assertThat(pageable.getPageSize()).isEqualTo(response.getBody().getSize());
}
@@ -86,8 +87,9 @@ public class FeignPageableEncodingTests {
@RibbonClient(name = "local", configuration = LocalRibbonClientConfiguration.class)
@SpringBootApplication(scanBasePackages = "org.springframework.cloud.openfeign.encoding.app")
@EnableSpringDataWebSupport
@Import({NoSecurityConfiguration.class, FeignClientsConfiguration.class})
@Import({ NoSecurityConfiguration.class, FeignClientsConfiguration.class })
public static class Application {
}
@Configuration
@@ -103,6 +105,7 @@ public class FeignPageableEncodingTests {
Collections.singletonList(new Server("localhost", this.port)));
return balancer;
}
}
}
}

View File

@@ -35,7 +35,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
public interface InvoiceClient {
@RequestMapping(value = "invoicesPaged", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<Page<Invoice>> getInvoicesPaged(org.springframework.data.domain.Pageable pageable);
ResponseEntity<Page<Invoice>> getInvoicesPaged(
org.springframework.data.domain.Pageable pageable);
@RequestMapping(value = "invoices", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<List<Invoice>> getInvoices();

View File

@@ -52,8 +52,10 @@ public class InvoiceResource {
}
@RequestMapping(value = "invoicesPaged", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Page<Invoice>> getInvoicesPaged(org.springframework.data.domain.Pageable pageable) {
Page<Invoice> page = new PageImpl<>(createInvoiceList(pageable.getPageSize()), pageable, 100);
public ResponseEntity<Page<Invoice>> getInvoicesPaged(
org.springframework.data.domain.Pageable pageable) {
Page<Invoice> page = new PageImpl<>(createInvoiceList(pageable.getPageSize()),
pageable, 100);
return ResponseEntity.ok(page);
}

View File

@@ -1,19 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* * Copyright 2013-2016 the original author or authors.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.openfeign.support;
@@ -22,6 +20,7 @@ import feign.RequestTemplate;
import feign.codec.Encoder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.openfeign.FeignContext;
@@ -31,12 +30,7 @@ import org.springframework.data.domain.Sort;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests the pagination encoding and sorting.
@@ -44,85 +38,78 @@ import static org.junit.Assert.assertThat;
* @author Charlie Mordant.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SpringEncoderTests.Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = {
"spring.application.name=springencodertest", "spring.jmx.enabled=false" })
@SpringBootTest(classes = SpringEncoderTests.Application.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = {
"spring.application.name=springencodertest", "spring.jmx.enabled=false" })
@DirtiesContext
public class PageableEncoderTests {
public static final int PAGE = 1;
public static final int SIZE = 10;
public static final String SORT_2 = "sort2";
public static final String SORT_1 = "sort1";
@Autowired
private FeignContext context;
public static final int PAGE = 1;
@Test
public void testPaginationAndSortingRequest() {
Encoder encoder = this.context.getInstance("foo", Encoder.class);
assertThat(encoder, is(notNullValue()));
RequestTemplate request = new RequestTemplate();
public static final int SIZE = 10;
encoder.encode(createPageAndSortRequest(), null, request);
public static final String SORT_2 = "sort2";
assertThat("Request queries shall contain three entries",
request.queries().size(),
equalTo(3));
assertThat("Request page shall contain page",
request.queries().get("page"),
hasItem(String.valueOf(PAGE)));
assertThat("Request size shall contain size",
request.queries().get("size"),
hasItem(String.valueOf(SIZE)));
assertThat("Request sort size shall contain sort entries",
request.queries().get("sort").size(),
equalTo(2));
}
public static final String SORT_1 = "sort1";
private Pageable createPageAndSortRequest() {
return PageRequest.of(PAGE, SIZE, Sort.Direction.ASC, SORT_1, SORT_2);
}
@Autowired
private FeignContext context;
@Test
public void testPaginationRequest() {
Encoder encoder = this.context.getInstance("foo", Encoder.class);
assertThat(encoder, is(notNullValue()));
RequestTemplate request = new RequestTemplate();
encoder.encode(createPageAndRequest(), null, request);
assertThat("Request queries shall contain three entries",
request.queries().size(),
equalTo(2));
assertThat("Request page shall contain page",
request.queries().get("page"),
hasItem(String.valueOf(PAGE)));
assertThat("Request size shall contain size",
request.queries().get("size"),
hasItem(String.valueOf(SIZE)));
assertThat("Request sort size shall contain sort entries",
request.queries().containsKey("sort"),
equalTo(false));
}
@Test
public void testPaginationAndSortingRequest() {
Encoder encoder = this.context.getInstance("foo", Encoder.class);
assertThat(encoder).isNotNull();
RequestTemplate request = new RequestTemplate();
encoder.encode(createPageAndSortRequest(), null, request);
private Pageable createPageAndRequest() {
return PageRequest.of(PAGE, SIZE);
}
// Request queries shall contain three entries
assertThat(request.queries().size()).isEqualTo(3);
// Request page shall contain page
assertThat(request.queries().get("page")).contains(String.valueOf(PAGE));
// Request size shall contain size
assertThat(request.queries().get("size")).contains(String.valueOf(SIZE));
// Request sort size shall contain sort entries
assertThat(request.queries().get("sort").size()).isEqualTo(2);
}
@Test
public void testSortingRequest() {
Encoder encoder = this.context.getInstance("foo", Encoder.class);
assertThat(encoder, is(notNullValue()));
RequestTemplate request = new RequestTemplate();
private Pageable createPageAndSortRequest() {
return PageRequest.of(PAGE, SIZE, Sort.Direction.ASC, SORT_1, SORT_2);
}
encoder.encode(createSort(), null, request);
@Test
public void testPaginationRequest() {
Encoder encoder = this.context.getInstance("foo", Encoder.class);
assertThat(encoder).isNotNull();
RequestTemplate request = new RequestTemplate();
encoder.encode(createPageAndRequest(), null, request);
assertThat(request.queries().size()).isEqualTo(2);
// Request page shall contain page
assertThat(request.queries().get("page")).contains(String.valueOf(PAGE));
// Request size shall contain size
assertThat(request.queries().get("size")).contains(String.valueOf(SIZE));
// Request sort size shall contain sort entries
assertThat(request.queries().containsKey("sort")).isEqualTo(false);
}
assertThat("Request queries shall contain three entries",
request.queries().size(),
equalTo(1));
assertThat("Request sort size shall contain sort entries",
request.queries().get("sort").size(),
equalTo(2));
}
private Pageable createPageAndRequest() {
return PageRequest.of(PAGE, SIZE);
}
private Sort createSort() {
return Sort.by(SORT_1, SORT_2).ascending();
}
}
@Test
public void testSortingRequest() {
Encoder encoder = this.context.getInstance("foo", Encoder.class);
assertThat(encoder).isNotNull();
RequestTemplate request = new RequestTemplate();
encoder.encode(createSort(), null, request);
// Request queries shall contain three entries
assertThat(request.queries().size()).isEqualTo(1);
// Request sort size shall contain sort entries
assertThat(request.queries().get("sort").size()).isEqualTo(2);
}
private Sort createSort() {
return Sort.by(SORT_1, SORT_2).ascending();
}
}

View File

@@ -12,7 +12,8 @@
<suppress files=".*LoadBalancerFeignClientOverrideTests.*" checks="LineLengthCheck" />
<suppress files=".*ProtobufSpringEncoderTest.*" checks="LineLengthCheck" />
<suppress files=".*ProtobufTest.*" checks="LineLengthCheck" />
<suppress files=".*FeignPageableEncodingTests.*" checks="LineLengthCheck" />
<suppress files=".*PageableEncoderTests.*" checks="LineLengthCheck" />
<!-- Important -->
<suppress files=".*HttpEncoding.*" checks="InterfaceIsTypeCheck" />
</suppressions>