|
1 | 1 | /*
|
2 |
| - * Copyright 2013-2015 the original author or authors. |
| 2 | + * Copyright 2013-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
22 | 22 | import java.util.Arrays;
|
23 | 23 | import java.util.Collection;
|
24 | 24 | import java.util.Collections;
|
| 25 | +import java.util.List; |
25 | 26 | import java.util.Map;
|
26 | 27 |
|
27 | 28 | import org.junit.Before;
|
|
33 | 34 | import org.springframework.data.domain.Pageable;
|
34 | 35 | import org.springframework.hateoas.Link;
|
35 | 36 | import org.springframework.hateoas.PagedResources;
|
| 37 | +import org.springframework.hateoas.PagedResources.PageMetadata; |
36 | 38 | import org.springframework.hateoas.Resource;
|
37 | 39 | import org.springframework.hateoas.ResourceAssembler;
|
38 | 40 | import org.springframework.hateoas.ResourceSupport;
|
@@ -273,6 +275,18 @@ public void alwaysAddsFirstAndLastLinkIfConfiguredTo() {
|
273 | 275 | assertThat(resources.getLink(Link.REL_LAST).getHref(), endsWith("?page=0&size=20"));
|
274 | 276 | }
|
275 | 277 |
|
| 278 | + /** |
| 279 | + * @see DATACMNS-802 |
| 280 | + */ |
| 281 | + @Test |
| 282 | + public void usesCustomPagedResources() { |
| 283 | + |
| 284 | + ResourceAssembler<Page<Person>, PagedResources<Resource<Person>>> assembler = new CustomPagedResourcesAssembler<Person>( |
| 285 | + resolver, null); |
| 286 | + |
| 287 | + assertThat(assembler.toResource(EMPTY_PAGE), is(instanceOf(CustomPagedResources.class))); |
| 288 | + } |
| 289 | + |
276 | 290 | private static Page<Person> createPage(int index) {
|
277 | 291 |
|
278 | 292 | AbstractPageRequest request = new PageRequest(index, 1);
|
@@ -310,4 +324,24 @@ public PersonResource toResource(Person entity) {
|
310 | 324 | return resource;
|
311 | 325 | }
|
312 | 326 | }
|
| 327 | + |
| 328 | + static class CustomPagedResourcesAssembler<T> extends PagedResourcesAssembler<T> { |
| 329 | + |
| 330 | + public CustomPagedResourcesAssembler(HateoasPageableHandlerMethodArgumentResolver resolver, UriComponents baseUri) { |
| 331 | + super(resolver, baseUri); |
| 332 | + } |
| 333 | + |
| 334 | + @Override |
| 335 | + protected <R extends ResourceSupport, S> PagedResources<R> createPagedResource(List<R> resources, |
| 336 | + PageMetadata metadata, Page<S> page) { |
| 337 | + return new CustomPagedResources<R>(resources, metadata); |
| 338 | + } |
| 339 | + } |
| 340 | + |
| 341 | + static class CustomPagedResources<R extends ResourceSupport> extends PagedResources<R> { |
| 342 | + |
| 343 | + public CustomPagedResources(Collection<R> content, PageMetadata metadata) { |
| 344 | + super(content, metadata); |
| 345 | + } |
| 346 | + } |
313 | 347 | }
|
0 commit comments