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