List of usage examples for org.springframework.data.domain Page getTotalElements
long getTotalElements();
From source file:com.artivisi.belajar.restful.service.impl.MenuServiceTestIT.java
@Test public void testFindAll() { Page<Menu> result = belajarRestfulService .findAllMenu(new PageRequest(0, belajarRestfulService.countAllMenu().intValue())); assertTrue(result.getTotalElements() > 0); }
From source file:org.jblogcms.core.account.repository.AccountRepositoryItTest.java
@Test @Transactional/*from ww w . j a v a 2 s . c o m*/ public void testFindAccounts_returnAllAccounts() throws Exception { Page<Account> accounts = accountRepository.findAccounts(pageable); Assert.assertEquals(3, accounts.getTotalElements()); Assert.assertEquals(ACCOUNT_1_ID, accounts.getContent().get(0).getId()); Assert.assertEquals(ACCOUNT_1_EMAIL, accounts.getContent().get(0).getEmail()); Assert.assertEquals(ACCOUNT_2_ID, accounts.getContent().get(1).getId()); Assert.assertEquals(ACCOUNT_2_EMAIL, accounts.getContent().get(1).getEmail()); Assert.assertEquals(ACCOUNT_3_ID, accounts.getContent().get(2).getId()); Assert.assertEquals(ACCOUNT_3_EMAIL, accounts.getContent().get(2).getEmail()); }
From source file:ymanv.forex.web.RateControllerTest.java
@DirtiesContext @Sql("/sql/insert_data.sql") @Test// w ww . j av a2 s. co m public void testFindLatestByCriteria() throws Exception { // when Page<LatestRate> result = controller.findLatestByCriteria(USD, EUR, null, null, null, null); // then assertThat(result.getTotalElements()).isEqualTo(1); assertThat(result.getNumberOfElements()).isEqualTo(1); RateEntity r = result.getContent().get(0); assertThat(r.getFromcur()).isEqualTo(USD); assertThat(r.getTocur()).isEqualTo(EUR); assertThat(r.getDate()).hasSameTimeAs(DATE_TIME_WITH_TZ.parse("2015-01-30 13:55:00.0 CET")); assertThat(r.getValue()).isEqualByComparingTo("0.88"); }
From source file:midas.database.PopulateDatabase.java
@Test @Transactional/*from w ww .j a v a 2 s. co m*/ public void testFindDuplicates() { CustomerJpa dupEntity = new CustomerJpa(); dupEntity.setFirstName("caio"); dupEntity.setLastName("amaral"); dupEntity = customerJpaRepo.save(dupEntity); CustomerJpa entity = new CustomerJpa(); entity.setFirstName("caio2"); entity.setLastName("amaral2"); entity.setDuplicates(Arrays.asList(dupEntity)); entity = customerJpaRepo.save(entity); entity = new CustomerJpa(); entity.setFirstName("caio3"); entity.setLastName("amaral3"); entity = customerJpaRepo.save(entity); PageRequest pageable = new PageRequest(0, 2); Page<CustomerJpa> findDuplicates = customerJpaRepo.findDuplicates(pageable); Assert.assertEquals(1l, findDuplicates.getTotalElements()); CustomerJpa customer = findDuplicates.getContent().get(0); Assert.assertEquals(2, customer.getId().intValue()); Assert.assertEquals(1, customer.getDuplicates().size()); Assert.assertEquals(1, customer.getDuplicates().get(0).getId().intValue()); }
From source file:com.davidmogar.alsa.services.bus.internal.BusManagerServiceImpl.java
@Override public Page<BusDto> findAll(int pageIndex) { Pageable pageable = createPageable(pageIndex); Page<Bus> page = busDataService.findAll(pageable); List<BusDto> users = page.getContent().stream().map(BusDto::new).collect(Collectors.toList()); return new PageImpl<>(users, pageable, page.getTotalElements()); }
From source file:com.github.markserrano.jsonquery.jpa.service.ParentChildThingEntityServiceTest.java
@Test public void testReadAndCount_SingleCriteriaBy_ParentNonId_ThingId() { String filter = "{\"groupOp\":\"AND\",\"rules\":" + "[{\"field\":\"parent.store\",\"op\":\"ne\",\"data\":\"StoreB\"}," + "{\"field\":\"parent.thing.id\",\"op\":\"ne\",\"data\":\"1\"}]" + "}"; BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter)); Page<Child> results = service.readAndCount(builder, new PageRequest(0, 3), Child.class, orderSpecifiers); Assert.assertNotNull(results);/*from w ww . j a v a 2 s . c om*/ Assert.assertEquals(2, results.getTotalElements()); Assert.assertEquals("StoreC", results.getContent().get(0).getParent().getStore()); Assert.assertEquals("StoreD", results.getContent().get(1).getParent().getStore()); }
From source file:com.github.markserrano.jsonquery.jpa.service.ParentChildThingEntityServiceTest.java
@Test public void testReadAndCount_DoubleCriteriaBy_ForeignTable_FieldOtherThanId() { String filter = "{\"groupOp\":\"AND\",\"rules\":" + "[{\"field\":\"parent.store\",\"op\":\"ne\",\"data\":\"StoreB\"}," + "{\"field\":\"birthDate\",\"op\":\"lt\",\"data\":\"1995-10-01T00:00:00.000Z\"}]" + "}"; BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter)); Page<Child> results = service.readAndCount(builder, new PageRequest(0, 3), Child.class, orderSpecifiers); Assert.assertNotNull(results);/*from w ww . ja v a 2 s . c om*/ Assert.assertEquals(2, results.getTotalElements()); Assert.assertEquals("StoreA", results.getContent().get(0).getParent().getStore()); Assert.assertEquals("StoreD", results.getContent().get(1).getParent().getStore()); }
From source file:com.github.markserrano.jsonquery.jpa.service.ParentChildThingEntityServiceTest.java
@Test public void testReadAndCount_SingleCriteriaBy_ParentNonId_ThingNonId() { String filter = "{\"groupOp\":\"AND\",\"rules\":" + "[{\"field\":\"parent.store\",\"op\":\"ne\",\"data\":\"StoreB\"}," + "{\"field\":\"parent.thing.name\",\"op\":\"ne\",\"data\":\"Pencil\"}]" + "}"; BooleanBuilder builder = jsonBooleanBuilder.build(new JsonFilter(filter)); Page<Child> results = service.readAndCount(builder, new PageRequest(0, 3), Child.class, orderSpecifiers); Assert.assertNotNull(results);// www. j ava 2 s .co m Assert.assertEquals(4, results.getTotalElements()); Assert.assertEquals(3, results.getContent().size()); // paged at 3 records Assert.assertEquals("StoreA", results.getContent().get(0).getParent().getStore()); Assert.assertEquals("StoreA", results.getContent().get(1).getParent().getStore()); Assert.assertEquals("StoreA", results.getContent().get(2).getParent().getStore()); }
From source file:com.oreilly.springdata.jpa.core.ProductRepositoryIntegrationTest.java
@Test @SuppressWarnings("unchecked") public void lookupProductsByDescription() { Pageable pageable = new PageRequest(0, 1, Direction.DESC, "name"); Page<Product> page = repository.findByDescriptionContaining("Apple", pageable); assertThat(page.getContent(), hasSize(1)); assertThat(page, Matchers.<Product>hasItems(named("iPad"))); assertThat(page.getTotalElements(), is(2L)); assertThat(page.isFirstPage(), is(true)); assertThat(page.isLastPage(), is(false)); assertThat(page.hasNextPage(), is(true)); }
From source file:com.foilen.smalltools.restapi.model.ApiPagination.java
public ApiPagination(Page<?> page) { this.currentPage = page.getNumber(); this.totalPages = page.getTotalPages(); this.setItemsPerPage(page.getSize()); this.totalItems = page.getTotalElements(); }