Search in sources :

Example 1 with Condition

use of org.jnosql.diana.api.Condition 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 2 with Condition

use of org.jnosql.diana.api.Condition 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 3 with Condition

use of org.jnosql.diana.api.Condition in project jnosql-diana-driver by eclipse.

the class QueryUtils method createClause.

private static void createClause(Optional<ColumnCondition> columnConditionOptional, List<Clause> clauses) {
    if (!columnConditionOptional.isPresent()) {
        return;
    }
    ColumnCondition columnCondition = columnConditionOptional.get();
    Column column = columnCondition.getColumn();
    Condition condition = columnCondition.getCondition();
    Object value = column.getValue().get();
    switch(condition) {
        case EQUALS:
            clauses.add(QueryBuilder.eq(getName(column), value));
            return;
        case GREATER_THAN:
            clauses.add(QueryBuilder.gt(getName(column), value));
            return;
        case GREATER_EQUALS_THAN:
            clauses.add(QueryBuilder.gte(getName(column), value));
            return;
        case LESSER_THAN:
            clauses.add(QueryBuilder.lt(getName(column), value));
            return;
        case LESSER_EQUALS_THAN:
            clauses.add(QueryBuilder.lte(getName(column), value));
            return;
        case IN:
            clauses.add(QueryBuilder.in(getName(column), getIinValue(value)));
            return;
        case LIKE:
            clauses.add(QueryBuilder.like(getName(column), value));
            return;
        case AND:
            for (ColumnCondition cc : column.get(new TypeReference<List<ColumnCondition>>() {
            })) {
                createClause(Optional.of(cc), clauses);
            }
            return;
        case OR:
        default:
            throw new UnsupportedOperationException("The columnCondition " + condition + " is not supported in cassandra column driver");
    }
}
Also used : ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Condition(org.jnosql.diana.api.Condition) Column(org.jnosql.diana.api.column.Column) ArrayList(java.util.ArrayList) List(java.util.List) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition)

Example 4 with Condition

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

the class DocumentRepositoryAsyncProxyTest method shouldDeleteByNameCallBack.

@Test
public void shouldDeleteByNameCallBack() {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    Consumer<Void> voidConsumer = v -> {
    };
    personRepository.deleteByName("name", voidConsumer);
    verify(template).delete(captor.capture(), consumerCaptor.capture());
    DocumentDeleteQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(Document.of("name", "name"), condition.getDocument());
    assertEquals(voidConsumer, consumerCaptor.getValue());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Document(org.jnosql.diana.api.document.Document) Converters(org.jnosql.artemis.Converters) Proxy(java.lang.reflect.Proxy) Matchers(org.mockito.Matchers) RepositoryAsync(org.jnosql.artemis.RepositoryAsync) Pagination(org.jnosql.artemis.Pagination) DynamicQueryException(org.jnosql.artemis.DynamicQueryException) 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) Duration(java.time.Duration) DocumentTemplateAsync(org.jnosql.artemis.document.DocumentTemplateAsync) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) Sort(org.jnosql.diana.api.Sort) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) 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) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Consumer(java.util.function.Consumer) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 5 with Condition

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

the class DocumentRepositoryAsyncProxyTest method shoudFindByNameSort.

@Test
public void shoudFindByNameSort() {
    Consumer<List<Person>> callback = v -> {
    };
    Sort sort = Sort.of("age", Sort.SortType.ASC);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    personRepository.findByName("name", sort, callback);
    verify(template).select(captor.capture(), consumerCaptor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(Document.of("name", "name"), condition.getDocument());
    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) Document(org.jnosql.diana.api.document.Document) Converters(org.jnosql.artemis.Converters) Proxy(java.lang.reflect.Proxy) Matchers(org.mockito.Matchers) RepositoryAsync(org.jnosql.artemis.RepositoryAsync) Pagination(org.jnosql.artemis.Pagination) DynamicQueryException(org.jnosql.artemis.DynamicQueryException) 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) Duration(java.time.Duration) DocumentTemplateAsync(org.jnosql.artemis.document.DocumentTemplateAsync) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) Sort(org.jnosql.diana.api.Sort) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) 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) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Consumer(java.util.function.Consumer) Sort(org.jnosql.diana.api.Sort) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Aggregations

List (java.util.List)13 Condition (org.jnosql.diana.api.Condition)13 Proxy (java.lang.reflect.Proxy)12 Duration (java.time.Duration)12 Collections.singletonList (java.util.Collections.singletonList)12 Optional (java.util.Optional)12 Consumer (java.util.function.Consumer)12 Inject (javax.inject.Inject)12 CDIExtension (org.jnosql.artemis.CDIExtension)12 Converters (org.jnosql.artemis.Converters)12 DynamicQueryException (org.jnosql.artemis.DynamicQueryException)12 Pagination (org.jnosql.artemis.Pagination)12 RepositoryAsync (org.jnosql.artemis.RepositoryAsync)12 Person (org.jnosql.artemis.model.Person)12 ClassRepresentations (org.jnosql.artemis.reflection.ClassRepresentations)12 Reflections (org.jnosql.artemis.reflection.Reflections)12 Sort (org.jnosql.diana.api.Sort)12 Assertions (org.junit.jupiter.api.Assertions)12 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)12 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)12