use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DynamicReturnPaginationTest method shouldReturnStream.
@Test
public void shouldReturnStream() throws NoSuchMethodException {
Method method = getMethod(PersonRepository.class, "getStream");
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 Stream);
Stream<Person> persons = (Stream) execute;
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 DynamicReturnPaginationTest method shouldReturnList.
@Test
public void shouldReturnList() throws NoSuchMethodException {
Method method = getMethod(PersonRepository.class, "getList");
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 List);
List<Person> persons = (List) execute;
Assertions.assertFalse(persons.isEmpty());
Assertions.assertEquals(new Person("Ada"), persons.get(0));
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 DynamicReturnTest method shouldFindPagination.
@Test
public void shouldFindPagination() {
Pagination pagination = Pagination.page(1L).size(2);
Pagination pagination1 = DynamicReturn.findPagination(new Object[] { "value", 23, pagination });
Assertions.assertEquals(pagination, pagination1);
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DynamicReturnTest method shouldReturnNullWhenThereIsNotPagination.
@Test
public void shouldReturnNullWhenThereIsNotPagination() {
Pagination pagination = DynamicReturn.findPagination(new Object[] { "value", 23, BigDecimal.TEN });
assertNull(pagination);
}
use of jakarta.nosql.mapping.Pagination in project jnosql-diana by eclipse.
the class DynamicReturnPaginationTest method shouldReturnErrorWhenExecutePage.
@Test
public void shouldReturnErrorWhenExecutePage() throws NoSuchMethodException {
Method method = getMethod(PersonRepository.class, "getPage");
Supplier<Stream<?>> stream = Stream::empty;
Supplier<Optional<?>> singleResult = DynamicReturn.toSingleResult(method).apply(stream);
Pagination pagination = getPagination();
DynamicReturn<?> dynamicReturn = DynamicReturn.builder().withClassSource(Person.class).withMethodSource(method).withResult(stream).withSingleResult(singleResult).withPagination(pagination).withStreamPagination(streamPagination).withSingleResultPagination(singlePagination).withPage(page).build();
dynamicReturn.execute();
Mockito.verify(singlePagination, Mockito.never()).apply(pagination);
Mockito.verify(streamPagination, Mockito.never()).apply(pagination);
Mockito.verify(page).apply(pagination);
}
Aggregations