Example usage for org.springframework.data.domain Page getTotalElements

List of usage examples for org.springframework.data.domain Page getTotalElements

Introduction

In this page you can find the example usage for org.springframework.data.domain Page getTotalElements.

Prototype

long getTotalElements();

Source Link

Document

Returns the total amount of elements.

Usage

From source file:uk.ac.ebi.ep.data.repositories.UniprotEntryRepositoryImplTest.java

/**
 * Test of findEnzymesByAccessions method, of class
 * UniprotEntryRepositoryImpl.//from  w w w  .  j a  va 2  s  . c  om
 */
@Test
public void testFindEnzymesByAccessions_List_Pageable() {
    LOGGER.info("findEnzymesByAccessions");
    List<String> accessions = new ArrayList<>();
    accessions.add("Q60991");
    accessions.add("Q63688");
    accessions.add("Q0III2");
    accessions.add("Q64441");
    accessions.add("fakeAccession");

    Pageable pageable = new PageRequest(0, 500, Sort.Direction.ASC, "function", "entryType");

    int expResult = 4;
    Page<EnzymeSummary> result = uniprotEntryRepository.findEnzymesByAccessions(accessions, pageable);

    assertEquals(expResult, result.getContent().size());
    assertEquals(4, result.getTotalElements());
    assertEquals(1, result.getTotalPages());

}

From source file:org.jblogcms.core.post.repository.PostRepositoryItTest.java

@Test
@Transactional/*from w w  w . j  a  v  a  2  s  .  c  o  m*/
public void testFindPostsByBlogIds_OneElementBlogIdArray() throws Exception {
    List<Long> blogIds = Arrays.asList(BLOG_3_ID);
    Page<Post> posts = postRepository.findPostsByBlogIds(blogIds, pageable);

    Assert.assertEquals(2, posts.getTotalElements());

    Assert.assertEquals(POST_1_ID, posts.getContent().get(0).getId());
    Assert.assertEquals(POST_1_TITLE, posts.getContent().get(0).getTitle());
    Assert.assertEquals(POST_1_ACCOUNT_1_ID, posts.getContent().get(0).getAccount().getId());
    Assert.assertEquals(POST_1_ACCOUNT_1_NAME, posts.getContent().get(0).getAccount().getName());

    Assert.assertEquals(POST_2_ID, posts.getContent().get(1).getId());
    Assert.assertEquals(POST_2_TITLE, posts.getContent().get(1).getTitle());
    Assert.assertEquals(POST_2_ACCOUNT_2_ID, posts.getContent().get(1).getAccount().getId());
    Assert.assertEquals(POST_2_ACCOUNT_2_NAME, posts.getContent().get(1).getAccount().getName());
}

From source file:org.jblogcms.core.post.repository.PostRepositoryItTest.java

@Test
@Transactional//from  ww w .jav  a 2s.  c om
public void testFindFavoritePosts_returnOnePost() throws Exception {
    Page<Post> posts = postRepository.findFavoritePosts(ACCOUNT_2_ID, pageable);

    Assert.assertEquals(1, posts.getTotalElements());

    Assert.assertEquals(POST_2_ID, posts.getContent().get(0).getId());
    Assert.assertEquals(POST_2_TITLE, posts.getContent().get(0).getTitle());
    Assert.assertEquals(POST_2_ACCOUNT_2_ID, posts.getContent().get(0).getAccount().getId());
    Assert.assertEquals(POST_2_ACCOUNT_2_NAME, posts.getContent().get(0).getAccount().getName());
    Assert.assertEquals(POST_2_BLOGS_SIZE, posts.getContent().get(0).getBlogs().size());
    Assert.assertTrue(posts.getContent().get(0).getBlogs().containsAll(post2Blogs));

}

From source file:com.github.markserrano.jsonquery.jpa.service.ParentEntityServiceTest.java

