use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.
the class DefaultColumnMapperSelectBuilderTest method shouldSelectWhereNameEq.
@Test
public void shouldSelectWhereNameEq() {
ColumnQuery query = mapperBuilder.selectFrom(Person.class).where("name").eq("Ada").build();
ColumnQuery queryExpected = select().from("Person").where("name").eq("Ada").build();
assertEquals(queryExpected, query);
}
use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.
the class DefaultDocumentEntityConverterTest method shouldConvertDocumentEntityFromEntity.
@Test
public void shouldConvertDocumentEntityFromEntity() {
Person person = Person.builder().withAge().withId(12).withName("Otavio").withPhones(Arrays.asList("234", "2342")).build();
DocumentEntity entity = converter.toDocument(person);
assertEquals("Person", entity.getName());
assertEquals(4, entity.size());
assertThat(entity.getDocuments(), containsInAnyOrder(Document.of("_id", 12L), Document.of("age", 10), Document.of("name", "Otavio"), Document.of("phones", Arrays.asList("234", "2342"))));
}
use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.
the class ReflectionFieldReaderFactoryTest method shouldRead.
@Test
public void shouldRead() {
Person person = Person.builder().withId(10L).withAge(10).withName("Ada").withPhones(singletonList("234234324")).build();
Field[] fields = Person.class.getDeclaredFields();
Stream.of(fields).forEach(f -> f.setAccessible(true));
Field id = Stream.of(fields).filter(f -> f.getName().equals("id")).findFirst().get();
Field name = Stream.of(fields).filter(f -> f.getName().equals("name")).findFirst().get();
Field age = Stream.of(fields).filter(f -> f.getName().equals("age")).findFirst().get();
Field phones = Stream.of(fields).filter(f -> f.getName().equals("phones")).findFirst().get();
Assertions.assertEquals(10L, readerFactory.apply(id).read(person));
Assertions.assertEquals("Ada", readerFactory.apply(name).read(person));
Assertions.assertEquals(10, readerFactory.apply(age).read(person));
Assertions.assertEquals(singletonList("234234324"), readerFactory.apply(phones).read(person));
}
use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.
the class ColumnReactiveRepositoryProxyTest 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());
}
use of jakarta.nosql.tck.entities.Person in project jnosql-diana by eclipse.
the class ColumnReactiveRepositoryProxyTest method shouldExecuteJNoSQLPrepare.
@Test
public void shouldExecuteJNoSQLPrepare() {
PreparedStatement statement = Mockito.mock(PreparedStatement.class);
when(template.prepare(Mockito.anyString())).thenReturn(statement);
final Publisher<Person> publisher = personRepository.findByQuery("Ada");
final CompletionSubscriber<Person, List<Person>> subscriber = ReactiveStreams.<Person>builder().toList().build();
publisher.subscribe(subscriber);
final CompletionStage<List<Person>> completion = subscriber.getCompletion();
AtomicReference<List<Person>> reference = new AtomicReference<>();
completion.thenAccept(reference::set);
final List<Person> people = reference.get();
assertNotNull(people);
verify(statement).bind("id", "Ada");
}
Aggregations