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

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

Introduction

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

Prototype

long getTotalElements();

Source Link

Document

Returns the total amount of elements.

Usage

From source file:org.bisen.blog.service.BlogServiceTest.java

/**
 * Test of saveBlog method, of class BlogServiceImpl.
 *///  www  . j av  a 2s.  c  o  m
@Test
public void testSaveAndSearchBlog() {
    System.out.println("saveBlog");

    Blog blog = new Blog();

    blog.setContent("<p>This is test content</p>");
    blog.setTitle("This is test title");
    blog.setTags(new HashSet<>(Arrays.asList(new Tag("test"), new Tag("test1"))));

    SolrBlog result = blogService.save(blog);

    Assert.assertTrue(result.getId() > 0);

    Page<SolrBlog> solrResults = blogService.search("content", new PageRequest(0, 10));
    Assert.assertTrue(solrResults.getTotalElements() > 0);
}

From source file:org.jblogcms.core.common.service.ItemServiceToolImpl.java

@Override
public Page<I> addItemRelationsToItemPage(Page<I> items, Long accountId) {
    if (items != null && items.getTotalElements() != 0) {
        addItemRelationsToItemList(items.getContent(), accountId);
    }/*from   w  w w  . j a v  a 2  s  .c o  m*/
    return items;
}

From source file:org.jblogcms.core.common.service.ItemServiceToolImpl.java

@Override
public Page<I> addItemRatesToItemPage(Page<I> items, Long accountId) {
    if (items != null && items.getTotalElements() != 0) {
        addItemRatesToItemList(items.getContent(), accountId);
    }// w w  w.  j a va 2s.c o  m
    return items;
}

From source file:th.co.geniustree.internship.advisor.service.ParentSearchServiceSpecIT.java

@Test
public void findEmailParentShouldReturnOneRow() {
    parentRepo.saveAndFlush(parent);/*from  ww  w.  j a  v  a  2  s. c om*/
    Page<Parent> search = parentSearchService.searchByNameOrEmail("parent", new PageRequest(0, 10));
    Assertions.assertThat(search.getTotalElements()).isEqualTo(1);
}

From source file:com.real.apps.shuttle.repository.VehicleRepositoryTest.java

@Test
public void shouldOnlyFindTheVehiclesWithTheGivenCompanyId() {
    ObjectId id = ObjectId.get();/*w  ww  .j  av  a 2 s  . com*/
    ObjectId control = ObjectId.get();

    Vehicle vehicleToBeFound = new Vehicle();
    vehicleToBeFound.setCompanyId(id);
    vehicleToBeFound.setLicenseNumber("Test License Number To Be Found");

    Vehicle vehicleToBeFound2 = new Vehicle();
    vehicleToBeFound2.setLicenseNumber("Test License Number To Be Found 2");
    vehicleToBeFound2.setCompanyId(id);

    Vehicle vehicleNotToBeFound = new Vehicle();
    vehicleNotToBeFound.setLicenseNumber("Test License Number Not To Be Found");
    vehicleNotToBeFound.setCompanyId(control);

    Vehicle controlVehicle = new Vehicle();

    assertNotNull(repository.save(vehicleNotToBeFound).getId());
    assertNotNull(repository.save(vehicleToBeFound).getId());
    assertNotNull(repository.save(vehicleToBeFound2).getId());
    assertNotNull(repository.save(controlVehicle).getId());

    Page<Vehicle> actual = repository.findByCompanyId(id, new PageRequest(0, 10));
    assertThat(actual.getTotalElements(), is(2l));
    assertThat(actual.getContent().get(0).getCompanyId(), is(id));
    assertThat(actual.getContent().get(1).getCompanyId(), is(id));
}

From source file:th.co.geniustree.internship.advisor.service.ParentSearchServiceSpecIT.java

@Test
public void updateEmailMustBeSuccess() {
    parentRepo.saveAndFlush(parent);/*from www  .j av  a 2 s . c  o  m*/
    Page<Parent> search = parentSearchService.searchByNameOrEmail("parent", new PageRequest(0, 10));
    Assertions.assertThat(search.getTotalElements()).isEqualTo(1);
    parent.setEmail("xxxxxxx@xxxxx.com");
    Page<Parent> searchAgain = parentSearchService.searchByNameOrEmail("xxxxxxx", new PageRequest(0, 10));
    Assertions.assertThat(searchAgain.getTotalElements()).isEqualTo(1);
}

From source file:org.openlmis.fulfillment.service.PageDto.java

/**
 * Creates new instance based on data from {@link Page} instance.
 *///  ww w . ja  v  a  2  s.c om
public PageDto(Page<T> page) {
    this(checkNotNull(page).isLast(), page.isFirst(), page.getTotalPages(), page.getTotalElements(),
            page.getSize(), page.getNumber(), page.getNumberOfElements(), page.getSort(),
            checkNotNull(page.getContent()));
}

From source file:edu.pitt.dbmi.ccd.db.service.AnnotationDataServiceTest.java

@Test
public void findByAnnotation() {
    final Pageable pageable = new PageRequest(0, 2);
    final Annotation annotation = annotationRepository.findOne(4L);
    final Page<AnnotationData> annotationData = annotationDataService.findByAnnotation(annotation, pageable);
    assertEquals(2, annotationData.getTotalElements());
}

From source file:com.demo.ticketservice.dao.TicketServiceRepositoryIntegrationTests.java

@Test
public void findsFirstPageOfCustomers() {

    Page<Customer> customers = this.customerRepository.findAll(new PageRequest(0, 10));
    assertThat(customers.getTotalElements(), is(greaterThan(1L)));
}

From source file:edu.pitt.dbmi.ccd.db.service.VocabularyServiceTest.java

@Test
public void search() {
    // matches/*from w w  w  .  j  a v a 2  s  .com*/
    final Set<String> search = new HashSet<>(Arrays.asList("Plaintext"));
    Page<Vocabulary> vocabularies = vocabularyService.search(search, new HashSet<String>(0), pageable);
    assertEquals(1, vocabularies.getTotalElements());

    // nots
    vocabularies = vocabularyService.search(new HashSet<String>(0), search, pageable);
    assertEquals(0, vocabularies.getTotalElements());
}