@Test
public void testReadAndCount_UsingJoins_WhenParentIsNotFiltered_ButChildIsFiltered() {
    // Scenario 1
    String filter = QueryUtil.init();
    String childFilter = "{\"groupOp\":\"AND\",\"rules\":"
            + "[{\"field\":\"age\",\"op\":\"gt\",\"data\":\"1\"}]" + "}";

    BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter));
    BooleanBuilder childBuilder = childBooleanBuilder.build(new JsonFilter(childFilter));

    Page<Parent> results = service.readAndCount(builder, new PageRequest(0, 3), Parent.class, orderSpecifier,
            childBuilder, "children", Child.class);

    Assert.assertNotNull(results);//from w  w w  .  j av a2  s . c o m
    Assert.assertEquals(6, results.getTotalElements());

    // Scenario 2
    childFilter = "{\"groupOp\":\"AND\",\"rules\":" + "[{\"field\":\"age\",\"op\":\"gt\",\"data\":\"20\"}]"
            + "}";
    childBuilder = childBooleanBuilder.build(new JsonFilter(childFilter));
    results = service.readAndCount(builder, new PageRequest(0, 3), Parent.class, orderSpecifier, childBuilder,
            "children", Child.class);

    Assert.assertNotNull(results);
    Assert.assertEquals(2, results.getTotalElements());
}

From source file:org.jblogcms.core.post.repository.PostRepositoryItTest.java

@Test
@Transactional/*  ww w  .j  a  v  a  2  s.c o m*/
public void testFindPostsByAccountId_returnOnePost() throws Exception {
    Page<Post> posts = postRepository.findPostsByAccountId(ACCOUNT_2_ID, pageable);

    Assert.assertEquals(1, posts.getTotalElements());

    Assert.assertEquals(POST_2_ID, posts.getContent().get(0).getId());
    Assert.assertEquals(POST_2_TITLE, posts.getContent().get(0).getTitle());
    Assert.assertEquals(POST_2_ACCOUNT_2_ID, posts.getContent().get(0).getAccount().getId());
    Assert.assertEquals(POST_2_ACCOUNT_2_NAME, posts.getContent().get(0).getAccount().getName());
    Assert.assertEquals(POST_2_BLOGS_SIZE, posts.getContent().get(0).getBlogs().size());
    Assert.assertTrue(posts.getContent().get(0).getBlogs().containsAll(post2Blogs));
}

From source file:edu.zipcloud.cloudstreetmarket.core.services.CommunityServiceImpl.java

@Override
public Page<UserActivityDTO> getPublicActivity(Pageable pageable) {
    Page<Action> actions = actionRepository.findAll(pageable);
    List<UserActivityDTO> result = transform(actions);
    return new PageImpl<>(result, pageable, actions.getTotalElements());
}

From source file:com.github.markserrano.jsonquery.jpa.service.ParentEntityServiceTest.java

@Test
public void testReadAndCount_UsingJoins_WhenParentIsFiltered_AndChildIsFiltered_AndPaged() {
    // Scenario 1
    String filter = "{\"groupOp\":\"AND\",\"rules\":"
            + "[{\"field\":\"store\",\"op\":\"ne\",\"data\":\"StoreB\"}]" + "}";
    String childFilter = "{\"groupOp\":\"AND\",\"rules\":"
            + "[{\"field\":\"age\",\"op\":\"gt\",\"data\":\"18\"}]" + "}";

    BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter));
    BooleanBuilder childBuilder = childBooleanBuilder.build(new JsonFilter(childFilter));

    Page<Parent> results = service.readAndCount(builder, new PageRequest(0, 2), Parent.class, orderSpecifier,
            childBuilder, "children", Child.class);

    Assert.assertNotNull(results);//from w w  w.  j a v  a2  s.co m
    Assert.assertEquals(3, results.getTotalElements());
    Assert.assertEquals(1, results.getContent().get(0).getId().intValue());
    Assert.assertEquals(1, results.getContent().get(1).getId().intValue());

    // Scenario 2
    results = service.readAndCount(builder, new PageRequest(1, 2), Parent.class, orderSpecifier, childBuilder,
            "children", Child.class);

    Assert.assertNotNull(results);
    Assert.assertEquals(3, results.getTotalElements());
    Assert.assertEquals(4, results.getContent().get(0).getId().intValue());
}

