List of usage examples for org.springframework.data.domain Page getTotalElements
long getTotalElements();
From source file:org.jblogcms.core.account.service.AccountServiceImplTest.java
@Test public void findFavoriteAccounts() throws Exception { when(accountRepositoryMock.findFavoriteAccounts(ACCOUNT_ID, pageable)).thenReturn(accounts); when(accountToolServiceMock.addItemRelationsToItemPage(accounts, CURRENT_ACCOUNT_ID)).thenReturn(accounts); Page<Account> testAccounts = accountService.findFavoriteAccounts(ACCOUNT_ID, pageable, CURRENT_ACCOUNT_ID); verify(accountRepositoryMock, times(1)).findFavoriteAccounts(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.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);/*from w w w . ja v a 2s . 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:de.hska.ld.content.service.DocumentServiceIntegrationTest.java
@Test public void testGetDocumentTagsPage() { for (int i = 0; i < 21; i++) { tagService.save(newTag());/*from w w w . j a v a 2s.c o m*/ } Page<Tag> tagPage = tagService.getTagsPage(0, 10, "DESC", "createdAt"); Assert.assertNotNull(tagPage); Assert.assertTrue(tagPage.getTotalElements() > 0); Assert.assertTrue(tagPage.getSize() == 10); Document document = documentService.save(newDocument()); documentService.addTag(document.getId(), tagPage.getContent().get(0).getId()); Page<Tag> documentTagsPage = documentService.getDocumentTagsPage(document.getId(), 0, 10, "DESC", "createdAt"); Assert.assertNotNull(documentTagsPage); Assert.assertTrue(documentTagsPage.getTotalElements() == 1); }
From source file:org.kemri.wellcome.controller.ReportController.java
@RequestMapping(value = Views.ALLLOCATIONS, produces = Views.MEDIA_TYPE_JSON) public @ResponseBody JqgridResponse<LocationDTO> locationRecords(@RequestParam("_search") Boolean search, @RequestParam(value = "filters", required = false) String filters, @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @RequestParam(value = "rows", required = false, defaultValue = "10") Integer rows, @RequestParam(value = "sidx", required = false) String sidx, @RequestParam(value = "sord", required = false) String sord) { Pageable pageRequest = new PageRequest(page - 1, rows); if (search == true) { return getFilteredLocations(filters, pageRequest); }/* ww w . ja va2 s .c om*/ Page<Location> locations = locationRepository.findAll(pageRequest); List<LocationDTO> locationsDTOList = LocationMapper.map(locations); JqgridResponse<LocationDTO> response = new JqgridResponse<LocationDTO>(); response.setRows(locationsDTOList); response.setRecords(Long.valueOf(locations.getTotalElements()).toString()); response.setTotal(Integer.valueOf(locations.getTotalPages()).toString()); response.setPage(Integer.valueOf(locations.getNumber() + 1).toString()); return response; }
From source file:com.thinkbiganalytics.feedmgr.service.feed.FeedModelTransform.java
/** * Convert a spring-data Page to a SearchResult UI object *///from w w w . j ava2 s . co m public SearchResult toSearchResult(Page<UIFeed> page) { SearchResult searchResult = new SearchResultImpl(); searchResult.setData(page.getContent()); searchResult.setRecordsTotal(page.getTotalElements()); searchResult.setRecordsFiltered(page.getTotalElements()); return searchResult; }
From source file:eu.trentorise.game.managers.DBPlayerManager.java
public Page<PlayerState> loadStates(String gameId, Pageable pageable) { StopWatch stopWatch = LogManager.getLogger(StopWatch.DEFAULT_LOGGER_NAME).getAppender("perf-file") != null ? new Log4JStopWatch() : null;// w w w .j a va2 s . c o m if (stopWatch != null) { stopWatch.start("loadStates"); } Page<StatePersistence> states = playerRepo.findByGameId(gameId, pageable); List<PlayerState> result = new ArrayList<PlayerState>(); for (StatePersistence state : states) { result.add(initConceptsStructure(new PlayerState(state), gameId)); } PageImpl<PlayerState> res = new PageImpl<PlayerState>(result, pageable, states.getTotalElements()); if (stopWatch != null) { stopWatch.stop("loadStates", "Loaded states of game " + gameId); } return res; }
From source file:de.hska.ld.content.service.DocumentServiceIntegrationTest.java
@Test @Transactional/* w ww .ja v a 2 s. c om*/ public void testPublicFlagForDocumentsPage() { // 1. Create a document with testUser Document document = documentService.save(newDocument()); // 2. Switch to user "user" User user = userService.findByUsername("user"); setAuthentication(user); // 3. Try to retrieve the document (expected is that the user doesn't see it now) Page<Document> documentsPage = documentService.getDocumentsPage(0, Integer.MAX_VALUE, "DESC", "createdAt"); List<Document> documentList = documentsPage.getContent(); final Document tempDocument = document; List<Document> documentFoundResult = documentList.stream() .filter(d -> tempDocument.getTitle().equals(d.getTitle())).collect(Collectors.toList()); Assert.assertTrue(documentFoundResult.size() == 0); // 4. Switch back to the testUser setAuthentication(testUser); // 5. Make the document public document = documentService.setAccessAll(document.getId(), true); // 6. Switch back to user setAuthentication(user); // 7. Try to retrieve the document again (expected is that the user does have access now) Page<Document> documentsPage2 = documentService.getDocumentsPage(0, Integer.MAX_VALUE, "DESC", "createdAt"); Assert.assertTrue(documentsPage2.getTotalElements() > 0); List<Document> documentList2 = documentsPage2.getContent(); final Document tempDocument2 = document; List<Document> documentFoundResult2 = documentList2.stream() .filter(d -> tempDocument2.getTitle().equals(d.getTitle())).collect(Collectors.toList()); Assert.assertTrue(documentFoundResult2.size() > 0); }
From source file:org.oncoblocks.centromere.jpa.test.JpaRepositoryTests.java
@Test public void findByCriteriaPagedTest() { List<QueryCriteria> searchCriterias = new ArrayList<>(); searchCriterias.add(new QueryCriteria("geneType", "protein-coding")); PageRequest pageRequest = new PageRequest(1, 2); Page<EntrezGene> page = geneRepository.find(searchCriterias, pageRequest); Assert.notNull(page);/*from w w w. j av a 2 s .co m*/ Assert.isTrue(page.getTotalElements() == 3); Assert.isTrue(page.getTotalPages() == 2); List<EntrezGene> genes = page.getContent(); Assert.notNull(genes); Assert.notEmpty(genes); Assert.isTrue(genes.size() == 1); EntrezGene gene = genes.get(0); Assert.notNull(gene); Assert.isTrue(gene.getEntrezGeneId().equals(4L)); }