use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.
the class DocumentReactiveRepositoryProxyTest method shouldSaveIterable.
@Test
public void shouldSaveIterable() throws ExecutionException, InterruptedException {
when(template.singleResult(Mockito.any(DocumentQuery.class))).thenReturn(Optional.empty());
ArgumentCaptor<Person> captor = ArgumentCaptor.forClass(Person.class);
Person person = Person.builder().withName("Ada").withId(10L).withPhones(singletonList("123123")).build();
final Observable<Person> observable = personRepository.save(singletonList(person));
final CompletableFuture<List<Person>> future = observable.getList().toCompletableFuture();
final List<Person> people = future.get();
assertNotNull(people);
verify(template).insert(captor.capture());
verify(template).insert(captor.capture());
Person personCapture = captor.getValue();
assertEquals(person, personCapture);
}
use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.
the class DocumentReactiveRepositoryProxyTest method shouldFindAll.
@Test
public void shouldFindAll() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(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 jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.
the class DefaultReactiveDocumentTemplateTest method shouldFind.
@Test
public void shouldFind() {
AtomicReference<List<Person>> reference = new AtomicReference<>();
Person ada = Person.builder().withId(1L).withAge(30).withName("Ada").build();
Mockito.when(template.find(Person.class, 1L)).thenReturn(Optional.of(ada));
final Observable<Person> observable = manager.find(Person.class, 1L);
Mockito.verify(template, Mockito.never()).find(Person.class, 1L);
CompletionStage<List<Person>> completion = observable.getList();
completion.thenAccept(reference::set);
Mockito.verify(template).find(Person.class, 1L);
MatcherAssert.assertThat(reference.get(), Matchers.containsInAnyOrder(ada));
}
use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.
the class DefaultReactiveDocumentTemplateTest method shouldInsertIterable.
@Test
public void shouldInsertIterable() {
AtomicReference<List<Person>> reference = new AtomicReference<>();
Person ada = Person.builder().withId(1L).withAge(30).withName("Ada").build();
Collection<Person> adas = Arrays.asList(ada, ada);
Mockito.when(template.insert(adas)).thenReturn(adas);
final Observable<Person> observable = manager.insert(adas);
Mockito.verify(template, Mockito.never()).insert(adas);
CompletionStage<List<Person>> completion = observable.getList();
completion.thenAccept(reference::set);
Mockito.verify(template).insert(adas);
MatcherAssert.assertThat(reference.get(), Matchers.containsInAnyOrder(ada, ada));
}
use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.
the class DefaultReactiveDocumentTemplateTest method shouldSelect.
@Test
public void shouldSelect() {
DocumentQuery query = Mockito.mock(DocumentQuery.class);
AtomicReference<List<Person>> reference = new AtomicReference<>();
Person ada = Person.builder().withId(1L).withAge(30).withName("Ada").build();
Mockito.when(template.select(query)).thenReturn(Stream.of(ada));
final Observable<Person> observable = manager.select(query);
Mockito.verify(template, Mockito.never()).select(query);
CompletionStage<List<Person>> completion = observable.getList();
completion.thenAccept(reference::set);
Mockito.verify(template).select(query);
MatcherAssert.assertThat(reference.get(), Matchers.containsInAnyOrder(ada));
}
Aggregations