use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis 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 org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.
the class DocumentRepositoryProxyTest method shouldFindByGreaterThan.
@Test
public void shouldFindByGreaterThan() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(singletonList(ada));
personRepository.findByAgeGreaterThan(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(GREATER_THAN, condition.getCondition());
assertEquals(Document.of("age", 33), condition.getDocument());
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.
the class DocumentRepositoryProxyTest method shouldDeleteByName.
@Test
public void shouldDeleteByName() {
ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
personRepository.deleteByName("Ada");
verify(template).delete(captor.capture());
DocumentDeleteQuery deleteQuery = captor.getValue();
DocumentCondition condition = deleteQuery.getCondition().get();
assertEquals("Person", deleteQuery.getDocumentCollection());
assertEquals(Condition.EQUALS, condition.getCondition());
assertEquals(Document.of("name", "Ada"), condition.getDocument());
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis 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(singletonList(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());
}
Aggregations