Search in sources :

Example 21 with Pagination

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

the class ColumnRepositoryProxyPaginationTest method shouldFindByAgeANDName.

@Test
public void shouldFindByAgeANDName() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    Set<Person> persons = personRepository.findByAgeAndName(20, "name", pagination);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    assertThat(persons, Matchers.contains(ada));
    ColumnQuery query = captor.getValue();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 22 with Pagination

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

the class ColumnRepositoryProxyPaginationTest method shouldFindByNameAndAgeGreaterEqualThan.

@Test
public void shouldFindByNameAndAgeGreaterEqualThan() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    personRepository.findByNameAndAgeGreaterThanEqual("Ada", 33, pagination);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    ColumnQuery query = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(AND, condition.getCondition());
    List<ColumnCondition> conditions = condition.getColumn().get(new TypeReference<List<ColumnCondition>>() {
    });
    ColumnCondition columnCondition = conditions.get(0);
    ColumnCondition columnCondition2 = conditions.get(1);
    assertEquals(Condition.EQUALS, columnCondition.getCondition());
    assertEquals("Ada", columnCondition.getColumn().get());
    assertEquals("name", columnCondition.getColumn().getName());
    assertEquals(Condition.GREATER_EQUALS_THAN, columnCondition2.getCondition());
    assertEquals(33, columnCondition2.getColumn().get());
    assertEquals("age", columnCondition2.getColumn().getName());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Person(jakarta.nosql.tck.entities.Person) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 23 with Pagination

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

the class ColumnRepositoryProxyPaginationTest method shouldConvertFieldToTheType.

@Test
public void shouldConvertFieldToTheType() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    personRepository.findByAge("120", pagination);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    ColumnQuery query = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(EQUALS, condition.getCondition());
    assertEquals(Column.of("age", 120), condition.getColumn());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) Person(jakarta.nosql.tck.entities.Person) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 24 with Pagination

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

the class ColumnRepositoryProxyPaginationTest method shouldFindByNameANDAgeOrderByAge.

@Test
public void shouldFindByNameANDAgeOrderByAge() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    Queue<Person> persons = personRepository.findByNameAndAgeOrderByAge("name", 20, pagination);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    assertThat(persons, Matchers.contains(ada));
    ColumnQuery query = captor.getValue();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 25 with Pagination

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

the class ColumnRepositoryProxyPaginationTest method shouldFindByNameLike.

@Test
public void shouldFindByNameLike() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    personRepository.findByNameLike("Ada", pagination);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    ColumnQuery query = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(LIKE, condition.getCondition());
    assertEquals(Column.of("name", "Ada"), condition.getColumn());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) Person(jakarta.nosql.tck.entities.Person) ColumnCondition(jakarta.nosql.column.ColumnCondition) 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