Search in sources :

Example 6 with PagedLinksInformation

use of io.crnk.core.resource.links.PagedLinksInformation in project crnk-framework by crnk-project.

the class HasNextBasedPagedLinksInformationTest method testNoPaging.

@Test
public void testNoPaging() throws InstantiationException, IllegalAccessException {
    QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(), resourceRegistry);
    JsonApiResponse results = adapter.findAll(querySpec);
    HasMoreResourcesMetaInformation metaInformation = (HasMoreResourcesMetaInformation) results.getMetaInformation();
    Assert.assertNull(metaInformation.getHasMoreResources());
    PagedLinksInformation linksInformation = (PagedLinksInformation) results.getLinksInformation();
    Assert.assertNull(linksInformation);
}
Also used : HasMoreResourcesMetaInformation(io.crnk.core.resource.meta.HasMoreResourcesMetaInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 7 with PagedLinksInformation

use of io.crnk.core.resource.links.PagedLinksInformation in project crnk-framework by crnk-project.

the class TotalBasedPagedLinksInformationTest method testPaging.

@Test
public void testPaging() throws InstantiationException, IllegalAccessException {
    QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(2L, 2L), resourceRegistry);
    PagedLinksInformation linksInformation = (PagedLinksInformation) adapter.findAll(querySpec).getLinksInformation();
    Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=2", linksInformation.getFirst());
    Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=2&page[offset]=4", linksInformation.getLast());
    Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=2", linksInformation.getPrev());
    Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=2&page[offset]=4", linksInformation.getNext());
}
Also used : PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 8 with PagedLinksInformation

use of io.crnk.core.resource.links.PagedLinksInformation in project crnk-framework by crnk-project.

the class TotalBasedPagedLinksInformationTest method testPagingNoContents.

@Test
public void testPagingNoContents() throws InstantiationException, IllegalAccessException {
    TotalResourceCountTestRepository.clear();
    QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(0L, 2L), resourceRegistry);
    PagedLinksInformation linksInformation = (PagedLinksInformation) adapter.findAll(querySpec).getLinksInformation();
    Assert.assertNull(linksInformation.getFirst());
    Assert.assertNull(linksInformation.getLast());
    Assert.assertNull(linksInformation.getPrev());
    Assert.assertNull(linksInformation.getNext());
}
Also used : PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 9 with PagedLinksInformation

use of io.crnk.core.resource.links.PagedLinksInformation in project crnk-framework by crnk-project.

the class HasNextBasedPagedLinksInformationTest method testPagingLast.

@Test
public void testPagingLast() throws InstantiationException, IllegalAccessException {
    QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(4L, 4L), resourceRegistry);
    JsonApiResponse results = adapter.findAll(querySpec);
    HasMoreResourcesMetaInformation metaInformation = (HasMoreResourcesMetaInformation) results.getMetaInformation();
    Assert.assertFalse(metaInformation.getHasMoreResources());
    PagedLinksInformation linksInformation = (PagedLinksInformation) results.getLinksInformation();
    Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=4", linksInformation.getFirst());
    Assert.assertNull(linksInformation.getLast());
    Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=4", linksInformation.getFirst());
    Assert.assertNull(linksInformation.getNext());
}
Also used : HasMoreResourcesMetaInformation(io.crnk.core.resource.meta.HasMoreResourcesMetaInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 10 with PagedLinksInformation

use of io.crnk.core.resource.links.PagedLinksInformation in project crnk-framework by crnk-project.

the class HasNextBasedPagedLinksInformationTest method testPagingFirst.

@Test
public void testPagingFirst() throws InstantiationException, IllegalAccessException {
    QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(0L, 3L), resourceRegistry);
    JsonApiResponse results = adapter.findAll(querySpec);
    HasMoreResourcesMetaInformation metaInformation = (HasMoreResourcesMetaInformation) results.getMetaInformation();
    Assert.assertTrue(metaInformation.getHasMoreResources());
    PagedLinksInformation linksInformation = (PagedLinksInformation) results.getLinksInformation();
    Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=3", linksInformation.getFirst());
    Assert.assertNull(linksInformation.getLast());
    Assert.assertNull(linksInformation.getPrev());
    Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=3&page[offset]=3", linksInformation.getNext());
}
Also used : HasMoreResourcesMetaInformation(io.crnk.core.resource.meta.HasMoreResourcesMetaInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) 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