Search in sources :

Example 26 with Pagination

use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.

the class ColumnPageTest method shouldExecutePaginationAsQuery.

@Test
public void shouldExecutePaginationAsQuery() {
    Pagination pagination = Pagination.page(1).size(1);
    ColumnQueryPagination queryPagination = ColumnQueryPagination.of(select().from("person").build(), pagination);
    ColumnQuery query = queryPagination;
    List<Person> people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(0L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(1L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(2L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(3L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(4L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(5L, people.stream().map(Person::getId).findFirst().orElse(-0L));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) ColumnQuery(jakarta.nosql.column.ColumnQuery) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 27 with Pagination

use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.

the class ColumnPageTest method shouldExecutePagination.

@Test
public void shouldExecutePagination() {
    Pagination pagination = Pagination.page(1).size(1);
    ColumnQueryPagination query = ColumnQueryPagination.of(select().from("person").build(), pagination);
    Page<Person> page = subject.select(query);
    verify(managerMock).select(query);
    assertNotNull(page);
    assertEquals(pagination, page.getPagination());
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 28 with Pagination

use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.

the class ColumnPageTest method shouldReturnNPEWhenCollectionFactoryIsNull.

@Test
public void shouldReturnNPEWhenCollectionFactoryIsNull() {
    Pagination pagination = Pagination.page(1).size(1);
    Page<Person> page = createPage(pagination);
    assertThrows(NullPointerException.class, () -> page.getContent(null));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 29 with Pagination

use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.

the class ColumnPageTest method shouldExecuteQueryPagination.

@Test
public void shouldExecuteQueryPagination() {
    Pagination pagination = Pagination.page(1).size(2);
    ColumnQueryPagination query = ColumnQueryPagination.of(select().from("person").build(), pagination);
    subject.select(query);
    verify(managerMock).select(query);
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) Test(org.junit.jupiter.api.Test)

Example 30 with Pagination

use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.

the class ColumnRepositoryProxySortTest method shouldFindByNameOrderByName2.

@Test
public void shouldFindByNameOrderByName2() {
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of((Person.builder().build())));
    Pagination pagination = getPagination();
    personRepository.findByNameOrderByName("name", pagination, Sorts.sorts().desc("age").asc("phone"));
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    ColumnQuery query = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(EQUALS, condition.getCondition());
    assertEquals(Column.of("name", "name"), condition.getColumn());
    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 : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) ColumnCondition(jakarta.nosql.column.ColumnCondition) 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