Search in sources :

Example 51 with DocumentCondition

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

the class DocumentQueryDeleteParserTest method shouldDeleteByNameAndAAgeBetween.

@Test
public void shouldDeleteByNameAndAAgeBetween() {
    DocumentDeleteQuery query = parser.parse("deleteByNameAndAgeBetween", new Object[] { "name", 10, 11 }, classRepresentation, converters);
    assertEquals("Person", query.getDocumentCollection());
    DocumentCondition condition = query.getCondition().get();
    assertEquals(Condition.AND, condition.getCondition());
    List<DocumentCondition> conditions = condition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    });
    DocumentCondition condition1 = conditions.get(0);
    assertEquals(Condition.EQUALS, condition1.getCondition());
    assertEquals(Document.of("name", "name"), condition1.getDocument());
    DocumentCondition condition2 = conditions.get(1);
    assertEquals(Condition.BETWEEN, condition2.getCondition());
    assertEquals(Document.of("age", Arrays.asList(10, 11)), condition2.getDocument());
}
Also used : List(java.util.List) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 52 with DocumentCondition

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

the class DocumentQueryParserTest method shouldFindByNameOrAge.

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

Example 53 with DocumentCondition

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

the class DocumentQueryParserTest method shouldFindByNameAndAge.

@Test
public void shouldFindByNameAndAge() {
    DocumentQuery query = parser.parse("findByNameAndAge", new Object[] { "name", 10 }, classRepresentation, converters);
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.AND, condition.getCondition());
    List<DocumentCondition> conditions = condition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    });
    DocumentCondition condition1 = conditions.get(0);
    assertEquals(Condition.EQUALS, condition1.getCondition());
    assertEquals(Document.of("name", "name"), condition1.getDocument());
    DocumentCondition condition2 = conditions.get(1);
    assertEquals(Condition.EQUALS, condition2.getCondition());
    assertEquals(Document.of("age", 10), condition2.getDocument());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) List(java.util.List) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 54 with DocumentCondition

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

the class DocumentRepositoryAsyncProxyTest method shouldDeleteByName.

@Test
public void shouldDeleteByName() {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    personRepository.deleteByName("name");
    verify(template).delete(captor.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());
}
Also used : DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 55 with DocumentCondition

use of org.jnosql.diana.api.document.DocumentCondition 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

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