Example usage for org.springframework.data.elasticsearch.core FacetedPage getTotalElements

List of usage examples for org.springframework.data.elasticsearch.core FacetedPage getTotalElements

Introduction

In this page you can find the example usage for org.springframework.data.elasticsearch.core FacetedPage getTotalElements.

Prototype

long getTotalElements();

Source Link

Document

Returns the total amount of elements.

Usage

From source file:org.springframework.data.elasticsearch.core.DefaultResultMapperTests.java

@Test
public void shouldMapSearchRequestToPage() {
    //Given//from   ww w . j  av  a  2  s.  c  om
    SearchHit[] hits = { createCarHit("Ford", "Grat"), createCarHit("BMW", "Arrow") };
    SearchHits searchHits = mock(SearchHits.class);
    when(searchHits.totalHits()).thenReturn(2L);
    when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
    when(response.getHits()).thenReturn(searchHits);

    //When
    FacetedPage<Car> page = resultMapper.mapResults(response, Car.class, null);

    //Then
    assertThat(page.hasContent(), is(true));
    assertThat(page.getTotalElements(), is(2L));
    assertThat(page.getContent().get(0).getName(), is("Ford"));
}

From source file:org.springframework.data.elasticsearch.core.DefaultResultMapperTests.java

@Test
public void shouldMapPartialSearchRequestToObject() {
    //Given// www .  j a  v a2s .c  o  m
    SearchHit[] hits = { createCarPartialHit("Ford", "Grat"), createCarPartialHit("BMW", "Arrow") };
    SearchHits searchHits = mock(SearchHits.class);
    when(searchHits.totalHits()).thenReturn(2L);
    when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
    when(response.getHits()).thenReturn(searchHits);

    //When
    FacetedPage<Car> page = resultMapper.mapResults(response, Car.class, null);

    //Then
    assertThat(page.hasContent(), is(true));
    assertThat(page.getTotalElements(), is(2L));
    assertThat(page.getContent().get(0).getName(), is("Ford"));
}