List of usage examples for org.springframework.data.domain Page getNumberOfElements
int getNumberOfElements();
From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java
@Test public void executesPagedFinderCorrectly() throws Exception { Page<Person> page = repository.findByLastnameLike("*a*", new PageRequest(0, 2, Direction.ASC, "lastname", "firstname")); assertThat(page.isFirst(), is(true)); assertThat(page.isLast(), is(false)); assertThat(page.getNumberOfElements(), is(2)); assertThat(page, hasItems(carter, stefan)); }
From source file:nu.yona.server.subscriptions.service.BuddyService.java
private void processPossiblePendingBuddyResponseMessage(User userEntity, Buddy buddy) { int page = 0; final int pageSize = 50; Page<Message> messagePage;/*from w w w.j a v a 2 s .co m*/ boolean messageFound = false; UserDto user = userService.createUserDtoWithPrivateData(userEntity); do { messagePage = messageService.getReceivedMessageEntitiesSinceDate(user.getId(), buddy.getLastStatusChangeTime(), new PageRequest(page++, pageSize)); messageFound = processPossiblePendingBuddyResponseMessage(user, buddy, messagePage); } while (!messageFound && messagePage.getNumberOfElements() == pageSize); }
From source file:com.afmobi.mongodb.repository.PersonRepositoryIntegrationTests.java
@Test public void executesPagedFinderWithAnnotatedQueryCorrectly() throws Exception { Page<Person> page = repository.findByLastnameLikeWithPageable(".*a.*", new PageRequest(0, 2, Direction.ASC, "lastname", "firstname")); assertThat(page.isFirst(), is(true)); assertThat(page.isLast(), is(false)); assertThat(page.getNumberOfElements(), is(2)); assertThat(page, hasItems(carter, stefan)); }
From source file:org.yukung.daguerreo.domain.repository.BasicJooqRepositoryTest.java
@Test public void findAllByPageable() throws Exception { // given/* ww w .j av a 2s . com*/ dbSetupTracker.skipNextLaunch(); // when PageRequest page1 = new PageRequest(0, 2); PageRequest page2 = new PageRequest(1, 2); Page<BookApi> bookApis1 = repository.findAll(page1); Page<BookApi> bookApis2 = repository.findAll(page2); // then assertThat(bookApis1).isNotNull().isNotEmpty().hasSize(2).extracting("id", "name", "url").containsExactly( tuple(1, "Amazon Product Advertising API", "https://ecs.amazonaws.jp/onca/xml"), tuple(2, "Google Books API", "https://www.googleapis.com/books/v1/volumes")); assertThat(bookApis1.getNumber()).isEqualTo(0); assertThat(bookApis1.getNumberOfElements()).isEqualTo(2); assertThat(bookApis1.getSize()).isEqualTo(2); assertThat(bookApis1.getTotalPages()).isEqualTo(2); assertThat(bookApis1.getTotalElements()).isEqualTo(3); assertThat(bookApis1.isFirst()).isTrue(); assertThat(bookApis1.isLast()).isFalse(); assertThat(bookApis1.hasNext()).isTrue(); assertThat(bookApis1.hasPrevious()).isFalse(); assertThat(bookApis2).isNotNull().isNotEmpty().hasSize(1).extracting("id", "name", "url") .containsExactly(tuple(3, "?API", "https://app.rakuten.co.jp/services/api/BooksBook/Search/20130522")); assertThat(bookApis2.getNumber()).isEqualTo(1); assertThat(bookApis2.getNumberOfElements()).isEqualTo(1); assertThat(bookApis2.getSize()).isEqualTo(2); assertThat(bookApis2.getTotalPages()).isEqualTo(2); assertThat(bookApis2.getTotalElements()).isEqualTo(3); assertThat(bookApis2.isFirst()).isFalse(); assertThat(bookApis2.isLast()).isTrue(); assertThat(bookApis2.hasNext()).isFalse(); assertThat(bookApis2.hasPrevious()).isTrue(); }
From source file:com.netflix.genie.core.jpa.services.JpaApplicationServiceImplIntegrationTests.java
/** * Test the get applications method./*from w ww . ja va2 s.c o m*/ */ @Test public void testGetApplicationsByStatuses() { final Set<ApplicationStatus> statuses = Sets.newHashSet(ApplicationStatus.ACTIVE, ApplicationStatus.INACTIVE); final Page<Application> apps = this.appService.getApplications(null, null, statuses, null, null, PAGEABLE); Assert.assertEquals(2, apps.getNumberOfElements()); Assert.assertEquals(APP_2_ID, apps.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(APP_1_ID, apps.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new)); }
From source file:com.netflix.genie.core.jpa.services.JpaApplicationServiceImplIntegrationTests.java
/** * Test the get applications method./*from w w w. j ava2s. c o m*/ */ @Test public void testGetApplicationsByTags() { final Set<String> tags = Sets.newHashSet("prod"); Page<Application> apps = this.appService.getApplications(null, null, null, tags, null, PAGEABLE); Assert.assertEquals(3, apps.getNumberOfElements()); Assert.assertEquals(APP_3_ID, apps.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(APP_2_ID, apps.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(APP_1_ID, apps.getContent().get(2).getId().orElseThrow(IllegalArgumentException::new)); tags.add("yarn"); apps = this.appService.getApplications(null, null, null, tags, null, PAGEABLE); Assert.assertEquals(1, apps.getNumberOfElements()); Assert.assertEquals(APP_2_ID, apps.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); tags.clear(); tags.add("genie.name:spark"); apps = this.appService.getApplications(null, null, null, tags, null, PAGEABLE); Assert.assertEquals(1, apps.getNumberOfElements()); Assert.assertEquals(APP_2_ID, apps.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); tags.add("somethingThatWouldNeverReallyExist"); apps = this.appService.getApplications(null, null, null, tags, null, PAGEABLE); Assert.assertTrue(apps.getNumberOfElements() == 0); tags.clear(); apps = this.appService.getApplications(null, null, null, tags, null, PAGEABLE); Assert.assertEquals(3, apps.getNumberOfElements()); Assert.assertEquals(APP_3_ID, apps.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(APP_2_ID, apps.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(APP_1_ID, apps.getContent().get(2).getId().orElseThrow(IllegalArgumentException::new)); }
From source file:org.yukung.daguerreo.domain.repository.BasicJooqRepositoryTest.java
@Test public void findAllByPageableAndDescendingSort() throws Exception { // given//ww w . j a v a2s. c om dbSetupTracker.skipNextLaunch(); // when PageRequest page1 = new PageRequest(0, 2, Sort.Direction.DESC, "id"); PageRequest page2 = new PageRequest(1, 2, Sort.Direction.DESC, "id"); Page<BookApi> bookApis1 = repository.findAll(page1); Page<BookApi> bookApis2 = repository.findAll(page2); // then assertThat(bookApis1).isNotNull().isNotEmpty().hasSize(2).extracting("id", "name", "url").containsExactly( tuple(3, "?API", "https://app.rakuten.co.jp/services/api/BooksBook/Search/20130522"), tuple(2, "Google Books API", "https://www.googleapis.com/books/v1/volumes")); assertThat(bookApis1.getNumber()).isEqualTo(0); assertThat(bookApis1.getNumberOfElements()).isEqualTo(2); assertThat(bookApis1.getSize()).isEqualTo(2); assertThat(bookApis1.getTotalPages()).isEqualTo(2); assertThat(bookApis1.getTotalElements()).isEqualTo(3); assertThat(bookApis1.isFirst()).isTrue(); assertThat(bookApis1.isLast()).isFalse(); assertThat(bookApis1.hasNext()).isTrue(); assertThat(bookApis1.hasPrevious()).isFalse(); assertThat(bookApis2).isNotNull().isNotEmpty().hasSize(1).extracting("id", "name", "url") .containsExactly(tuple(1, "Amazon Product Advertising API", "https://ecs.amazonaws.jp/onca/xml")); assertThat(bookApis2.getNumber()).isEqualTo(1); assertThat(bookApis2.getNumberOfElements()).isEqualTo(1); assertThat(bookApis2.getSize()).isEqualTo(2); assertThat(bookApis2.getTotalPages()).isEqualTo(2); assertThat(bookApis2.getTotalElements()).isEqualTo(3); assertThat(bookApis2.isFirst()).isFalse(); assertThat(bookApis2.isLast()).isTrue(); assertThat(bookApis2.hasNext()).isFalse(); assertThat(bookApis2.hasPrevious()).isTrue(); }
From source file:com.netflix.genie.core.jpa.services.JpaApplicationServiceImplIntegrationTests.java
/** * Test the get applications method.//from w w w. j ava2 s .c o m */ @Test public void testGetApplicationsByType() { final Page<Application> apps = this.appService.getApplications(null, null, null, null, APP_2_TYPE, PAGEABLE); Assert.assertEquals(1, apps.getNumberOfElements()); Assert.assertEquals(APP_2_ID, apps.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); }
From source file:com.netflix.genie.core.jpa.services.JpaApplicationServiceImplIntegrationTests.java
/** * Test the get applications method./*from ww w .j a v a 2 s . c om*/ */ @Test public void testGetApplicationsByName() { final Page<Application> apps = this.appService.getApplications(APP_2_NAME, null, null, null, null, PAGEABLE); Assert.assertEquals(1, apps.getNumberOfElements()); Assert.assertThat(apps.getContent().get(0).getId().orElseGet(RandomSuppliers.STRING), Matchers.is(APP_2_ID)); }
From source file:com.netflix.genie.core.jpa.services.JpaApplicationServiceImplIntegrationTests.java
/** * Test the get applications method.// w w w .j a va2 s . c o m */ @Test public void testGetApplicationsByUser() { final Page<Application> apps = this.appService.getApplications(null, APP_1_USER, null, null, null, PAGEABLE); Assert.assertEquals(2, apps.getNumberOfElements()); Assert.assertEquals(APP_3_ID, apps.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(APP_1_ID, apps.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new)); }