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")));
}
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));
}
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());
}
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());
}
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());
}
Aggregations