Search in sources :

Example 46 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana 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(Stream.of(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(jakarta.nosql.document.DocumentQuery) Person(jakarta.nosql.tck.entities.Person) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 47 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class DocumentRepositoryProxyTest method shouldFindByNameLike.

@Test
public void shouldFindByNameLike() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
    personRepository.findByNameLike("Ada");
    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(LIKE, condition.getCondition());
    assertEquals(Document.of("name", "Ada"), condition.getDocument());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Person(jakarta.nosql.tck.entities.Person) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 48 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class DefaultDocumentEventPersistManagerTest method shouldFirePreQuery.

@Test
public void shouldFirePreQuery() {
    DocumentQuery query = DocumentQuery.select().from("collection").build();
    subject.firePreQuery(query);
    ArgumentCaptor<DocumentQueryExecute> captor = ArgumentCaptor.forClass(DocumentQueryExecute.class);
    verify(documentQueryExecute).fire(captor.capture());
    assertEquals(query, captor.getValue().getQuery());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentQueryExecute(jakarta.nosql.mapping.document.DocumentQueryExecute) Test(org.junit.jupiter.api.Test)

Example 49 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class DefaultDocumentMapperSelectBuilderTest method shouldSelectOrderAsc.

@Test
public void shouldSelectOrderAsc() {
    DocumentQuery query = mapperBuilder.selectFrom(Worker.class).orderBy("salary").asc().build();
    DocumentQuery queryExpected = select().from("Worker").orderBy("money").asc().build();
    assertEquals(queryExpected, query);
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Worker(jakarta.nosql.tck.entities.Worker) Test(org.junit.jupiter.api.Test)

Example 50 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class DefaultDocumentMapperSelectBuilderTest method shouldCreateQueryWithPagination.

@Test
public void shouldCreateQueryWithPagination() {
    Pagination pagination = Pagination.page(2).size(2);
    DocumentMapperFrom columnFrom = mapperBuilder.selectFrom(Person.class);
    DocumentQuery query = columnFrom.build(pagination);
    assertEquals(pagination.getLimit(), query.getLimit());
    assertEquals(pagination.getSkip(), query.getSkip());
}
Also used : DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Pagination(jakarta.nosql.mapping.Pagination) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentMapperFrom(jakarta.nosql.mapping.document.DocumentQueryMapper.DocumentMapperFrom) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentQuery (jakarta.nosql.document.DocumentQuery)292 Test (org.junit.jupiter.api.Test)234 DocumentEntity (jakarta.nosql.document.DocumentEntity)123 Document (jakarta.nosql.document.Document)98 DocumentCondition (jakarta.nosql.document.DocumentCondition)64 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)55 Person (jakarta.nosql.tck.entities.Person)50 List (java.util.List)50 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)44 Arrays.asList (java.util.Arrays.asList)34 ValueSource (org.junit.jupiter.params.provider.ValueSource)30 Pagination (jakarta.nosql.mapping.Pagination)27 ArrayList (java.util.ArrayList)26 Collectors (java.util.stream.Collectors)19 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)18 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Matchers.contains (org.hamcrest.Matchers.contains)16 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)16 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)16