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));
}
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());
}
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());
}
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());
}
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());
}
Aggregations