Search in sources :

Example 31 with Person

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);
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 32 with Person

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());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 33 with Person

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));
}
Also used : List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 34 with Person

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));
}
Also used : List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 35 with Person

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));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Aggregations

Person (jakarta.nosql.tck.entities.Person)201 Test (org.junit.jupiter.api.Test)197 DocumentQuery (jakarta.nosql.document.DocumentQuery)50 ColumnQuery (jakarta.nosql.column.ColumnQuery)49 Pagination (jakarta.nosql.mapping.Pagination)42 List (java.util.List)32 AtomicReference (java.util.concurrent.atomic.AtomicReference)29 ColumnCondition (jakarta.nosql.column.ColumnCondition)17 DocumentCondition (jakarta.nosql.document.DocumentCondition)17 Collections.singletonList (java.util.Collections.singletonList)14 Optional (java.util.Optional)13 Arrays.asList (java.util.Arrays.asList)12 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)11 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)11 ColumnQueryPagination (jakarta.nosql.mapping.column.ColumnQueryPagination)9 DocumentQueryPagination (jakarta.nosql.mapping.document.DocumentQueryPagination)9 Duration (java.time.Duration)8 ColumnEntity (jakarta.nosql.column.ColumnEntity)7 DocumentEntity (jakarta.nosql.document.DocumentEntity)7 ArrayList (java.util.ArrayList)7