Search in sources :

Example 1 with PagedMetaInformation

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

the class JpaRelationshipRepositoryTestBase method testFindNulledOneTargetWithLimit.

/**
 * Note that implementation behaves slightly differently with a LIMIT in place. Does only work for single requests.
 */
@Test
public void testFindNulledOneTargetWithLimit() throws InstantiationException, IllegalAccessException {
    long nulledEntityId = numTestEntities - 1;
    QuerySpec querySpec = new QuerySpec(RelatedEntity.class);
    querySpec.setLimit(5L);
    RelatedEntity relatedEntity = repo.findOneTarget(nulledEntityId, TestEntity.ATTR_oneRelatedValue, querySpec);
    Assert.assertNull(relatedEntity);
    ResourceList<RelatedEntity> list = repo.findManyTargets(nulledEntityId, TestEntity.ATTR_oneRelatedValue, querySpec);
    Assert.assertEquals(0, list.size());
    PagedMetaInformation pagedMeta = list.getMeta(PagedMetaInformation.class);
    Assert.assertNotNull(pagedMeta.getTotalResourceCount());
    Assert.assertEquals(Long.valueOf(0L), pagedMeta.getTotalResourceCount());
}
Also used : PagedMetaInformation(io.crnk.core.resource.meta.PagedMetaInformation) RelatedEntity(io.crnk.jpa.model.RelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

Example 2 with PagedMetaInformation

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

the class JpaEntityRepositoryTestBase method testPagingLast.

@Test
public void testPagingLast() throws InstantiationException, IllegalAccessException {
    QuerySpec querySpec = new QuerySpec(TestEntity.class);
    querySpec.setOffset(4L);
    querySpec.setLimit(4L);
    ResourceList<TestEntity> list = repo.findAll(querySpec);
    Assert.assertEquals(1, list.size());
    Assert.assertEquals(4, list.get(0).getId().intValue());
    PagedMetaInformation metaInformation = list.getMeta(PagedMetaInformation.class);
    Assert.assertEquals(5, metaInformation.getTotalResourceCount().longValue());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) PagedMetaInformation(io.crnk.core.resource.meta.PagedMetaInformation) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

Example 3 with PagedMetaInformation

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

the class JpaRelationshipRepositoryTestBase method testGetManyRelationWithPaging.

@Test
public void testGetManyRelationWithPaging() throws InstantiationException, IllegalAccessException {
    TestEntity test = setupManyRelation(Arrays.asList(100L, 101L, 102L, 103L, 104L));
    QuerySpec querySpec = new QuerySpec(TestEntity.class);
    querySpec.setOffset(2L);
    querySpec.setLimit(2L);
    ResourceList<RelatedEntity> list = repo.findManyTargets(test.getId(), TestEntity.ATTR_manyRelatedValues, querySpec);
    Assert.assertEquals(2, list.size());
    Assert.assertEquals(102, list.get(0).getId().intValue());
    Assert.assertEquals(103, list.get(1).getId().intValue());
    PagedMetaInformation metaInformation = list.getMeta(PagedMetaInformation.class);
    Assert.assertEquals(5, metaInformation.getTotalResourceCount().longValue());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) PagedMetaInformation(io.crnk.core.resource.meta.PagedMetaInformation) RelatedEntity(io.crnk.jpa.model.RelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

Example 4 with PagedMetaInformation

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

the class JpaEntityRepositoryTestBase method testPaging.

@Test
public void testPaging() throws InstantiationException, IllegalAccessException {
    QuerySpec querySpec = new QuerySpec(TestEntity.class);
    querySpec.setOffset(2L);
    querySpec.setLimit(2L);
    ResourceList<TestEntity> list = repo.findAll(querySpec);
    Assert.assertEquals(2, list.size());
    Assert.assertEquals(2, list.get(0).getId().intValue());
    Assert.assertEquals(3, list.get(1).getId().intValue());
    PagedMetaInformation metaInformation = list.getMeta(PagedMetaInformation.class);
    Assert.assertEquals(5, metaInformation.getTotalResourceCount().longValue());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) PagedMetaInformation(io.crnk.core.resource.meta.PagedMetaInformation) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

Example 5 with PagedMetaInformation

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

the class JpaEntityRepositoryTestBase method testPagingFirst.

@Test
public void testPagingFirst() throws InstantiationException, IllegalAccessException {
    QuerySpec querySpec = new QuerySpec(TestEntity.class);
    querySpec.setOffset(0L);
    querySpec.setLimit(3L);
    ResourceList<TestEntity> list = repo.findAll(querySpec);
    Assert.assertEquals(3, list.size());
    Assert.assertEquals(0, list.get(0).getId().intValue());
    Assert.assertEquals(1, list.get(1).getId().intValue());
    Assert.assertEquals(2, list.get(2).getId().intValue());
    PagedMetaInformation metaInformation = list.getMeta(PagedMetaInformation.class);
    Assert.assertEquals(5, metaInformation.getTotalResourceCount().longValue());
}
Also used : TestEntity(io.crnk.jpa.model.TestEntity) PagedMetaInformation(io.crnk.core.resource.meta.PagedMetaInformation) Test(org.junit.Test) AbstractJpaTest(io.crnk.jpa.query.AbstractJpaTest)

Aggregations

PagedMetaInformation (io.crnk.core.resource.meta.PagedMetaInformation)9 Test (org.junit.Test)6 AbstractJpaTest (io.crnk.jpa.query.AbstractJpaTest)5 QuerySpec (io.crnk.core.queryspec.QuerySpec)4 TestEntity (io.crnk.jpa.model.TestEntity)4 HasMoreResourcesMetaInformation (io.crnk.core.resource.meta.HasMoreResourcesMetaInformation)3 MetaInformation (io.crnk.core.resource.meta.MetaInformation)3 JpaRequestContext (io.crnk.jpa.internal.JpaRequestContext)2 RelatedEntity (io.crnk.jpa.model.RelatedEntity)2 Task (io.crnk.core.mock.models.Task)1 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