Search in sources :

Example 51 with Pagination

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

the class DocumentPageTest method shouldExecutePagination.

@Test
public void shouldExecutePagination() {
    Pagination pagination = Pagination.page(1).size(1);
    DocumentQueryPagination query = DocumentQueryPagination.of(select().from("person").build(), pagination);
    Page<Person> page = subject.select(query);
    verify(managerMock).select(query);
    assertNotNull(page);
    assertEquals(pagination, page.getPagination());
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 52 with Pagination

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

the class DynamicReturnPaginationTest method shouldReturnQueue.

@Test
public void shouldReturnQueue() throws NoSuchMethodException {
    Method method = getMethod(PersonRepository.class, "getQueue");
    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 Queue);
    Queue<Person> persons = (Queue) 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) Queue(java.util.Queue) Test(org.junit.jupiter.api.Test)

Example 53 with Pagination

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

the class DynamicReturnPaginationTest method shouldReturnNavigableSet.

@Test
public void shouldReturnNavigableSet() throws NoSuchMethodException {
    Method method = getMethod(PersonRepository.class, "getNavigableSet");
    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 NavigableSet);
    NavigableSet<Person> persons = (NavigableSet) 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) 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 54 with Pagination

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

the class DynamicReturnPaginationTest method shouldReturnOptional.

@Test
public void shouldReturnOptional() 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.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 Optional);
    Optional<Person> optional = (Optional) execute;
    Assertions.assertTrue(optional.isPresent());
    Assertions.assertEquals(new Person("Ada"), optional.get());
    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 55 with Pagination

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

the class DynamicReturnPaginationTest method shouldReturnNull.

@Test
public void shouldReturnNull() 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.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.assertNull(execute);
    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)

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