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

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

Introduction

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

Prototype

List<T> getContent();

Source Link

Document

Returns the page content as List .

Usage

From source file:org.jblogcms.core.account.service.AccountServiceImplTest.java

@Test
public void findAccountSubscribers() throws Exception {
    when(accountRepositoryMock.findAccountSubscribers(ACCOUNT_ID, pageable)).thenReturn(accounts);
    when(accountToolServiceMock.addItemRelationsToItemPage(accounts, CURRENT_ACCOUNT_ID)).thenReturn(accounts);

    Page<Account> testAccounts = accountService.findAccountSubscribers(ACCOUNT_ID, pageable,
            CURRENT_ACCOUNT_ID);// w w w.  j  ava 2  s.  c o m

    verify(accountRepositoryMock, times(1)).findAccountSubscribers(ACCOUNT_ID, pageable);
    verify(accountToolServiceMock, times(1)).addItemRelationsToItemPage(accounts, CURRENT_ACCOUNT_ID);

    Assert.assertEquals(ACCOUNTS_SIZE, testAccounts.getTotalElements());

    Assert.assertEquals(ACCOUNT_1_ID, testAccounts.getContent().get(0).getId());
    Assert.assertEquals(ACCOUNT_1_EMAIL, testAccounts.getContent().get(0).getEmail());
    Assert.assertEquals(ACCOUNT_2_ID, testAccounts.getContent().get(1).getId());
    Assert.assertEquals(ACCOUNT_2_EMAIL, testAccounts.getContent().get(1).getEmail());
    Assert.assertEquals(ACCOUNT_3_ID, testAccounts.getContent().get(2).getId());
    Assert.assertEquals(ACCOUNT_3_EMAIL, testAccounts.getContent().get(2).getEmail());
}

From source file:org.jblogcms.core.blog.service.BlogServiceImplTest.java

@Test
public void testFindBlogs() throws Exception {

    when(blogRepositoryMock.findBlogs(pageable)).thenReturn(blogs);
    when(blogToolServiceMock.addItemRelationsToItemPage(blogs, CURRENT_ACCOUNT_ID)).thenReturn(blogs);

    Page<Blog> testBlogs = blogService.findBlogs(pageable, CURRENT_ACCOUNT_ID);

    verify(blogRepositoryMock, times(1)).findBlogs(pageable);
    verify(blogToolServiceMock, times(1)).addItemRelationsToItemPage(blogs, CURRENT_ACCOUNT_ID);

    Assert.assertEquals(BLOGS_SIZE, testBlogs.getTotalElements());

    Assert.assertEquals(BLOG_1_ID, testBlogs.getContent().get(0).getId());
    Assert.assertEquals(BLOG_1_NAME, testBlogs.getContent().get(0).getName());
    Assert.assertEquals(BLOG_1_URL_NAME, testBlogs.getContent().get(0).getUrlName());

    Assert.assertEquals(BLOG_2_ID, testBlogs.getContent().get(1).getId());
    Assert.assertEquals(BLOG_2_NAME, testBlogs.getContent().get(1).getName());
    Assert.assertEquals(BLOG_2_URL_NAME, testBlogs.getContent().get(1).getUrlName());

    Assert.assertEquals(BLOG_3_ID, testBlogs.getContent().get(2).getId());
    Assert.assertEquals(BLOG_3_NAME, testBlogs.getContent().get(2).getName());
    Assert.assertEquals(BLOG_3_URL_NAME, testBlogs.getContent().get(2).getUrlName());
}

From source file:org.jblogcms.core.post.service.PostServiceImplTest.java

@Test
public void findPosts() throws Exception {
    when(postRepositoryMock.findPosts(pageable)).thenReturn(posts);
    when(postToolServiceMock.addItemRelationsToItemPage(posts, CURRENT_ACCOUNT_ID)).thenReturn(posts);
    when(postToolServiceMock.addItemRatesToItemPage(posts, CURRENT_ACCOUNT_ID)).thenReturn(posts);

    Page<Post> testPosts = postService.findPosts(pageable, CURRENT_ACCOUNT_ID);

    verify(postRepositoryMock, times(1)).findPosts(pageable);
    verify(postToolServiceMock, times(1)).addItemRelationsToItemPage(posts, CURRENT_ACCOUNT_ID);
    verify(postToolServiceMock, times(1)).addItemRatesToItemPage(posts, CURRENT_ACCOUNT_ID);

    Assert.assertEquals(POSTS_SIZE, testPosts.getTotalElements());

    Assert.assertEquals(POST_1_ID, testPosts.getContent().get(0).getId());
    Assert.assertEquals(POST_1_TITLE, testPosts.getContent().get(0).getTitle());

    Assert.assertEquals(POST_2_ID, testPosts.getContent().get(1).getId());
    Assert.assertEquals(POST_2_TITLE, testPosts.getContent().get(1).getTitle());

    Assert.assertEquals(POST_3_ID, testPosts.getContent().get(2).getId());
    Assert.assertEquals(POST_3_TITLE, testPosts.getContent().get(2).getTitle());
}

