Search in sources :

Example 26 with Person

use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.

the class ColumnReactiveRepositoryProxyTest method shouldFindByNameANDAge.

@Test
public void shouldFindByNameANDAge() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(Mockito.any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    Publisher<Person> publisher = personRepository.findByNameAndAge("name", 20);
    final CompletionSubscriber<Person, List<Person>> subscriber = ReactiveStreams.<Person>builder().toList().build();
    publisher.subscribe(subscriber);
    AtomicReference<List<Person>> reference = new AtomicReference<>();
    final CompletionStage<List<Person>> completion = subscriber.getCompletion();
    completion.thenAccept(reference::set);
    final List<Person> people = reference.get();
    assertNotNull(people);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    assertThat(people, Matchers.contains(ada));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 27 with Person

use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.

the class ColumnReactiveRepositoryProxyTest method shouldSaveIterable.

@Test
public void shouldSaveIterable() throws ExecutionException, InterruptedException {
    when(template.singleResult(Mockito.any(ColumnQuery.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 : ColumnQuery(jakarta.nosql.column.ColumnQuery) 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 28 with Person

use of jakarta.nosql.tck.entities.Person in project jnosql-diana 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(10L)).thenReturn(Optional.ofNullable(Value.of(person)));
    when(bucketManager.get("user")).thenReturn(Optional.of(Value.of(new User("keyvalueMock", "keyvalueMock", 10))));
    return bucketManager;
}
Also used : User(jakarta.nosql.tck.entities.User) BucketManager(jakarta.nosql.keyvalue.BucketManager) Person(jakarta.nosql.tck.entities.Person) Produces(javax.enterprise.inject.Produces) Database(jakarta.nosql.mapping.Database)

Example 29 with Person

use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.

the class MockProducer method getBucketManager.

@Produces
public BucketManager getBucketManager() {
    BucketManager bucketManager = Mockito.mock(BucketManager.class);
    Person person = Person.builder().withName("Default").build();
    when(bucketManager.get("key")).thenReturn(Optional.ofNullable(Value.of(person)));
    when(bucketManager.get(10L)).thenReturn(Optional.ofNullable(Value.of(person)));
    when(bucketManager.get("user")).thenReturn(Optional.of(Value.of(new User("Default", "Default", 10))));
    return bucketManager;
}
Also used : User(jakarta.nosql.tck.entities.User) BucketManager(jakarta.nosql.keyvalue.BucketManager) Person(jakarta.nosql.tck.entities.Person) Produces(javax.enterprise.inject.Produces)

Example 30 with Person

use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.

the class DocumentReactiveRepositoryProxyTest method shouldSaveUsingUpdateWhenDataExists.

@Test
public void shouldSaveUsingUpdateWhenDataExists() throws ExecutionException, InterruptedException {
    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();
    final Observable<Person> observable = personRepository.save(person);
    assertNotNull(observable);
    final CompletionStage<Optional<Person>> completion = observable.getFirst();
    final Optional<Person> optionalPerson = completion.toCompletableFuture().get();
    verify(template).update(captor.capture());
    Person value = captor.getValue();
    assertEquals(person, value);
    assertNotNull(optionalPerson.isPresent());
}
Also used : Optional(java.util.Optional) 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