Search in sources :

Example 21 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.

the class ColumnRepositoryAsyncProxyTest method shoudFindByNameSortPagination.

@Test
public void shoudFindByNameSortPagination() {
    Consumer<List<Person>> callback = v -> {
    };
    Sort sort = Sort.of("age", Sort.SortType.ASC);
    Pagination pagination = Pagination.of(10, 20);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    personRepository.findByName("name", sort, pagination, 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, query.getSorts().get(0));
    assertEquals(pagination.getFirstResult(), query.getFirstResult());
    assertEquals(pagination.getMaxResults(), query.getMaxResults());
}
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) Pagination(org.jnosql.artemis.Pagination) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Consumer(java.util.function.Consumer) Sort(org.jnosql.diana.api.Sort) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 22 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.

the class ColumnRepositoryAsyncProxyTest method shoudFindByName.

@Test
public void shoudFindByName() {
    Consumer<List<Person>> callback = v -> {
    };
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    personRepository.findByName("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());
}
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 23 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.

the class ColumnRepositoryProxyTest method shouldFindByNameAndAgeGreaterEqualThan.

@Test
public void shouldFindByNameAndAgeGreaterEqualThan() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(singletonList(ada));
    personRepository.findByNameAndAgeGreaterThanEqual("Ada", 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(AND, condition.getCondition());
    List<ColumnCondition> conditions = condition.getColumn().get(new TypeReference<List<ColumnCondition>>() {
    });
    assertThat(conditions, containsInAnyOrder(eq(Column.of("name", "Ada")), gte(Column.of("age", 33))));
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Person(org.jnosql.artemis.model.Person) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 24 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.

the class ColumnRepositoryProxyTest method shouldFindByNameANDAgeOrderByAge.

@Test
public void shouldFindByNameANDAgeOrderByAge() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(singletonList(ada));
    Queue<Person> persons = personRepository.findByNameAndAgeOrderByAge("name", 20);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    assertThat(persons, Matchers.contains(ada));
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 25 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.

the class ColumnRepositoryProxyTest method shouldFindByNameANDAge.

@Test
public void shouldFindByNameANDAge() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(singletonList(ada));
    List<Person> persons = personRepository.findByNameAndAge("name", 20);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    assertThat(persons, 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