From source file:com.netflix.genie.core.jpa.services.JpaJobSearchServiceImplIntegrationTests.java

/**
 * Make sure we can search jobs successfully.
 */// www. j a va  2  s . c o m
@Test
public void canFindJobs() {
    //TODO: add more cases
    final Pageable page = new PageRequest(0, 10, Sort.Direction.DESC, "updated");
    Page<JobSearchResult> jobs = this.service.findJobs(null, null, null, null, null, null, null, null, null,
            null, null, null, null, page);
    Assert.assertThat(jobs.getTotalElements(), Matchers.is(3L));

    jobs = this.service.findJobs(null, null, null, Sets.newHashSet(JobStatus.RUNNING), null, null, null, null,
            null, null, null, null, null, page);
    Assert.assertThat(jobs.getTotalElements(), Matchers.is(1L));
    Assert.assertThat(jobs.getContent().stream().filter(job -> job.getId().equals(JOB_3_ID)).count(),
            Matchers.is(1L));

    jobs = this.service.findJobs(JOB_1_ID, null, null, null, null, null, null, null, null, null, null, null,
            null, page);
    Assert.assertThat(jobs.getTotalElements(), Matchers.is(1L));
    Assert.assertThat(jobs.getContent().stream().filter(job -> job.getId().equals(JOB_1_ID)).count(),
            Matchers.is(1L));
}

From source file:org.wallride.service.ArticleService.java

@Cacheable(value = WallRideCacheConfiguration.ARTICLE_CACHE)
public SortedSet<Article> getLatestArticles(String language, Post.Status status, int size) {
    ArticleSearchRequest request = new ArticleSearchRequest().withLanguage(language).withStatus(status);

    Pageable pageable = new PageRequest(0, size);
    Page<Article> page = articleRepository.search(request, pageable);
    return new TreeSet<>(page.getContent());
}

From source file:org.wallride.service.ArticleService.java

@Cacheable(value = WallRideCacheConfiguration.ARTICLE_CACHE)
public SortedSet<Article> getArticlesByCategoryCode(String language, String code, Post.Status status,
        int size) {
    ArticleSearchRequest request = new ArticleSearchRequest().withLanguage(language).withCategoryCodes(code)
            .withStatus(status);//from w  w w  .j av  a2  s .  c o m

    Pageable pageable = new PageRequest(0, size);
    Page<Article> page = articleRepository.search(request, pageable);
    return new TreeSet<>(page.getContent());
}

From source file:com.github.jens_meiss.blog.server.service.impl.BlogServiceImpl.java

@Secured("IS_AUTHENTICATED_ANONYMOUSLY")
@Override/*  www.java 2s .c  o  m*/
public List<PopularBlogDTO> getPopularBlogs(final int startIndex, final int length) {

    logger.debug("getPopularBlogs");

    final Page<BlogEntity> page = blogRepository.findAll(
            new PageRequest(startIndex, length, new Sort(new Sort.Order(Direction.DESC, "visitsPerDay"),
                    new Sort.Order(Direction.DESC, "dateLastUpdated"))));

    final List<PopularBlogDTO> popularBlogs = blogEntryToPopularBlogDTO(page.getContent());

    final PopulardBlogDTOImpl popularBlogDTO = new PopulardBlogDTOImpl();
    popularBlogDTO.setAuthor("author");
    popularBlogDTO.setDateLastUpdate(new Date(System.currentTimeMillis() + 1000));
    popularBlogDTO.setPath("path");
    popularBlogDTO.setPreview("preview");
    popularBlogDTO.setTitle("title");
    popularBlogDTO.setVisitsPerDay(12345);

    popularBlogs.add(popularBlogDTO);

    return popularBlogs;
}

