use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DocumentPageTest method shouldRequestPageTwice.
@Test
public void shouldRequestPageTwice() {
Pagination pagination = Pagination.page(1).size(1);
Page<Person> page = createPage(pagination);
List<Person> people = page.getContent().collect(Collectors.toList());
assertEquals(1, people.size());
assertEquals(0L, people.get(0).getId());
assertNotNull(page.getContent(ArrayList::new));
assertNotNull(page.getContent(HashSet::new));
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DocumentPageTest method shouldCreatePagination.
@Test
public void shouldCreatePagination() {
Pagination pagination = Pagination.page(1).size(1);
Page<Person> page = createPage(pagination);
assertEquals(0L, page.get().map(Person::getId).findFirst().orElse(-0L));
Page<Person> nextPage = page.next();
assertEquals(pagination.next(), nextPage.getPagination());
assertEquals(1L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
nextPage = nextPage.next();
assertEquals(2L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
nextPage = nextPage.next();
assertEquals(3L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
nextPage = nextPage.next();
assertEquals(4L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
nextPage = nextPage.next();
assertEquals(5L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
nextPage = nextPage.next();
assertEquals(6L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
nextPage = nextPage.next();
assertEquals(7L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DefaultDocumentQueryPaginationTest method shouldCreateDocumentQueryPagination.
@Test
public void shouldCreateDocumentQueryPagination() {
DocumentQuery query = select().from("column").build();
Pagination pagination = Pagination.page(1).size(2);
DocumentQueryPagination queryPagination = DocumentQueryPagination.of(query, pagination);
assertNotNull(queryPagination);
isQueryEquals(query, pagination, queryPagination);
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DefaultDocumentMapperSelectBuilderTest method shouldCreatePage.
@Test
public void shouldCreatePage() {
Pagination pagination = Pagination.page(2).size(2);
DocumentTemplate template = Mockito.mock(DocumentTemplate.class);
ArgumentCaptor<DocumentQueryPagination> queryCaptor = ArgumentCaptor.forClass(DocumentQueryPagination.class);
Page<Person> page = mapperBuilder.selectFrom(Person.class).page(template, pagination);
Mockito.verify(template).select(queryCaptor.capture());
DocumentQuery query = queryCaptor.getValue();
assertEquals(pagination.getLimit(), query.getLimit());
assertEquals(pagination.getSkip(), query.getSkip());
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DocumentRepositoryProxySortTest method shouldFindByNameOrderByName2.
@Test
public void shouldFindByNameOrderByName2() {
when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(Person.builder().build()));
Pagination pagination = getPagination();
personRepository.findByNameOrderByName("name", pagination, Sorts.sorts().desc("age").asc("phone"));
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
DocumentQuery query = captor.getValue();
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(EQUALS, condition.getCondition());
assertEquals(Document.of("name", "name"), condition.getDocument());
assertEquals(pagination.getSkip(), query.getSkip());
assertEquals(pagination.getLimit(), query.getLimit());
assertThat(query.getSorts(), Matchers.contains(Sort.asc("name"), Sort.desc("age"), Sort.asc("phone")));
}
Aggregations