use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DocumentRepositoryProxyTest 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));
personRepository.findByAge("120");
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());
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DocumentRepositoryProxyPaginationTest method shouldFindByNameAndAgeGreaterEqualThan.
@Test
public void shouldFindByNameAndAgeGreaterEqualThan() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
Pagination pagination = getPagination();
personRepository.findByNameAndAgeGreaterThanEqual("Ada", 33, 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(AND, condition.getCondition());
List<DocumentCondition> conditions = condition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
});
DocumentCondition columnCondition = conditions.get(0);
DocumentCondition columnCondition2 = conditions.get(1);
assertEquals(Condition.EQUALS, columnCondition.getCondition());
assertEquals("Ada", columnCondition.getDocument().get());
assertEquals("name", columnCondition.getDocument().getName());
assertEquals(Condition.GREATER_EQUALS_THAN, columnCondition2.getCondition());
assertEquals(33, columnCondition2.getDocument().get());
assertEquals("age", columnCondition2.getDocument().getName());
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 shouldFindByAgeBetween.
@Test
public void shouldFindByAgeBetween() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
Pagination pagination = getPagination();
personRepository.findByAgeBetween(10, 15, 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(BETWEEN, condition.getCondition());
List<Value> values = condition.getDocument().get(new TypeReference<List<Value>>() {
});
assertEquals(Arrays.asList(10, 15), values.stream().map(Value::get).collect(Collectors.toList()));
assertTrue(condition.getDocument().getName().contains("age"));
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 shouldFindByAgeLessEqual.
@Test
public void shouldFindByAgeLessEqual() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
Pagination pagination = getPagination();
personRepository.findByAgeLessThan(33, 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(LESSER_THAN, condition.getCondition());
assertEquals(Document.of("age", 33), 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 shouldFindByNameLike.
@Test
public void shouldFindByNameLike() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
Pagination pagination = getPagination();
personRepository.findByNameLike("Ada", 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(LIKE, condition.getCondition());
assertEquals(Document.of("name", "Ada"), condition.getDocument());
assertEquals(pagination.getSkip(), query.getSkip());
assertEquals(pagination.getLimit(), query.getLimit());
}
Aggregations