Search in sources :

Example 96 with Pagination

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

the class ColumnPageTest method setUp.

@BeforeEach
public void setUp() {
    managerMock = Mockito.mock(ColumnFamilyManager.class);
    columnEventPersistManager = Mockito.mock(ColumnEventPersistManager.class);
    captor = ArgumentCaptor.forClass(ColumnEntity.class);
    Instance<ColumnFamilyManager> instance = Mockito.mock(Instance.class);
    when(instance.get()).thenReturn(managerMock);
    this.subject = new DefaultColumnTemplate(converter, instance, new DefaultColumnWorkflow(columnEventPersistManager, converter), columnEventPersistManager, classMappings, converters);
    Pagination pagination = Pagination.page(1).size(1);
    ColumnQueryPagination query = ColumnQueryPagination.of(select().from("person").build(), pagination);
    for (int index = 0; index <= 10; index++) {
        Column[] columns = new Column[] { Column.of("age", index), Column.of("name", "Ada " + index), Column.of("_id", (long) index) };
        ColumnEntity columnEntity = ColumnEntity.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) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) ColumnEventPersistManager(jakarta.nosql.mapping.column.ColumnEventPersistManager) ColumnEntity(jakarta.nosql.column.ColumnEntity) ColumnFamilyManager(jakarta.nosql.column.ColumnFamilyManager) Column(jakarta.nosql.column.Column) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 97 with Pagination

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

the class ColumnPageTest method shouldGetAsStream.

@Test
public void shouldGetAsStream() {
    Pagination pagination = Pagination.page(1).size(1);
    Page<Person> page = createPage(pagination);
    Stream<Person> stream = page.get();
    assertNotNull(stream);
    assertEquals(1L, stream.count());
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 98 with Pagination

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

the class ColumnPageTest method shouldRequestPageTwice.

@Test
public void shouldRequestPageTwice() {
    Pagination pagination = Pagination.page(1).size(1);
    Page<Person> page = createPage(pagination);
    List<Person> people = page.getContent().collect(Collectors.toList());
    assertEquals(1, people.size());
    assertEquals(0L, people.get(0).getId());
    assertNotNull(page.getContent(ArrayList::new));
    assertNotNull(page.getContent(HashSet::new));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 99 with Pagination

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

the class ColumnPageTest method shouldCreatePagination.

@Test
public void shouldCreatePagination() {
    Pagination pagination = Pagination.page(1).size(1);
    Page<Person> page = createPage(pagination);
    assertEquals(0L, page.get().map(Person::getId).findFirst().orElse(-0L));
    Page<Person> nextPage = page.next();
    assertEquals(pagination.next(), nextPage.getPagination());
    assertEquals(1L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
    nextPage = nextPage.next();
    assertEquals(2L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
    nextPage = nextPage.next();
    assertEquals(3L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
    nextPage = nextPage.next();
    assertEquals(4L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
    nextPage = nextPage.next();
    assertEquals(5L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
    nextPage = nextPage.next();
    assertEquals(6L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
    nextPage = nextPage.next();
    assertEquals(7L, nextPage.get().map(Person::getId).findFirst().orElse(-0L));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) ColumnQueryPagination(jakarta.nosql.mapping.column.ColumnQueryPagination) 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