Search in sources :

Example 96 with ColumnQuery

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));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Converters(org.jnosql.artemis.Converters) Proxy(java.lang.reflect.Proxy) RepositoryAsync(org.jnosql.artemis.RepositoryAsync) Pagination(org.jnosql.artemis.Pagination) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) DynamicQueryException(org.jnosql.artemis.DynamicQueryException) ColumnQueryBuilder.delete(org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Reflections(org.jnosql.artemis.reflection.Reflections) Condition(org.jnosql.diana.api.Condition) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Matchers.eq(org.mockito.Matchers.eq) Duration(java.time.Duration) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Sort(org.jnosql.diana.api.Sort) ColumnTemplateAsync(org.jnosql.artemis.column.ColumnTemplateAsync) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) Column(org.jnosql.diana.api.column.Column) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) List(java.util.List) ColumnQueryBuilder.select(org.jnosql.diana.api.column.query.ColumnQueryBuilder.select) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Consumer(java.util.function.Consumer) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 97 with ColumnQuery

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);
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 98 with ColumnQuery

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());
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Person(org.jnosql.artemis.model.Person) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 99 with ColumnQuery

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());
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Person(org.jnosql.artemis.model.Person) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 100 with ColumnQuery

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));
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)117 Test (org.junit.jupiter.api.Test)113 Person (org.jnosql.artemis.model.Person)37 ColumnCondition (org.jnosql.diana.api.column.ColumnCondition)35 Column (org.jnosql.diana.api.column.Column)29 List (java.util.List)26 ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)26 Collections.singletonList (java.util.Collections.singletonList)20 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)19 Arrays.asList (java.util.Arrays.asList)15 Duration (java.time.Duration)14 ColumnQueryBuilder.delete (org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete)14 ColumnQueryBuilder.select (org.jnosql.diana.api.column.query.ColumnQueryBuilder.select)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Optional (java.util.Optional)13 Consumer (java.util.function.Consumer)13 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)13 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)13 Inject (javax.inject.Inject)12 CDIExtension (org.jnosql.artemis.CDIExtension)12