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

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

Introduction

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

Prototype

int getNumberOfElements();

Source Link

Document

Returns the number of elements currently on this Slice .

Usage

From source file:org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepositoryTest.java

@Test
public void shouldSearchDocumentsGivenSearchQuery() {
    //given/*from   www  . j a v a2s . c om*/
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setMessage("some test message");
    sampleEntity.setVersion(System.currentTimeMillis());
    repository.save(sampleEntity);

    SearchQuery query = new NativeSearchQueryBuilder().withQuery(termQuery("message", "test")).build();
    //when
    Page<SampleEntity> page = repository.search(query);
    //then
    assertThat(page, is(notNullValue()));
    assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1)));
}

From source file:org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepositoryTest.java

@Test
public void shouldSearchDocumentsGivenElasticsearchQuery() {
    //given//from  www.j  a v a2  s  . c o m
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setMessage("hello world.");
    sampleEntity.setVersion(System.currentTimeMillis());
    repository.save(sampleEntity);
    //when
    Page<SampleEntity> page = repository.search(termQuery("message", "world"), new PageRequest(0, 50));
    //then
    assertThat(page, is(notNullValue()));
    assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1)));
}

From source file:org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepositoryTests.java

@Test
public void shouldSearchDocumentsGivenSearchQuery() {
    // given/*w w  w. j  a va2  s  .c o m*/
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setMessage("some test message");
    sampleEntity.setVersion(System.currentTimeMillis());
    repository.save(sampleEntity);

    SearchQuery query = new NativeSearchQueryBuilder().withQuery(termQuery("message", "test")).build();
    // when
    Page<SampleEntity> page = repository.search(query);
    // then
    assertThat(page, is(notNullValue()));
    assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1)));
}

From source file:org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepositoryTests.java

@Test
public void shouldSearchDocumentsGivenElasticsearchQuery() {
    // given//from w  w w  . j  ava  2  s  . com
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity = new SampleEntity();
    sampleEntity.setId(documentId);
    sampleEntity.setMessage("hello world.");
    sampleEntity.setVersion(System.currentTimeMillis());
    repository.save(sampleEntity);
    // when
    Page<SampleEntity> page = repository.search(termQuery("message", "world"), new PageRequest(0, 50));
    // then
    assertThat(page, is(notNullValue()));
    assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1)));
}

From source file:org.springframework.data.neo4j.aspects.support.FinderTest.java

private void assertPage(Page<Person> page0, int pageNumber, int totalPages, final int totalElements,
        Person... people) {//from  w  ww .  ja va  2  s .  c o  m
    assertEquals("content count", people.length, page0.getNumberOfElements());
    assertEquals("page number", pageNumber, page0.getNumber());
    assertEquals("page size", 2, page0.getSize());
    assertEquals("total elements", totalElements, page0.getTotalElements());
    assertEquals("page count", totalPages, page0.getTotalPages());
    assertEquals("next page", pageNumber < totalPages - 1, page0.hasNextPage());
    assertEquals("previous page", pageNumber > 0, page0.hasPreviousPage());
    assertEquals("page content", asList(people), page0.getContent());
}

From source file:piecework.export.concrete.ExportAsCommaSeparatedValuesProvider.java

@Override
public List<String> next() {
    Page<ProcessInstance> page = pager.nextPage();

    List<String> rows = page.hasContent() ? new ArrayList<String>(page.getNumberOfElements())
            : Collections.<String>emptyList();

    if (page.hasContent()) {
        List<ProcessInstance> instances = page.getContent();
        for (ProcessInstance instance : instances) {
            String row = convert(instance);
            if (row != null)
                rows.add(row);/*from w  w  w . ja  v a  2  s.co m*/
        }
    }

    return rows;
}

From source file:piecework.export.concrete.ExportAsExcelWorkbookProvider.java

@Override
public List<Row> next() {
    Page<ProcessInstance> page = pager.nextPage();

    List<Row> rows = page.hasContent() ? new ArrayList<Row>(page.getNumberOfElements())
            : Collections.<Row>emptyList();

    if (page.hasContent()) {
        List<ProcessInstance> instances = page.getContent();
        for (ProcessInstance instance : instances) {
            rows.add(convert(instance));
        }//from  w  w  w  .j  av  a 2 s .  c  om
    }

    return rows;
}