Search in sources :

Example 96 with DocumentCondition

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

the class DocumentRepositoryProxySortTest method shouldFindByNameOrderByName.

@Test
public void shouldFindByNameOrderByName() {
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(Person.builder().build()));
    Pagination pagination = getPagination();
    personRepository.findByNameOrderByName("name", pagination, Sort.desc("age"));
    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")));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 97 with DocumentCondition

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

the class DocumentRepositoryProxyPaginationTest method shouldFindByNameInstance.

@Test
public void shouldFindByNameInstance() {
    when(template.singleResult(any(DocumentQuery.class))).thenReturn(Optional.of(Person.builder().build()));
    Pagination pagination = getPagination();
    personRepository.findByName("name", pagination);
    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());
    assertEquals(Document.of("name", "name"), condition.getDocument());
    assertNotNull(personRepository.findByName("name", pagination));
    when(template.singleResult(any(DocumentQuery.class))).thenReturn(Optional.empty());
    assertNull(personRepository.findByName("name", pagination));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 98 with DocumentCondition

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

the class DocumentRepositoryProxyPaginationTest method shouldConvertFieldToTheType.

@Test
public void shouldConvertFieldToTheType() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    personRepository.findByAge("120", pagination);
    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("age", 120), condition.getDocument());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) Person(jakarta.nosql.tck.entities.Person) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 99 with DocumentCondition

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

the class DocumentRepositoryProxyPaginationTest method shouldFindByStringWhenFieldIsSet.

@Test
public void shouldFindByStringWhenFieldIsSet() {
    Vendor vendor = new Vendor("vendor");
    vendor.setPrefixes(Collections.singleton("prefix"));
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(vendor));
    Pagination pagination = getPagination();
    vendorRepository.findByPrefixes("prefix", pagination);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).singleResult(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("vendors", query.getDocumentCollection());
    assertEquals(EQUALS, condition.getCondition());
    assertEquals(Document.of("prefixes", "prefix"), condition.getDocument());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) Vendor(jakarta.nosql.tck.entities.Vendor) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 100 with DocumentCondition

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

the class DocumentRepositoryProxyTest method shouldFindBySalary_CurrencyOrderByCurrency_Name.

@Test
public void shouldFindBySalary_CurrencyOrderByCurrency_Name() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
    personRepository.findBySalary_CurrencyOrderByCurrency_Name("USD");
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    final Sort sort = query.getSorts().get(0);
    final Document document = condition.getDocument();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals("salary.currency", document.getName());
    assertEquals("currency.name", sort.getName());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Sort(jakarta.nosql.Sort) Document(jakarta.nosql.document.Document) Person(jakarta.nosql.tck.entities.Person) 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