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));
}
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);
}
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;
}
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;
}
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());
}
Aggregations