Search in sources :

Example 6 with Pagination

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

the class DynamicReturnPaginationTest method shouldReturnSet.

@Test
public void shouldReturnSet() throws NoSuchMethodException {
    Method method = getMethod(PersonRepository.class, "getSet");
    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 Set);
    Set<Person> persons = (Set) 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);
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) SortedSet(java.util.SortedSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) Optional(java.util.Optional) Stream(java.util.stream.Stream) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 7 with Pagination

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

the class DynamicReturnPaginationTest method shouldReturnEmptyOptional.

@Test
public void shouldReturnEmptyOptional() throws NoSuchMethodException {
    Method method = getMethod(PersonRepository.class, "getOptional");
    Supplier<Stream<?>> stream = Stream::empty;
    Supplier<Optional<?>> singleResult = DynamicReturn.toSingleResult(method).apply(stream);
    Pagination pagination = getPagination();
    when(singlePagination.apply(pagination)).thenReturn(Optional.empty());
    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 Optional);
    Optional<Person> optional = (Optional) execute;
    Assertions.assertFalse(optional.isPresent());
    Mockito.verify(singlePagination).apply(pagination);
    Mockito.verify(streamPagination, Mockito.never()).apply(pagination);
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) Optional(java.util.Optional) Stream(java.util.stream.Stream) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 8 with Pagination

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

the class DynamicReturnPaginationTest method shouldReturnCollection.

@Test
public void shouldReturnCollection() throws NoSuchMethodException {
    Method method = getMethod(PersonRepository.class, "getCollection");
    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 Collection);
    Collection<Person> persons = (Collection) 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);
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) Optional(java.util.Optional) Collection(java.util.Collection) Stream(java.util.stream.Stream) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 9 with Pagination

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

the class DynamicReturnPaginationTest method shouldReturnIterable.

@Test
public void shouldReturnIterable() throws NoSuchMethodException {
    Method method = getMethod(PersonRepository.class, "getIterable");
    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 Iterable);
    Iterable<Person> persons = (List) execute;
    Assertions.assertEquals(new Person("Ada"), persons.iterator().next());
    Mockito.verify(singlePagination, Mockito.never()).apply(pagination);
    Mockito.verify(streamPagination).apply(pagination);
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) Optional(java.util.Optional) Stream(java.util.stream.Stream) List(java.util.List) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 10 with Pagination

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

the class DynamicReturnPaginationTest method shouldReturnDeque.

@Test
public void shouldReturnDeque() throws NoSuchMethodException {
    Method method = getMethod(PersonRepository.class, "getDeque");
    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 Deque);
    Deque<Person> persons = (Deque) 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);
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) Optional(java.util.Optional) Stream(java.util.stream.Stream) Method(java.lang.reflect.Method) Deque(java.util.Deque) 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