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

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

Introduction

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

Prototype

List<T> getContent();

Source Link

Document

Returns the page content as List .

Usage

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

@Test
public void shouldMapSearchRequestToPage() {
    //Given/*from   w  ww  .  j a v 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//from w ww .  j a  va2 s  .  c om
    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"));
}