Search in sources :

Example 16 with Pagination

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

the class DefaultColumnQueryPaginationTest method shouldNext.

@Test
public void shouldNext() {
    ColumnQuery query = select().from("column").where("name").eq("Ada").build();
    Pagination pagination = Pagination.page(1).size(2);
    Pagination secondPage = pagination.next();
    ColumnQueryPagination queryPagination = ColumnQueryPagination.of(query, pagination);
    assertNotNull(queryPagination);
    assertEquals(pagination.getLimit(), queryPagination.getLimit());
    assertEquals(pagination.getSkip(), queryPagination.getSkip());
    isQueryEquals(query, pagination, queryPagination);
    ColumnQueryPagination next = queryPagination.next();
    isQueryEquals(query, secondPage, next);
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) Test(org.junit.jupiter.api.Test)

Example 17 with Pagination

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

the class DefaultColumnQueryPaginationTest method shouldOverrideSkipLimit.

@Test
public void shouldOverrideSkipLimit() {
    ColumnQuery query = select().from("column").build();
    Pagination pagination = Pagination.page(1).size(2);
    ColumnQueryPagination queryPagination = ColumnQueryPagination.of(query, pagination);
    assertNotNull(queryPagination);
    assertEquals(pagination.getLimit(), queryPagination.getLimit());
    assertEquals(pagination.getSkip(), queryPagination.getSkip());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) Test(org.junit.jupiter.api.Test)

Example 18 with Pagination

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

the class ColumnRepositoryProxyPaginationTest method shouldFindByNameInstance.

@Test
public void shouldFindByNameInstance() {
    when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional.of(Person.builder().build()));
    Pagination pagination = getPagination();
    personRepository.findByName("name", pagination);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).singleResult(captor.capture());
    ColumnQuery query = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
    assertEquals(Column.of("name", "name"), condition.getColumn());
    assertNotNull(personRepository.findByName("name", pagination));
    when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional.empty());
    assertNull(personRepository.findByName("name", pagination));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 19 with Pagination

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

the class ColumnRepositoryProxyPaginationTest method shouldFindByGreaterThan.

@Test
public void shouldFindByGreaterThan() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    personRepository.findByAgeGreaterThan(33, pagination);
    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(GREATER_THAN, condition.getCondition());
    assertEquals(Column.of("age", 33), condition.getColumn());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) Person(jakarta.nosql.tck.entities.Person) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 20 with Pagination

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

the class ColumnRepositoryProxyPaginationTest method shouldFindAll.

@Test
public void shouldFindAll() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    List<Person> persons = personRepository.findAll(pagination);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    ColumnQuery query = captor.getValue();
    assertFalse(query.getCondition().isPresent());
    assertEquals("Person", query.getColumnFamily());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) Person(jakarta.nosql.tck.entities.Person) 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