From source file:org.jblogcms.core.blog.service.BlogServiceImplTest.java

@Test
public void testFindFavoriteBlogs() throws Exception {

    when(blogRepositoryMock.findFavoriteBlogs(ACCOUNT_ID, pageable)).thenReturn(blogs);
    when(blogToolServiceMock.addItemRelationsToItemPage(blogs, CURRENT_ACCOUNT_ID)).thenReturn(blogs);

    Page<Blog> testBlogs = blogService.findFavoriteBlogs(ACCOUNT_ID, pageable, CURRENT_ACCOUNT_ID);

    verify(blogRepositoryMock, times(1)).findFavoriteBlogs(ACCOUNT_ID, pageable);
    verify(blogToolServiceMock, times(1)).addItemRelationsToItemPage(blogs, CURRENT_ACCOUNT_ID);

    Assert.assertEquals(BLOGS_SIZE, testBlogs.getTotalElements());

    Assert.assertEquals(BLOG_1_ID, testBlogs.getContent().get(0).getId());
    Assert.assertEquals(BLOG_1_NAME, testBlogs.getContent().get(0).getName());
    Assert.assertEquals(BLOG_1_URL_NAME, testBlogs.getContent().get(0).getUrlName());

    Assert.assertEquals(BLOG_2_ID, testBlogs.getContent().get(1).getId());
    Assert.assertEquals(BLOG_2_NAME, testBlogs.getContent().get(1).getName());
    Assert.assertEquals(BLOG_2_URL_NAME, testBlogs.getContent().get(1).getUrlName());

    Assert.assertEquals(BLOG_3_ID, testBlogs.getContent().get(2).getId());
    Assert.assertEquals(BLOG_3_NAME, testBlogs.getContent().get(2).getName());
    Assert.assertEquals(BLOG_3_URL_NAME, testBlogs.getContent().get(2).getUrlName());
}

From source file:org.jblogcms.core.post.service.PostServiceImplTest.java

@Test
public void findFavoritePosts() throws Exception {
    when(postRepositoryMock.findFavoritePosts(ACCOUNT_ID, pageable)).thenReturn(posts);
    when(postToolServiceMock.addItemRelationsToItemPage(posts, CURRENT_ACCOUNT_ID)).thenReturn(posts);
    when(postToolServiceMock.addItemRatesToItemPage(posts, CURRENT_ACCOUNT_ID)).thenReturn(posts);

    Page<Post> testPosts = postService.findFavoritePosts(ACCOUNT_ID, pageable, CURRENT_ACCOUNT_ID);

    verify(postRepositoryMock, times(1)).findFavoritePosts(ACCOUNT_ID, pageable);
    verify(postToolServiceMock, times(1)).addItemRelationsToItemPage(posts, CURRENT_ACCOUNT_ID);
    verify(postToolServiceMock, times(1)).addItemRatesToItemPage(posts, CURRENT_ACCOUNT_ID);

    Assert.assertEquals(POSTS_SIZE, testPosts.getTotalElements());

    Assert.assertEquals(POST_1_ID, testPosts.getContent().get(0).getId());
    Assert.assertEquals(POST_1_TITLE, testPosts.getContent().get(0).getTitle());

    Assert.assertEquals(POST_2_ID, testPosts.getContent().get(1).getId());
    Assert.assertEquals(POST_2_TITLE, testPosts.getContent().get(1).getTitle());

    Assert.assertEquals(POST_3_ID, testPosts.getContent().get(2).getId());
    Assert.assertEquals(POST_3_TITLE, testPosts.getContent().get(2).getTitle());
}

From source file:com.ethlo.geodata.GeodataServiceImpl.java

@Override
public GeoLocation findbyCoordinate(Coordinates point, int distance) {
    GeoLocation location = findWithin(point, distance);

    // Fall back to nearest match
    if (location == null) {
        final Page<GeoLocationDistance> nearest = findNear(point, distance, new PageRequest(0, 1));
        location = nearest.hasContent() ? nearest.getContent().get(0).getLocation() : null;
    }/*from  w  w  w  . j  a va 2  s  .c  o m*/

    if (location != null) {
        return location;
    }
    throw new EmptyResultDataAccessException(
            "Cannot find a location for position lat=" + point.getLat() + ", lng=" + point.getLng(), 1);
}