use of io.gravitee.repository.management.api.search.Pageable in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceTest method shouldFindByApi.
@Test
public void shouldFindByApi() throws TechnicalException {
final Pageable pageable = mock(Pageable.class);
when(pageable.pageNumber()).thenReturn(1);
when(pageable.pageSize()).thenReturn(1);
final Page<Rating> pageRating = mock(Page.class);
when(pageRating.getPageNumber()).thenReturn(1);
when(pageRating.getPageElements()).thenReturn(10L);
when(pageRating.getTotalElements()).thenReturn(100L);
when(pageRating.getContent()).thenReturn(singletonList(rating));
when(ratingRepository.findByApiPageable(eq(API_ID), eq(new PageableBuilder().pageNumber(0).pageSize(1).build()))).thenReturn(pageRating);
final Page<RatingEntity> pageRatingEntity = ratingService.findByApi(API_ID, pageable);
assertEquals(1, pageRatingEntity.getPageNumber());
assertEquals(10, pageRatingEntity.getPageElements());
assertEquals(100, pageRatingEntity.getTotalElements());
final RatingEntity ratingEntity = pageRatingEntity.getContent().get(0);
assertEquals(USER, ratingEntity.getUser());
assertEquals(API_ID, ratingEntity.getApi());
assertEquals(TITLE, ratingEntity.getTitle());
assertEquals(COMMENT, ratingEntity.getComment());
assertEquals(RATE, ratingEntity.getRate(), 0);
assertEquals(ratingEntity.getCreatedAt(), ratingEntity.getUpdatedAt());
}
Aggregations