List of usage examples for org.springframework.data.domain Page getContent
List<T> getContent();
From source file:com.github.markserrano.jsonquery.jpa.service.ParentEntityServiceTest.java
@Test public void testReadAndCount_UsingJoins_WhenParentIsFiltered_AndChildIsFiltered() { 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, 10), Parent.class, orderSpecifier, childBuilder, "children", Child.class); Assert.assertNotNull(results);/* w w w. j a v a 2 s. c om*/ Assert.assertEquals(3, results.getTotalElements()); Assert.assertEquals(1, results.getContent().get(0).getId().intValue()); Assert.assertEquals(1, results.getContent().get(1).getId().intValue()); Assert.assertEquals(4, results.getContent().get(2).getId().intValue()); }
From source file:net.turnbig.jdbcx.test.JdbcxPagingTest.java
@Test public void testQueryPagedListBean() { PageRequest pr = new PageRequest(0, 10); Page<Member> members = jdbc.queryForListBean("select * from member where name like 'batched%'", Member.class, pr); Assert.assertEquals("name like batch get 10 record", members.getSize(), 10); Assert.assertEquals("name like batch get 10 record", members.getTotalElements(), 200); Assert.assertEquals("name like batch get 10 record", members.getTotalPages(), 20); PageRequest pr2 = new PageRequest(1, 20, new Sort(new Order(Direction.ASC, "id"))); Page<Map<String, Object>> members2 = jdbc.queryForListMap("select * from member where name like 'batched%'", pr2);//w ww . j a va 2 s. co m Assert.assertEquals("name like batch get 20 record", members2.getSize(), 20); Assert.assertEquals("name like batch get 200 total", members2.getTotalElements(), 200); Assert.assertEquals("name like batch get 10 pages", members2.getTotalPages(), 10); logger.info("{}", members2.getContent()); Map<String, String> params = new HashMap<String, String>(); params.put("name", "batched%"); members2 = jdbc.queryForListMap("select * from member where name like :name", params, pr2); Assert.assertEquals("name like batch get 20 record", members2.getSize(), 20); Assert.assertEquals("name like batch get 200 total", members2.getTotalElements(), 200); Assert.assertEquals("name like batch get 10 pages", members2.getTotalPages(), 10); logger.info("{}", members2.getContent()); // Map<String, String> params = new HashMap<String, String>(); // params.put("name", "woo"); // List<Member> members2 = jdbc.queryForListBean("select * from member where name = :name", params, Member.class); // Assert.assertEquals("name with woo only 1 record", members2.size(), 1); // // Member member = members.get(0); // Assert.assertEquals("ip should be 127.0.0.1", member.getRegistIp(), "127.0.0.1"); }
From source file:org.jblogcms.core.post.repository.PostRepositoryItTest.java
@Test @Transactional/*from w ww .j a va 2 s . co m*/ public void testFindPosts_returnAllPosts() throws Exception { Page<Post> posts = postRepository.findPosts(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_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(1).getBlogs().containsAll(post2Blogs)); 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()); Assert.assertEquals(POST_3_BLOGS_SIZE, posts.getContent().get(2).getBlogs().size()); Assert.assertTrue(posts.getContent().get(2).getBlogs().containsAll(post3Blogs)); }
From source file:com.ync365.px.web.score.ScoreController.java
@RequestMapping(value = "/score/updateScoreinit/grid", method = RequestMethod.POST) @ResponseBody//w ww. j a v a 2 s . com public Map<String, Object> updateScoreinit(int classId, Paginator page, Model model) { PxClassStudent pxClassStudent = new PxClassStudent(); pxClassStudent.setClassId(classId); Page<PxClassStudent> pxClassStudentlist = pxClassStudentService.getCsinfoByClassIdinPage(pxClassStudent, page); Map<String, Object> map = new HashMap<String, Object>(); map.put("data", pxClassStudentlist.getContent()); map.put("iTotalRecords", pxClassStudentlist.getTotalElements()); map.put("iTotalDisplayRecords", pxClassStudentlist.getTotalElements()); return map; }
From source file:org.jblogcms.core.post.repository.PostRepositoryItTest.java
@Test @Transactional/*from w w w . java 2s. c om*/ public void testFindBlogPosts_returnTwoPost() throws Exception { Page<Post> posts = postRepository.findBlogPosts(BLOG_2_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_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: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);/* ww w. j av a2s .c o 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/* w w w. j a v a2 s. co 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.apereo.openlrs.repositories.statements.ElasticSearchStatementRepository.java
@Override public List<Statement> getByUser(String user) { Page<StatementMetadata> metadata = esStatementMetadataRepository.findByUser(user, new PageRequest(0, 1000)); if (metadata != null && metadata.getContent() != null && !metadata.getContent().isEmpty()) { return map(metadata.getContent()); }//from w w w . j ava 2 s. c o m return null; }
From source file:org.jblogcms.core.post.repository.PostRepositoryItTest.java
@Test @Transactional/*from w ww . j av a2 s .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:org.jblogcms.core.post.repository.PostRepositoryItTest.java
@Test @Transactional/*from w w w .j ava 2s.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)); }