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")));
}
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")));
}
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")));
}
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());
}
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()));
}
Aggregations