use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DefaultColumnMapperSelectBuilderTest method shouldExecuteSingleQueryPagination.
@Test
public void shouldExecuteSingleQueryPagination() {
Pagination pagination = Pagination.page(2).size(2);
ColumnTemplate template = Mockito.mock(ColumnTemplate.class);
ArgumentCaptor<ColumnQuery> queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class);
mapperBuilder.selectFrom(Person.class).getSingleResult(template, pagination);
Mockito.verify(template).singleResult(queryCaptor.capture());
ColumnQuery query = queryCaptor.getValue();
assertEquals(pagination.getLimit(), query.getLimit());
assertEquals(pagination.getSkip(), query.getSkip());
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DefaultColumnMapperSelectBuilderTest method shouldExecuteQueryPagination.
@Test
public void shouldExecuteQueryPagination() {
Pagination pagination = Pagination.page(2).size(2);
ColumnTemplate template = Mockito.mock(ColumnTemplate.class);
ArgumentCaptor<ColumnQuery> queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class);
mapperBuilder.selectFrom(Person.class).getResult(template, pagination);
Mockito.verify(template).select(queryCaptor.capture());
ColumnQuery query = queryCaptor.getValue();
assertEquals(pagination.getLimit(), query.getLimit());
assertEquals(pagination.getSkip(), query.getSkip());
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DefaultColumnMapperSelectBuilderTest method shouldCreatePage.
@Test
public void shouldCreatePage() {
Pagination pagination = Pagination.page(2).size(2);
ColumnTemplate template = Mockito.mock(ColumnTemplate.class);
ArgumentCaptor<ColumnQueryPagination> queryCaptor = ArgumentCaptor.forClass(ColumnQueryPagination.class);
Page<Person> page = mapperBuilder.selectFrom(Person.class).page(template, pagination);
Mockito.verify(template).select(queryCaptor.capture());
ColumnQuery query = queryCaptor.getValue();
assertEquals(pagination.getLimit(), query.getLimit());
assertEquals(pagination.getSkip(), query.getSkip());
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DefaultPaginationTest method shouldReturnReadOnly.
@Test
public void shouldReturnReadOnly() {
Pagination pagination = Pagination.page(1).size(2);
Pagination unmodifiable = pagination.unmodifiable();
assertThrows(UnsupportedOperationException.class, unmodifiable::next);
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DynamicReturnPaginationTest method shouldReturnAnInstance.
@Test
public void shouldReturnAnInstance() throws NoSuchMethodException {
Method method = getMethod(PersonRepository.class, "getInstance");
Supplier<Stream<?>> stream = Stream::empty;
Supplier<Optional<?>> singleResult = DynamicReturn.toSingleResult(method).apply(stream);
Pagination pagination = getPagination();
when(singlePagination.apply(pagination)).thenReturn(Optional.of(new Person("Ada")));
DynamicReturn<?> dynamicReturn = DynamicReturn.builder().withClassSource(Person.class).withMethodSource(method).withResult(stream).withSingleResult(singleResult).withPagination(pagination).withStreamPagination(streamPagination).withSingleResultPagination(singlePagination).withPage(page).build();
Object execute = dynamicReturn.execute();
Assertions.assertTrue(execute instanceof Person);
Person person = (Person) execute;
Assertions.assertEquals(new Person("Ada"), person);
Mockito.verify(singlePagination).apply(pagination);
Mockito.verify(streamPagination, Mockito.never()).apply(pagination);
}
Aggregations