use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class ColumnRepositoryAsyncProxyTest method shouldFindByNameOrderByAgeDesc.
@Test
public void shouldFindByNameOrderByAgeDesc() {
Consumer<List<Person>> callback = v -> {
};
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
personRepository.findByNameOrderByAgeDesc("name", callback);
verify(template).select(captor.capture(), consumerCaptor.capture());
ColumnQuery query = captor.getValue();
ColumnCondition condition = query.getCondition().get();
assertEquals("Person", query.getColumnFamily());
assertEquals(Condition.EQUALS, condition.getCondition());
assertEquals(Column.of("name", "name"), condition.getColumn());
assertEquals(callback, consumerCaptor.getValue());
assertEquals(Sort.of("age", Sort.SortType.DESC), query.getSorts().get(0));
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class AbstractColumnTemplateAsync method find.
@Override
public <T, ID> void find(Class<T> entityClass, ID id, Consumer<Optional<T>> callBack) {
requireNonNull(entityClass, "entityClass is required");
requireNonNull(id, "id is required");
requireNonNull(callBack, "callBack is required");
ClassRepresentation classRepresentation = getClassRepresentations().get(entityClass);
FieldRepresentation idField = classRepresentation.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
Object value = ConverterUtil.getValue(id, classRepresentation, idField.getFieldName(), getConverters());
ColumnQuery query = ColumnQueryBuilder.select().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
singleResult(query, callBack);
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class ColumnRepositoryProxyTest method shouldFindByGreaterThan.
@Test
public void shouldFindByGreaterThan() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(ColumnQuery.class))).thenReturn(singletonList(ada));
personRepository.findByAgeGreaterThan(33);
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());
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class ColumnRepositoryProxyTest method shouldFindByAgeBetween.
@Test
public void shouldFindByAgeBetween() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(ColumnQuery.class))).thenReturn(singletonList(ada));
personRepository.findByAgeBetween(10, 15);
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(BETWEEN, condition.getCondition());
assertEquals(Column.of("age", Arrays.asList(10, 15)), condition.getColumn());
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class ColumnRepositoryProxyTest method shouldFindByNameANDAgeOrderByName.
@Test
public void shouldFindByNameANDAgeOrderByName() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(ColumnQuery.class))).thenReturn(singletonList(ada));
Stream<Person> persons = personRepository.findByNameAndAgeOrderByName("name", 20);
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
verify(template).select(captor.capture());
assertThat(persons.collect(Collectors.toList()), Matchers.contains(ada));
}
Aggregations