From source file:org.jblogcms.core.post.repository.PostRepositoryItTest.java

@Test
@Transactional//from   w ww.  j av a2 s  . c o m
public void testFindPostsByAccountId_returnNoPosts() throws Exception {
    Page<Post> posts = postRepository.findPostsByAccountId(ACCOUNT_WITH_NO_POSTS, pageable);

    Assert.assertEquals(0, posts.getTotalElements());
}

From source file:org.jblogcms.core.post.repository.PostRepositoryItTest.java

@Test
@Transactional/*from   w  w w  .  j  a  va  2 s.co  m*/
public void testFindPostsByBlogIds_AFewElementsBlogIdArray() throws Exception {
    List<Long> blogIds = Arrays.asList(BLOG_1_ID, BLOG_2_ID);
    Page<Post> posts = postRepository.findPostsByBlogIds(blogIds, pageable);

    Assert.assertEquals(3, posts.getTotalElements());

    Assert.assertEquals(POST_1_ID, posts.getContent().get(0).getId());
    Assert.assertEquals(POST_1_TITLE, posts.getContent().get(0).getTitle());
    Assert.assertEquals(POST_1_ACCOUNT_1_ID, posts.getContent().get(0).getAccount().getId());
    Assert.assertEquals(POST_1_ACCOUNT_1_NAME, posts.getContent().get(0).getAccount().getName());

    Assert.assertEquals(POST_2_ID, posts.getContent().get(1).getId());
    Assert.assertEquals(POST_2_TITLE, posts.getContent().get(1).getTitle());
    Assert.assertEquals(POST_2_ACCOUNT_2_ID, posts.getContent().get(1).getAccount().getId());
    Assert.assertEquals(POST_2_ACCOUNT_2_NAME, posts.getContent().get(1).getAccount().getName());

    Assert.assertEquals(POST_3_ID, posts.getContent().get(2).getId());
    Assert.assertEquals(POST_3_TITLE, posts.getContent().get(2).getTitle());
    Assert.assertEquals(POST_3_ACCOUNT_1_ID, posts.getContent().get(2).getAccount().getId());
    Assert.assertEquals(POST_3_ACCOUNT_1_NAME, posts.getContent().get(2).getAccount().getName());
}

From source file:org.jblogcms.core.post.repository.PostRepositoryItTest.java

@Test
@Transactional/*  w w w .j a v a2 s .com*/
public void testFindFavoritePosts_returnTwoPosts() throws Exception {
    Page<Post> posts = postRepository.findFavoritePosts(ACCOUNT_1_ID, pageable);

    Assert.assertEquals(2, posts.getTotalElements());

    Assert.assertEquals(POST_1_ID, posts.getContent().get(0).getId());
    Assert.assertEquals(POST_1_TITLE, posts.getContent().get(0).getTitle());
    Assert.assertEquals(POST_1_ACCOUNT_1_ID, posts.getContent().get(0).getAccount().getId());
    Assert.assertEquals(POST_1_ACCOUNT_1_NAME, posts.getContent().get(0).getAccount().getName());
    Assert.assertEquals(POST_1_BLOGS_SIZE, posts.getContent().get(0).getBlogs().size());
    Assert.assertTrue(posts.getContent().get(0).getBlogs().containsAll(post1Blogs));

    Assert.assertEquals(POST_2_ID, posts.getContent().get(1).getId());
    Assert.assertEquals(POST_2_TITLE, posts.getContent().get(1).getTitle());
    Assert.assertEquals(POST_2_ACCOUNT_2_ID, posts.getContent().get(1).getAccount().getId());
    Assert.assertEquals(POST_2_ACCOUNT_2_NAME, posts.getContent().get(1).getAccount().getName());
    Assert.assertEquals(POST_2_BLOGS_SIZE, posts.getContent().get(1).getBlogs().size());
    Assert.assertTrue(posts.getContent().get(0).getBlogs().containsAll(post2Blogs));
}