use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.
the class DocumentRepositoryProxyTest method shouldSaveUsingInsertWhenDataDoesNotExist.
@Test
public void shouldSaveUsingInsertWhenDataDoesNotExist() {
when(template.find(Mockito.eq(Person.class), Mockito.eq(10L))).thenReturn(Optional.empty());
ArgumentCaptor<Person> captor = ArgumentCaptor.forClass(Person.class);
Person person = Person.builder().withName("Ada").withId(10L).withPhones(singletonList("123123")).build();
assertNotNull(personRepository.save(person));
verify(template).insert(captor.capture());
Person value = captor.getValue();
assertEquals(person, value);
}
use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.
the class DocumentRepositoryProxyTest method shouldFindByAgeLessEqual.
@Test
public void shouldFindByAgeLessEqual() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(singletonList(ada));
personRepository.findByAgeLessThan(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(LESSER_THAN, condition.getCondition());
assertEquals(Document.of("age", 33), condition.getDocument());
}
use of org.jnosql.artemis.model.Person in project jnosql-artemis 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(singletonList(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 org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.
the class DocumentRepositoryProxyTest method shouldExecuteQuery.
@Test
public void shouldExecuteQuery() {
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.singleResult(Mockito.any(DocumentQuery.class))).thenReturn(Optional.of(ada));
DocumentQuery query = select().from("Person").where("name").eq("Ada").build();
Person person = personRepository.query(query);
verify(template).singleResult(captor.capture());
assertEquals(ada, person);
assertEquals(query, captor.getValue());
}
use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.
the class DocumentRepositoryProxyTest method shouldFindByAgeBetween.
@Test
public void shouldFindByAgeBetween() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(singletonList(ada));
personRepository.findByAgeBetween(10, 15);
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());
assertEquals(Document.of("age", Arrays.asList(10, 15)), condition.getDocument());
}
Aggregations