Search in sources :

Example 61 with Pagination

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);
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) Optional(java.util.Optional) Stream(java.util.stream.Stream) Method(java.lang.reflect.Method) SortedSet(java.util.SortedSet) Test(org.junit.jupiter.api.Test)

Example 62 with 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());
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) Test(org.junit.jupiter.api.Test)

Example 63 with Pagination

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);
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) Test(org.junit.jupiter.api.Test)

Example 64 with Pagination

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();
    }
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) DocumentEventPersistManager(jakarta.nosql.mapping.document.DocumentEventPersistManager) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Document(jakarta.nosql.document.Document) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 65 with Pagination

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));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Person(jakarta.nosql.tck.entities.Person) 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