use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.
the class DocumentRepositoryProxyTest method shouldFindByAgeANDName.
@Test
public void shouldFindByAgeANDName() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(Mockito.any(DocumentQuery.class))).thenReturn(Stream.of(ada));
Set<Person> persons = personRepository.findByAgeAndName(20, "name");
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
assertThat(persons, Matchers.contains(ada));
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.
the class DocumentRepositoryProxyTest method shouldFindByNameInstance.
@Test
public void shouldFindByNameInstance() {
when(template.singleResult(Mockito.any(DocumentQuery.class))).thenReturn(Optional.of(Person.builder().build()));
personRepository.findByName("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(Document.of("name", "name"), condition.getDocument());
assertNotNull(personRepository.findByName("name"));
when(template.singleResult(Mockito.any(DocumentQuery.class))).thenReturn(Optional.empty());
assertNull(personRepository.findByName("name"));
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.
the class DocumentRepositoryProxyTest 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));
personRepository.findByNameAndAgeGreaterThanEqual("Ada", 33);
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());
assertTrue(columnCondition.getDocument().getName().contains("name"));
assertEquals(Condition.GREATER_EQUALS_THAN, columnCondition2.getCondition());
assertEquals(33, columnCondition2.getDocument().get());
assertTrue(columnCondition2.getDocument().getName().contains("age"));
}
use of jakarta.nosql.document.DocumentQuery 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.DocumentQuery in project jnosql-diana by eclipse.
the class DocumentRepositoryProxyPaginationTest method shouldFindByAgeANDName.
@Test
public void shouldFindByAgeANDName() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
Pagination pagination = getPagination();
Set<Person> persons = personRepository.findByAgeAndName(20, "name", pagination);
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
assertThat(persons, Matchers.contains(ada));
DocumentQuery query = captor.getValue();
assertEquals("Person", query.getDocumentCollection());
assertEquals(pagination.getSkip(), query.getSkip());
assertEquals(pagination.getLimit(), query.getLimit());
}
Aggregations