use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DynamicReturnPaginationTest method shouldReturnSortedSet.
@Test
public void shouldReturnSortedSet() throws NoSuchMethodException {
Method method = getMethod(PersonRepository.class, "getSortedSet");
Supplier<Stream<?>> stream = Stream::empty;
Supplier<Optional<?>> singleResult = DynamicReturn.toSingleResult(method).apply(stream);
Pagination pagination = getPagination();
when(streamPagination.apply(pagination)).thenReturn(Stream.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 SortedSet);
SortedSet<Person> persons = (SortedSet) execute;
Assertions.assertFalse(persons.isEmpty());
Assertions.assertEquals(new Person("Ada"), persons.iterator().next());
Mockito.verify(singlePagination, Mockito.never()).apply(pagination);
Mockito.verify(streamPagination).apply(pagination);
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DefaultPaginationTest method shouldCreatePaginationInstance.
@Test
public void shouldCreatePaginationInstance() {
Pagination pagination = Pagination.page(1).size(2);
assertEquals(1, pagination.getPageNumber());
assertEquals(2L, pagination.getPageSize());
assertEquals(2L, pagination.getLimit());
assertEquals(0L, pagination.getSkip());
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DefaultPaginationTest method shouldNext.
@Test
public void shouldNext() {
Pagination pagination = Pagination.page(1).size(2);
checkPagination(pagination, 1, 0, 2, 2);
Pagination secondPage = pagination.next();
assertNotNull(secondPage);
checkPagination(secondPage, 2, 2, 2, 2);
Pagination thirdPage = secondPage.next();
checkPagination(thirdPage, 3, 4, 2, 2);
Pagination fourthPage = thirdPage.next();
checkPagination(fourthPage, 4, 6, 2, 2);
Pagination fifthPage = fourthPage.next();
checkPagination(fifthPage, 5, 8, 2, 2);
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DocumentPageTest method setUp.
@BeforeEach
public void setUp() {
managerMock = Mockito.mock(DocumentCollectionManager.class);
columnEventPersistManager = Mockito.mock(DocumentEventPersistManager.class);
captor = ArgumentCaptor.forClass(DocumentEntity.class);
Instance<DocumentCollectionManager> instance = Mockito.mock(Instance.class);
when(instance.get()).thenReturn(managerMock);
this.subject = new DefaultDocumentTemplate(converter, instance, new DefaultDocumentWorkflow(columnEventPersistManager, converter), columnEventPersistManager, classMappings, converters);
Pagination pagination = Pagination.page(1).size(1);
DocumentQueryPagination query = DocumentQueryPagination.of(select().from("person").build(), pagination);
for (int index = 0; index <= 10; index++) {
Document[] columns = new Document[] { Document.of("age", index), Document.of("name", "Ada " + index), Document.of("_id", (long) index) };
DocumentEntity columnEntity = DocumentEntity.of("Person");
columnEntity.addAll(Stream.of(columns).collect(Collectors.toList()));
when(managerMock.select(query)).thenReturn(Stream.of(columnEntity));
query = query.next();
}
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DocumentPageTest method shouldReturnNPEWhenCollectionFactoryIsNull.
@Test
public void shouldReturnNPEWhenCollectionFactoryIsNull() {
Pagination pagination = Pagination.page(1).size(1);
Page<Person> page = createPage(pagination);
assertThrows(NullPointerException.class, () -> page.getContent(null));
}
Aggregations