Search in sources :

Example 91 with ColumnQuery

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

the class ColumnQueryParserTest method shouldFindByNameWithPageSortArgumentAndIgnore.

@Test
public void shouldFindByNameWithPageSortArgumentAndIgnore() {
    Pagination pagination = Pagination.of(2L, 10);
    Sort sort = Sort.of("age", Sort.SortType.ASC);
    ColumnQuery query = parser.parse("findByName", new Object[] { "name", pagination, sort, "ignore" }, classRepresentation, converters);
    assertEquals("Person", query.getColumnFamily());
    assertEquals(Condition.EQUALS, query.getCondition().get().getCondition());
    assertEquals(Column.of("name", "name"), query.getCondition().get().getColumn());
    assertEquals(pagination.getMaxResults(), query.getMaxResults());
    assertEquals(pagination.getFirstResult(), query.getFirstResult());
    assertEquals(sort, query.getSorts().get(0));
}
Also used : Pagination(org.jnosql.artemis.Pagination) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Sort(org.jnosql.diana.api.Sort) Test(org.junit.jupiter.api.Test)

Example 92 with ColumnQuery

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

the class ColumnQueryParserTest method shouldFindByNameWithSortArgument.

@Test
public void shouldFindByNameWithSortArgument() {
    Sort sort = Sort.of("age", Sort.SortType.ASC);
    ColumnQuery query = parser.parse("findByName", new Object[] { "name", sort }, classRepresentation, converters);
    assertEquals("Person", query.getColumnFamily());
    assertEquals(Condition.EQUALS, query.getCondition().get().getCondition());
    assertEquals(Column.of("name", "name"), query.getCondition().get().getColumn());
    assertEquals(sort, query.getSorts().get(0));
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Sort(org.jnosql.diana.api.Sort) Test(org.junit.jupiter.api.Test)

Example 93 with ColumnQuery

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

the class ColumnQueryParserTest method shouldFindByNameOrAge.

@Test
public void shouldFindByNameOrAge() {
    ColumnQuery query = parser.parse("findByNameOrAge", new Object[] { "name", 10 }, classRepresentation, converters);
    ColumnCondition condition = query.getCondition().get();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(Condition.OR, condition.getCondition());
    List<ColumnCondition> conditions = condition.getColumn().get(new TypeReference<List<ColumnCondition>>() {
    });
    ColumnCondition condition1 = conditions.get(0);
    assertEquals(Condition.EQUALS, condition1.getCondition());
    assertEquals(Column.of("name", "name"), condition1.getColumn());
    ColumnCondition condition2 = conditions.get(1);
    assertEquals(Condition.EQUALS, condition2.getCondition());
    assertEquals(Column.of("age", 10), condition2.getColumn());
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) List(java.util.List) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 94 with ColumnQuery

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

the class ColumnRepositoryAsyncProxyTest method shouldExecuteQuery.

@Test
public void shouldExecuteQuery() {
    Consumer<List<Person>> callback = v -> {
    };
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    ColumnQuery query = select().from("Person").where("name").eq("Ada").build();
    personRepository.query(query, callback);
    verify(template).select(captor.capture(), consumerCaptor.capture());
    ColumnQuery queryCaptor = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals(query, queryCaptor);
    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 95 with ColumnQuery

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

the class ColumnRepositoryAsyncProxyTest method shoudFindByNameSort.

@Test
public void shoudFindByNameSort() {
    Consumer<List<Person>> callback = v -> {
    };
    Sort sort = Sort.of("age", Sort.SortType.ASC);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    personRepository.findByName("name", sort, 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));
}
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) 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)

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