Search in sources :

Example 66 with Pagination

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));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 67 with Pagination

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));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 68 with Pagination

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);
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Pagination(jakarta.nosql.mapping.Pagination) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Test(org.junit.jupiter.api.Test)

Example 69 with Pagination

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());
}
Also used : DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Pagination(jakarta.nosql.mapping.Pagination) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) DocumentTemplate(jakarta.nosql.mapping.document.DocumentTemplate) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 70 with Pagination

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")));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Aggregations

Pagination (jakarta.nosql.mapping.Pagination)99 Test (org.junit.jupiter.api.Test)96 Person (jakarta.nosql.tck.entities.Person)46 ColumnQuery (jakarta.nosql.column.ColumnQuery)27 DocumentQuery (jakarta.nosql.document.DocumentQuery)27 ColumnQueryPagination (jakarta.nosql.mapping.column.ColumnQueryPagination)17 DocumentQueryPagination (jakarta.nosql.mapping.document.DocumentQueryPagination)17 Method (java.lang.reflect.Method)15 Optional (java.util.Optional)15 Stream (java.util.stream.Stream)15 ColumnCondition (jakarta.nosql.column.ColumnCondition)13 DocumentCondition (jakarta.nosql.document.DocumentCondition)13 List (java.util.List)7 Person (org.eclipse.jnosql.mapping.graph.model.Person)7 Vendor (jakarta.nosql.tck.entities.Vendor)4 ColumnTemplate (jakarta.nosql.mapping.column.ColumnTemplate)3 DocumentTemplate (jakarta.nosql.mapping.document.DocumentTemplate)3 Value (jakarta.nosql.Value)2 ArrayList (java.util.ArrayList)2 Collections.singletonList (java.util.Collections.singletonList)2