use of io.crnk.core.resource.meta.DefaultPagedMetaInformation in project crnk-framework by crnk-project.
the class QuerySpec method apply.
/**
* Evaluates this querySpec against the provided list in memory. It supports
* sorting, filter and paging.
* <p>
* TODO currently ignores relations and inclusions, has room for
* improvements
*
* @param <T> the type of resources in this Iterable
* @param resources resources
* @return sorted, filtered list.
*/
public <T> DefaultResourceList<T> apply(Iterable<T> resources) {
DefaultResourceList<T> resultList = new DefaultResourceList<>();
resultList.setMeta(new DefaultPagedMetaInformation());
apply(resources, resultList);
return resultList;
}
use of io.crnk.core.resource.meta.DefaultPagedMetaInformation in project crnk-framework by crnk-project.
the class OffsetLimitPagingBehaviorTest method testBuild.
@Test
public void testBuild() {
PagingBehavior pagingBehavior = new OffsetLimitPagingBehavior();
OffsetLimitPagingSpec pagingSpec = new OffsetLimitPagingSpec(0L, 10L);
ModuleRegistry moduleRegistry = new ModuleRegistry();
ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
QuerySpec spec = new QuerySpec(Task.class);
QuerySpecAdapter querySpecAdapter = new QuerySpecAdapter(spec, resourceRegistry);
querySpecAdapter.setPagingSpec(pagingSpec);
PagingSpecUrlBuilder urlBuilder = mock(PagingSpecUrlBuilder.class);
when(urlBuilder.build(any(QuerySpecAdapter.class))).thenReturn("http://some.org");
DefaultPagedMetaInformation pagedMetaInformation = new DefaultPagedMetaInformation();
pagedMetaInformation.setTotalResourceCount(30L);
ResourceList resourceList = new DefaultResourceList(pagedMetaInformation, null);
for (int i = 0; i < 30; i++) {
resourceList.add(new Task());
}
PagedLinksInformation pagedLinksInformation = new DefaultPagedLinksInformation();
pagingBehavior.build(pagedLinksInformation, resourceList, querySpecAdapter, urlBuilder);
assertThat(pagedLinksInformation.getFirst(), equalTo("http://some.org"));
assertThat(pagedLinksInformation.getNext(), equalTo("http://some.org"));
assertNull(pagedLinksInformation.getPrev());
assertThat(pagedLinksInformation.getLast(), equalTo("http://some.org"));
}
Aggregations