Search in sources :

Example 91 with ColumnCondition

use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.

the class ColumnRepositoryProxySortTest method shouldFindByName.

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

Example 92 with ColumnCondition

use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.

the class ColumnRepositoryProxySortTest method shouldFindByNameAndAge.

@Test
public void shouldFindByNameAndAge() {
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(Person.builder().build()));
    personRepository.findByNameAndAge("name", 10, Sorts.sorts().desc("name"));
    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());
    assertEquals(0, query.getSkip());
    assertEquals(0, query.getLimit());
    assertThat(query.getSorts(), Matchers.contains(Sort.desc("name")));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 93 with ColumnCondition

use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.

the class ColumnRepositoryProxySortTest method shouldFindByAge.

@Test
public void shouldFindByAge() {
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(Person.builder().build()));
    personRepository.findByAge(10, Sort.desc("name"));
    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(Condition.EQUALS, condition.getCondition());
    assertEquals(0, query.getSkip());
    assertEquals(0, query.getLimit());
    assertThat(query.getSorts(), Matchers.contains(Sort.desc("name")));
    assertEquals(Column.of("age", 10), condition.getColumn());
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(Person.builder().build()));
    assertNotNull(personRepository.findByAge(10, Sort.asc("name")));
    when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional.empty());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 94 with ColumnCondition

use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.

the class ColumnRepositoryProxySortTest method shouldFindByNameOrderByName.

@Test
public void shouldFindByNameOrderByName() {
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of((Person.builder().build())));
    Pagination pagination = getPagination();
    personRepository.findByNameOrderByName("name", pagination, Sort.desc("age"));
    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("name", "name"), condition.getColumn());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
    assertThat(query.getSorts(), Matchers.contains(Sort.asc("name"), Sort.desc("age")));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 95 with ColumnCondition

use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.

the class ColumnRepositoryProxyTest 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));
    personRepository.findByNameLike("Ada");
    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());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Person(jakarta.nosql.tck.entities.Person) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnCondition (jakarta.nosql.column.ColumnCondition)130 Test (org.junit.jupiter.api.Test)68 ColumnQuery (jakarta.nosql.column.ColumnQuery)64 Column (jakarta.nosql.column.Column)57 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 ValueSource (org.junit.jupiter.params.provider.ValueSource)37 List (java.util.List)34 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)33 Person (jakarta.nosql.tck.entities.Person)17 Pagination (jakarta.nosql.mapping.Pagination)13 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)10 TypeReference (jakarta.nosql.TypeReference)7 Params (jakarta.nosql.Params)6 ColumnEntity (jakarta.nosql.column.ColumnEntity)6 Collections.singletonList (java.util.Collections.singletonList)5 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)4 ColumnObserverParser (jakarta.nosql.column.ColumnObserverParser)4 ColumnQueryParams (jakarta.nosql.column.ColumnQueryParams)4