Search in sources :

Example 11 with PagedLinksInformation

use of io.crnk.core.resource.links.PagedLinksInformation 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"));
}
Also used : Task(io.crnk.core.mock.models.Task) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) DefaultPagedMetaInformation(io.crnk.core.resource.meta.DefaultPagedMetaInformation) ResourceList(io.crnk.core.resource.list.ResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Aggregations

PagedLinksInformation (io.crnk.core.resource.links.PagedLinksInformation)11 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)10 Test (org.junit.Test)10 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)9 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)5 HasMoreResourcesMetaInformation (io.crnk.core.resource.meta.HasMoreResourcesMetaInformation)5 DefaultPagedLinksInformation (io.crnk.core.resource.links.DefaultPagedLinksInformation)2 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)1 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)1 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)1 Task (io.crnk.core.mock.models.Task)1 ModuleRegistry (io.crnk.core.module.ModuleRegistry)1 QuerySpec (io.crnk.core.queryspec.QuerySpec)1 PagingSpecUrlBuilder (io.crnk.core.queryspec.pagingspec.PagingSpecUrlBuilder)1 DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)1 ResourceList (io.crnk.core.resource.list.ResourceList)1 DefaultPagedMetaInformation (io.crnk.core.resource.meta.DefaultPagedMetaInformation)1