Search in sources :

Example 91 with DocumentCondition

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

the class AbstractMapperQuery method ltImpl.

protected <T> void ltImpl(T value) {
    requireNonNull(value, "value is required");
    DocumentCondition newCondition = DocumentCondition.lt(Document.of(mapping.getColumnField(name), getValue(value)));
    appendCondition(newCondition);
}
Also used : DocumentCondition(jakarta.nosql.document.DocumentCondition)

Example 92 with DocumentCondition

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

the class DocumentRepositoryProxySortTest method shouldFindByNameOrderByName2.

@Test
public void shouldFindByNameOrderByName2() {
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(Person.builder().build()));
    Pagination pagination = getPagination();
    personRepository.findByNameOrderByName("name", pagination, Sorts.sorts().desc("age").asc("phone"));
    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(EQUALS, condition.getCondition());
    assertEquals(Document.of("name", "name"), condition.getDocument());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
    assertThat(query.getSorts(), Matchers.contains(Sort.asc("name"), Sort.desc("age"), Sort.asc("phone")));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 93 with DocumentCondition

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

the class DocumentRepositoryProxySortTest method shouldFindByNameAndAge.

@Test
public void shouldFindByNameAndAge() {
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(Person.builder().build()));
    personRepository.findByNameAndAge("name", 10, Sorts.sorts().desc("name"));
    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(AND, condition.getCondition());
    assertEquals(0, query.getSkip());
    assertEquals(0, query.getLimit());
    assertThat(query.getSorts(), Matchers.contains(Sort.desc("name")));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 94 with DocumentCondition

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

the class DocumentRepositoryProxySortTest method shouldFindByAge.

@Test
public void shouldFindByAge() {
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(Person.builder().build()));
    personRepository.findByAge(10, Sort.desc("name"));
    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(Condition.EQUALS, condition.getCondition());
    assertEquals(0, query.getSkip());
    assertEquals(0, query.getLimit());
    assertThat(query.getSorts(), Matchers.contains(Sort.desc("name")));
    assertEquals(Document.of("age", 10), condition.getDocument());
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(Person.builder().build()));
    assertNotNull(personRepository.findByAge(10, Sort.asc("name")));
    when(template.singleResult(any(DocumentQuery.class))).thenReturn(Optional.empty());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 95 with DocumentCondition

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

the class DocumentRepositoryProxySortTest method shouldFindByName.

@Test
public void shouldFindByName() {
    when(template.singleResult(any(DocumentQuery.class))).thenReturn(Optional.of(Person.builder().build()));
    Pagination pagination = getPagination();
    personRepository.findByName("name", pagination, Sort.desc("name"));
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).singleResult(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
    assertThat(query.getSorts(), Matchers.contains(Sort.desc("name")));
    assertEquals(Document.of("name", "name"), condition.getDocument());
    assertNotNull(personRepository.findByName("name", pagination, Sort.asc("name")));
    when(template.singleResult(any(DocumentQuery.class))).thenReturn(Optional.empty());
    assertNull(personRepository.findByName("name", pagination, Sort.asc("name")));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentCondition (jakarta.nosql.document.DocumentCondition)132 Test (org.junit.jupiter.api.Test)68 DocumentQuery (jakarta.nosql.document.DocumentQuery)64 Document (jakarta.nosql.document.Document)60 List (java.util.List)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 ValueSource (org.junit.jupiter.params.provider.ValueSource)37 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)33 Person (jakarta.nosql.tck.entities.Person)17 Pagination (jakarta.nosql.mapping.Pagination)13 DocumentPreparedStatement (jakarta.nosql.document.DocumentPreparedStatement)10 TypeReference (jakarta.nosql.TypeReference)7 Params (jakarta.nosql.Params)6 DocumentEntity (jakarta.nosql.document.DocumentEntity)6 DocumentObserverParser (jakarta.nosql.document.DocumentObserverParser)5 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)4 DocumentQueryParams (jakarta.nosql.document.DocumentQueryParams)4 SelectQueryConverter (jakarta.nosql.document.SelectQueryConverter)4