Search in sources :

Example 21 with Person

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

Example 22 with Person

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

Example 23 with Person

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

Example 24 with 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());
}
Also used : Optional(java.util.Optional) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 25 with Person

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");
}
Also used : PreparedStatement(jakarta.nosql.mapping.PreparedStatement) 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)

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