Search in sources :

Example 26 with DefaultResourceList

use of io.crnk.core.resource.list.DefaultResourceList 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

DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)26 Task (io.crnk.core.mock.models.Task)7 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)6 MultivaluedMap (io.crnk.core.engine.internal.utils.MultivaluedMap)6 ResourceField (io.crnk.core.engine.information.resource.ResourceField)5 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)5 QuerySpec (io.crnk.core.queryspec.QuerySpec)5 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)4 DefaultHasMoreResourcesMetaInformation (io.crnk.core.resource.meta.DefaultHasMoreResourcesMetaInformation)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Test (org.junit.Test)4 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)3 ResourceList (io.crnk.core.resource.list.ResourceList)3 JsonLinksInformation (io.crnk.client.response.JsonLinksInformation)2 JsonMetaInformation (io.crnk.client.response.JsonMetaInformation)2 Resource (io.crnk.core.engine.document.Resource)2 ModuleRegistry (io.crnk.core.module.ModuleRegistry)2 FilterSpec (io.crnk.core.queryspec.FilterSpec)2