Search in sources :

Example 46 with ColumnCondition

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

the class SelectQueryParserTest method shouldReturnParserQuery13.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where stamina <= -10.23" })
public void shouldReturnParserQuery13(String query) {
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).select(captor.capture());
    ColumnQuery columnQuery = captor.getValue();
    checkBaseQuery(columnQuery, 0L, 0L);
    assertTrue(columnQuery.getCondition().isPresent());
    ColumnCondition condition = columnQuery.getCondition().get();
    assertEquals(Condition.LESSER_EQUALS_THAN, condition.getCondition());
    assertEquals(Column.of("stamina", -10.23), condition.getColumn());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnCondition(jakarta.nosql.column.ColumnCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 47 with ColumnCondition

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

the class DefaultColumnTemplateTest method shouldReturnFind.

@Test
public void shouldReturnFind() {
    subject.find(Person.class, "10");
    ArgumentCaptor<ColumnQuery> queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(managerMock).select(queryCaptor.capture());
    ColumnQuery query = queryCaptor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(ColumnCondition.eq(Column.of("_id", 10L)), condition);
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 48 with ColumnCondition

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

the class ColumnRepositoryProxyPaginationTest method shouldFindByNameInstance.

@Test
public void shouldFindByNameInstance() {
    when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional.of(Person.builder().build()));
    Pagination pagination = getPagination();
    personRepository.findByName("name", pagination);
    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());
    assertEquals(Column.of("name", "name"), condition.getColumn());
    assertNotNull(personRepository.findByName("name", pagination));
    when(template.singleResult(any(ColumnQuery.class))).thenReturn(Optional.empty());
    assertNull(personRepository.findByName("name", pagination));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 49 with ColumnCondition

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

the class ColumnRepositoryProxyPaginationTest method shouldFindByGreaterThan.

@Test
public void shouldFindByGreaterThan() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    personRepository.findByAgeGreaterThan(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(GREATER_THAN, condition.getCondition());
    assertEquals(Column.of("age", 33), 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 50 with ColumnCondition

use of jakarta.nosql.column.ColumnCondition 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)

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