Search in sources :

Example 6 with DocumentQueryPagination

use of jakarta.nosql.mapping.document.DocumentQueryPagination 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 7 with DocumentQueryPagination

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

the class DefaultDocumentQueryPaginationTest method shouldCreateDocumentQueryPagination.

@Test
public void shouldCreateDocumentQueryPagination() {
    DocumentQuery query = select().from("column").build();
    Pagination pagination = Pagination.page(1).size(2);
    DocumentQueryPagination queryPagination = DocumentQueryPagination.of(query, pagination);
    assertNotNull(queryPagination);
    isQueryEquals(query, pagination, queryPagination);
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Pagination(jakarta.nosql.mapping.Pagination) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Test(org.junit.jupiter.api.Test)

Example 8 with DocumentQueryPagination

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

the class DefaultDocumentMapperSelectBuilderTest method shouldCreatePage.

@Test
public void shouldCreatePage() {
    Pagination pagination = Pagination.page(2).size(2);
    DocumentTemplate template = Mockito.mock(DocumentTemplate.class);
    ArgumentCaptor<DocumentQueryPagination> queryCaptor = ArgumentCaptor.forClass(DocumentQueryPagination.class);
    Page<Person> page = mapperBuilder.selectFrom(Person.class).page(template, pagination);
    Mockito.verify(template).select(queryCaptor.capture());
    DocumentQuery query = queryCaptor.getValue();
    assertEquals(pagination.getLimit(), query.getLimit());
    assertEquals(pagination.getSkip(), query.getSkip());
}
Also used : DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Pagination(jakarta.nosql.mapping.Pagination) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) DocumentTemplate(jakarta.nosql.mapping.document.DocumentTemplate) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Aggregations

Pagination (jakarta.nosql.mapping.Pagination)8 DocumentQueryPagination (jakarta.nosql.mapping.document.DocumentQueryPagination)8 Test (org.junit.jupiter.api.Test)7 DocumentQuery (jakarta.nosql.document.DocumentQuery)5 Person (jakarta.nosql.tck.entities.Person)3 Document (jakarta.nosql.document.Document)1 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)1 DocumentEntity (jakarta.nosql.document.DocumentEntity)1 DocumentEventPersistManager (jakarta.nosql.mapping.document.DocumentEventPersistManager)1 DocumentTemplate (jakarta.nosql.mapping.document.DocumentTemplate)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1