Search in sources :

Example 86 with Pagination

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

the class ColumnRepositoryProxySortTest method shouldFindByName.

@Test
public void shouldFindByName() {
    when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional.of(Person.builder().build()));
    Pagination pagination = getPagination();
    personRepository.findByName("name", pagination, Sort.desc("name"));
    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());
    assertThat(query.getSorts(), Matchers.contains(Sort.desc("name")));
    assertEquals(Column.of("name", "name"), condition.getColumn());
    assertNotNull(personRepository.findByName("name", pagination, Sort.asc("name")));
    when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional.empty());
    assertNull(personRepository.findByName("name", pagination, Sort.asc("name")));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 87 with Pagination

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

the class ColumnRepositoryProxySortTest method shouldFindAll.

@Test
public void shouldFindAll() {
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(Person.builder().build()));
    Pagination pagination = getPagination();
    personRepository.findAll(pagination, Sorts.sorts().asc("name"));
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    ColumnQuery query = captor.getValue();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
    assertThat(query.getSorts(), Matchers.contains(Sort.asc("name")));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) Test(org.junit.jupiter.api.Test)

Example 88 with Pagination

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

the class ColumnRepositoryProxySortTest method shouldFindByNameOrderByName.

@Test
public void shouldFindByNameOrderByName() {
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of((Person.builder().build())));
    Pagination pagination = getPagination();
    personRepository.findByNameOrderByName("name", pagination, Sort.desc("age"));
    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")));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 89 with Pagination

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

the class DefaultColumnMapperSelectBuilderTest method shouldCreateQueryWithPagination.

@Test
public void shouldCreateQueryWithPagination() {
    Pagination pagination = Pagination.page(2).size(2);
    ColumnMapperFrom columnFrom = mapperBuilder.selectFrom(Person.class);
    ColumnQuery query = columnFrom.build(pagination);
    assertEquals(pagination.getLimit(), query.getLimit());
    assertEquals(pagination.getSkip(), query.getSkip());
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnMapperFrom(jakarta.nosql.mapping.column.ColumnQueryMapper.ColumnMapperFrom) Test(org.junit.jupiter.api.Test)

Example 90 with Pagination

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

the class GraphPageTest method shouldNext2.

@Test
public void shouldNext2() {
    Pagination pagination = Pagination.page(1).size(1);
    Page<Person> page = template.getTraversalVertex().orderBy("name").desc().page(pagination);
    assertNotNull(page);
    Stream<Person> people = page.get();
    assertEquals(pagination, page.getPagination());
    assertEquals(poliana.getName(), people.map(Person::getName).collect(joining()));
    pagination = pagination.next();
    page = page.next();
    people = page.get();
    assertEquals(pagination, page.getPagination());
    assertEquals(paulo.getName(), people.map(Person::getName).collect(joining()));
    pagination = pagination.next();
    page = page.next();
    people = page.get();
    assertEquals(pagination, page.getPagination());
    assertEquals(otavio.getName(), people.map(Person::getName).collect(joining()));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) Person(org.eclipse.jnosql.mapping.graph.model.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