use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.
the class DocumentRepositoryProxyTest method shouldSaveUsingUpdateWhenDataExists.
@Test
public void shouldSaveUsingUpdateWhenDataExists() {
when(template.find(Mockito.eq(Person.class), Mockito.eq(10L))).thenReturn(Optional.of(Person.builder().build()));
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).update(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 shouldFindAll.
@Test
public void shouldFindAll() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(singletonList(ada));
List<Person> persons = personRepository.findAll();
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
DocumentQuery query = captor.getValue();
assertFalse(query.getCondition().isPresent());
assertEquals("Person", query.getDocumentCollection());
}
use of org.jnosql.artemis.model.Person 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());
}
use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.
the class DocumentRepositoryProxyTest method shouldFindByNameANDAgeOrderByName.
@Test
public void shouldFindByNameANDAgeOrderByName() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(Mockito.any(DocumentQuery.class))).thenReturn(singletonList(ada));
Stream<Person> persons = personRepository.findByNameAndAgeOrderByName("name", 20);
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
assertThat(persons.collect(Collectors.toList()), Matchers.contains(ada));
}
use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.
the class MockProducer method getBucketManagerMock.
@Produces
@Database(value = DatabaseType.KEY_VALUE, provider = "keyvalueMock")
public BucketManager getBucketManagerMock() {
BucketManager bucketManager = Mockito.mock(BucketManager.class);
Person person = Person.builder().withName("keyvalueMock").build();
when(bucketManager.get("key")).thenReturn(Optional.ofNullable(Value.of(person)));
when(bucketManager.get("user")).thenReturn(Optional.of(Value.of(new User("keyvalueMock", "keyvalueMock", 10))));
return bucketManager;
}
Aggregations