Search in sources :

Example 36 with ColumnQuery

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

the class ColumnReactiveRepositoryProxyTest method shouldFindByNameANDAge.

@Test
public void shouldFindByNameANDAge() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(Mockito.any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    Publisher<Person> publisher = personRepository.findByNameAndAge("name", 20);
    final CompletionSubscriber<Person, List<Person>> subscriber = ReactiveStreams.<Person>builder().toList().build();
    publisher.subscribe(subscriber);
    AtomicReference<List<Person>> reference = new AtomicReference<>();
    final CompletionStage<List<Person>> completion = subscriber.getCompletion();
    completion.thenAccept(reference::set);
    final List<Person> people = reference.get();
    assertNotNull(people);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    assertThat(people, Matchers.contains(ada));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 37 with ColumnQuery

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

the class SelectQueryParserTest method shouldReturnParserQuery21.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where name like \"Ada\"" })
public void shouldReturnParserQuery21(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();
    Column column = condition.getColumn();
    assertEquals(Condition.LIKE, condition.getCondition());
    assertEquals("name", column.getName());
    assertEquals("Ada", column.get());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Column(jakarta.nosql.column.Column) ColumnCondition(jakarta.nosql.column.ColumnCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 38 with ColumnQuery

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

the class SelectQueryParserTest method shouldReturnParserQuery9.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God skip 10 limit 12" })
public void shouldReturnParserQuery9(String query) {
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).select(captor.capture());
    ColumnQuery columnQuery = captor.getValue();
    assertTrue(columnQuery.getColumns().isEmpty());
    assertTrue(columnQuery.getSorts().isEmpty());
    assertEquals(12L, columnQuery.getLimit());
    assertEquals(10L, columnQuery.getSkip());
    assertEquals("God", columnQuery.getColumnFamily());
    assertFalse(columnQuery.getCondition().isPresent());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 39 with ColumnQuery

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

the class DefaultColumnQueryParserTest method shouldReturnParserQuery.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God" })
public void shouldReturnParserQuery(String query) {
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    parser.query(query, manager, ColumnObserverParser.EMPTY);
    Mockito.verify(manager).select(captor.capture());
    ColumnQuery columnQuery = captor.getValue();
    assertTrue(columnQuery.getColumns().isEmpty());
    assertTrue(columnQuery.getSorts().isEmpty());
    assertEquals(0L, columnQuery.getLimit());
    assertEquals(0L, columnQuery.getSkip());
    assertEquals("God", columnQuery.getColumnFamily());
    assertFalse(columnQuery.getCondition().isPresent());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with ColumnQuery

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

the class DefaultColumnQueryParserTest method shouldReturnEmptySingleResult.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where age = @age" })
public void shouldReturnEmptySingleResult(String query) {
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    Mockito.when(manager.select(Mockito.any(ColumnQuery.class))).thenReturn(Stream.empty());
    ColumnPreparedStatement prepare = parser.prepare(query, manager, ColumnObserverParser.EMPTY);
    prepare.bind("age", 12);
    final Optional<ColumnEntity> result = prepare.getSingleResult();
    Mockito.verify(manager).select(captor.capture());
    ColumnQuery columnQuery = captor.getValue();
    ColumnCondition columnCondition = columnQuery.getCondition().get();
    Column column = columnCondition.getColumn();
    assertEquals(Condition.EQUALS, columnCondition.getCondition());
    assertEquals("age", column.getName());
    assertEquals(12, column.get());
    assertFalse(result.isPresent());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) ColumnPreparedStatement(jakarta.nosql.column.ColumnPreparedStatement) Column(jakarta.nosql.column.Column) ColumnCondition(jakarta.nosql.column.ColumnCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ColumnQuery (jakarta.nosql.column.ColumnQuery)160 Test (org.junit.jupiter.api.Test)120 ColumnCondition (jakarta.nosql.column.ColumnCondition)64 Person (jakarta.nosql.tck.entities.Person)50 Column (jakarta.nosql.column.Column)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)30 ValueSource (org.junit.jupiter.params.provider.ValueSource)30 Pagination (jakarta.nosql.mapping.Pagination)27 ColumnEntity (jakarta.nosql.column.ColumnEntity)26 List (java.util.List)26 Collections.singletonList (java.util.Collections.singletonList)10 Value (jakarta.nosql.Value)8 ColumnQueryPagination (jakarta.nosql.mapping.column.ColumnQueryPagination)8 Arrays.asList (java.util.Arrays.asList)8 Params (jakarta.nosql.Params)7 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)7 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)7 ColumnQueryParams (jakarta.nosql.column.ColumnQueryParams)7 ColumnTemplate (jakarta.nosql.mapping.column.ColumnTemplate)6 SelectQuery (jakarta.nosql.query.SelectQuery)6