Search in sources :

Example 1 with HasMoreResourcesMetaInformation

use of io.crnk.core.resource.meta.HasMoreResourcesMetaInformation in project crnk-framework by crnk-project.

the class InMemoryEvaluatorTest method testNextPageMetaInformationIsTrue.

@Test
public void testNextPageMetaInformationIsTrue() {
    QuerySpec spec = new QuerySpec(Task.class);
    DefaultResourceList<Task> results = new DefaultResourceList<>();
    results.setMeta(new DefaultHasMoreResourcesMetaInformation());
    spec.setLimit(2L);
    spec.apply(tasks, results);
    Assert.assertEquals(2, results.size());
    HasMoreResourcesMetaInformation meta = results.getMeta(HasMoreResourcesMetaInformation.class);
    Assert.assertTrue(meta.getHasMoreResources());
}
Also used : Task(io.crnk.core.mock.models.Task) DefaultHasMoreResourcesMetaInformation(io.crnk.core.resource.meta.DefaultHasMoreResourcesMetaInformation) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) HasMoreResourcesMetaInformation(io.crnk.core.resource.meta.HasMoreResourcesMetaInformation) DefaultHasMoreResourcesMetaInformation(io.crnk.core.resource.meta.DefaultHasMoreResourcesMetaInformation) Test(org.junit.Test)

Example 2 with HasMoreResourcesMetaInformation

use of io.crnk.core.resource.meta.HasMoreResourcesMetaInformation in project crnk-framework by crnk-project.

the class InMemoryEvaluatorTest method testNextPageMetaInformationIsFalse.

@Test
public void testNextPageMetaInformationIsFalse() {
    QuerySpec spec = new QuerySpec(Task.class);
    DefaultResourceList<Task> results = new DefaultResourceList<>();
    results.setMeta(new DefaultHasMoreResourcesMetaInformation());
    spec.setLimit(5L);
    spec.apply(tasks, results);
    HasMoreResourcesMetaInformation meta = results.getMeta(HasMoreResourcesMetaInformation.class);
    Assert.assertEquals(5, results.size());
    Assert.assertFalse(meta.getHasMoreResources());
}
Also used : Task(io.crnk.core.mock.models.Task) DefaultHasMoreResourcesMetaInformation(io.crnk.core.resource.meta.DefaultHasMoreResourcesMetaInformation) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) HasMoreResourcesMetaInformation(io.crnk.core.resource.meta.HasMoreResourcesMetaInformation) DefaultHasMoreResourcesMetaInformation(io.crnk.core.resource.meta.DefaultHasMoreResourcesMetaInformation) Test(org.junit.Test)

Example 3 with HasMoreResourcesMetaInformation

use of io.crnk.core.resource.meta.HasMoreResourcesMetaInformation in project crnk-framework by crnk-project.

the class HasNextBasedPagedLinksInformationTest method testPaging.

@Test
public void testPaging() throws InstantiationException, IllegalAccessException {
    QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(2L, 2L), 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]=2", linksInformation.getFirst());
    Assert.assertNull(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 : 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 4 with HasMoreResourcesMetaInformation

use of io.crnk.core.resource.meta.HasMoreResourcesMetaInformation in project crnk-framework by crnk-project.

the class HasNextBasedPagedLinksInformationTest method testPagingNoContents.

@Test
public void testPagingNoContents() throws InstantiationException, IllegalAccessException {
    HasNextPageTestRepository.clear();
    QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(0L, 2L), resourceRegistry);
    JsonApiResponse results = adapter.findAll(querySpec);
    HasMoreResourcesMetaInformation metaInformation = (HasMoreResourcesMetaInformation) results.getMetaInformation();
    Assert.assertFalse(metaInformation.getHasMoreResources());
    PagedLinksInformation linksInformation = (PagedLinksInformation) results.getLinksInformation();
    Assert.assertNull(linksInformation.getFirst());
    Assert.assertNull(linksInformation.getLast());
    Assert.assertNull(linksInformation.getPrev());
    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 5 with HasMoreResourcesMetaInformation

use of io.crnk.core.resource.meta.HasMoreResourcesMetaInformation 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)

Aggregations

HasMoreResourcesMetaInformation (io.crnk.core.resource.meta.HasMoreResourcesMetaInformation)10 Test (org.junit.Test)7 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)5 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)5 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)5 PagedLinksInformation (io.crnk.core.resource.links.PagedLinksInformation)5 MetaInformation (io.crnk.core.resource.meta.MetaInformation)3 PagedMetaInformation (io.crnk.core.resource.meta.PagedMetaInformation)3 Task (io.crnk.core.mock.models.Task)2 QuerySpec (io.crnk.core.queryspec.QuerySpec)2 DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)2 DefaultHasMoreResourcesMetaInformation (io.crnk.core.resource.meta.DefaultHasMoreResourcesMetaInformation)2 JpaRequestContext (io.crnk.jpa.internal.JpaRequestContext)2 ComputedAttributeRegistry (io.crnk.jpa.query.ComputedAttributeRegistry)1 JpaQueryFactory (io.crnk.jpa.query.JpaQueryFactory)1 Tuple (io.crnk.jpa.query.Tuple)1 ArrayList (java.util.ArrayList)1