Search in sources :

Example 56 with DocumentCondition

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

the class DocumentRepositoryAsyncProxyTest method shoudFindByName.

@Test
public void shoudFindByName() {
    Consumer<List<Person>> callback = v -> {
    };
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    personRepository.findByName("name", 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());
}
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) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 57 with DocumentCondition

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

the class DocumentRepositoryAsyncProxyTest 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<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    personRepository.findByName("name", sort, pagination, 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));
    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) 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) Pagination(org.jnosql.artemis.Pagination) 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)

Example 58 with DocumentCondition

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

the class DocumentRepositoryAsyncProxyTest method shouldExecuteQuery.

@Test
public void shouldExecuteQuery() {
    Consumer<List<Person>> callback = v -> {
    };
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    DocumentQuery query = select().from("Person").where("name").eq("Ada").build();
    personRepository.query(query, callback);
    verify(template).select(captor.capture(), consumerCaptor.capture());
    DocumentQuery queryCaptor = captor.getValue();
    DocumentCondition 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) 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) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 59 with DocumentCondition

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

the class DocumentRepositoryAsyncProxyTest method shouldFindByNameOrderByAgeDesc.

@Test
public void shouldFindByNameOrderByAgeDesc() {
    Consumer<List<Person>> callback = v -> {
    };
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    personRepository.findByNameOrderByAgeDesc("name", 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.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) 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) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 60 with DocumentCondition

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

the class AbstractMapperQuery method gteImpl.

protected void gteImpl(Number value) {
    requireNonNull(value, "value is required");
    DocumentCondition newCondition = DocumentCondition.gte(Document.of(representation.getColumnField(name), getValue(value)));
    appendCondition(newCondition);
}
Also used : DocumentCondition(org.jnosql.diana.api.document.DocumentCondition)

Aggregations

DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)69 Test (org.junit.jupiter.api.Test)46 Document (org.jnosql.diana.api.document.Document)31 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)29 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)23 List (java.util.List)22 Person (org.jnosql.artemis.model.Person)13 Collections.singletonList (java.util.Collections.singletonList)7 Pagination (org.jnosql.artemis.Pagination)7 Sort (org.jnosql.diana.api.Sort)7 Proxy (java.lang.reflect.Proxy)6 Duration (java.time.Duration)6 Optional (java.util.Optional)6 Consumer (java.util.function.Consumer)6 Inject (javax.inject.Inject)6 CDIExtension (org.jnosql.artemis.CDIExtension)6 Converters (org.jnosql.artemis.Converters)6 DynamicQueryException (org.jnosql.artemis.DynamicQueryException)6 RepositoryAsync (org.jnosql.artemis.RepositoryAsync)6 DocumentTemplateAsync (org.jnosql.artemis.document.DocumentTemplateAsync)6