Search in sources :

Example 96 with DocumentQuery

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

the class DocumentQueryParserTest method shouldFindByNameAndAAgeBetween.

@Test
public void shouldFindByNameAndAAgeBetween() {
    DocumentQuery query = parser.parse("findByNameAndAgeBetween", 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 : 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 97 with DocumentQuery

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

the class DocumentRepositoryProxyTest method shouldFindByAgeLessEqual.

@Test
public void shouldFindByAgeLessEqual() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(singletonList(ada));
    personRepository.findByAgeLessThan(33);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(LESSER_THAN, condition.getCondition());
    assertEquals(Document.of("age", 33), condition.getDocument());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Person(org.jnosql.artemis.model.Person) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 98 with DocumentQuery

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

the class DocumentRepositoryProxyTest method shouldFindByAgeANDName.

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

Example 99 with DocumentQuery

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

the class DocumentRepositoryProxyTest method shouldExecuteQuery.

@Test
public void shouldExecuteQuery() {
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.singleResult(Mockito.any(DocumentQuery.class))).thenReturn(Optional.of(ada));
    DocumentQuery query = select().from("Person").where("name").eq("Ada").build();
    Person person = personRepository.query(query);
    verify(template).singleResult(captor.capture());
    assertEquals(ada, person);
    assertEquals(query, captor.getValue());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 100 with DocumentQuery

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

the class DocumentRepositoryProxyTest method shouldFindByAgeBetween.

@Test
public void shouldFindByAgeBetween() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(singletonList(ada));
    personRepository.findByAgeBetween(10, 15);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(BETWEEN, condition.getCondition());
    assertEquals(Document.of("age", Arrays.asList(10, 15)), condition.getDocument());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Person(org.jnosql.artemis.model.Person) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)201 Test (org.junit.jupiter.api.Test)186 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)95 Document (org.jnosql.diana.api.document.Document)84 List (java.util.List)50 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)46 Person (org.jnosql.artemis.model.Person)37 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)35 Arrays.asList (java.util.Arrays.asList)27 ArrayList (java.util.ArrayList)21 Duration (java.time.Duration)20 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)20 Optional (java.util.Optional)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)18 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17 DocumentQueryBuilder.delete (org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete)17 BeforeEach (org.junit.jupiter.api.BeforeEach)17 Consumer (java.util.function.Consumer)16 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)16