Search in sources :

Example 71 with Pagination

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

the class DocumentRepositoryProxySortTest method shouldFindByName.

@Test
public void shouldFindByName() {
    when(template.singleResult(any(DocumentQuery.class))).thenReturn(Optional.of(Person.builder().build()));
    Pagination pagination = getPagination();
    personRepository.findByName("name", pagination, Sort.desc("name"));
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).singleResult(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
    assertThat(query.getSorts(), Matchers.contains(Sort.desc("name")));
    assertEquals(Document.of("name", "name"), condition.getDocument());
    assertNotNull(personRepository.findByName("name", pagination, Sort.asc("name")));
    when(template.singleResult(any(DocumentQuery.class))).thenReturn(Optional.empty());
    assertNull(personRepository.findByName("name", pagination, Sort.asc("name")));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 72 with Pagination

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

the class DocumentRepositoryProxySortTest method shouldFindByNameOrderByName.

@Test
public void shouldFindByNameOrderByName() {
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(Person.builder().build()));
    Pagination pagination = getPagination();
    personRepository.findByNameOrderByName("name", pagination, Sort.desc("age"));
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(EQUALS, condition.getCondition());
    assertEquals(Document.of("name", "name"), condition.getDocument());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
    assertThat(query.getSorts(), Matchers.contains(Sort.asc("name"), Sort.desc("age")));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 73 with Pagination

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

the class DocumentRepositoryProxyPaginationTest method shouldFindByNameInstance.

@Test
public void shouldFindByNameInstance() {
    when(template.singleResult(any(DocumentQuery.class))).thenReturn(Optional.of(Person.builder().build()));
    Pagination pagination = getPagination();
    personRepository.findByName("name", pagination);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).singleResult(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
    assertEquals(Document.of("name", "name"), condition.getDocument());
    assertNotNull(personRepository.findByName("name", pagination));
    when(template.singleResult(any(DocumentQuery.class))).thenReturn(Optional.empty());
    assertNull(personRepository.findByName("name", pagination));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 74 with Pagination

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

the class DocumentRepositoryProxyPaginationTest method shouldFindAll.

@Test
public void shouldFindAll() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    List<Person> persons = personRepository.findAll(pagination);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    assertFalse(query.getCondition().isPresent());
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 75 with Pagination

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

the class DocumentRepositoryProxyPaginationTest method shouldFindByNameANDAgeOrderByName.

@Test
public void shouldFindByNameANDAgeOrderByName() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    Stream<Person> persons = personRepository.findByNameAndAgeOrderByName("name", 20, pagination);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    assertThat(persons.collect(Collectors.toList()), Matchers.contains(ada));
    DocumentQuery query = captor.getValue();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) 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