Search in sources :

Example 36 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class DefaultColumnEntityConverterTest method shouldConvertFromListEmbeddable.

@Test
public void shouldConvertFromListEmbeddable() {
    ColumnEntity entity = ColumnEntity.of("AppointmentBook");
    entity.add(Column.of("_id", "ids"));
    List<List<Column>> columns = new ArrayList<>();
    columns.add(asList(Column.of("contact_name", "Ada"), Column.of("type", ContactType.EMAIL), Column.of("information", "ada@lovelace.com")));
    columns.add(asList(Column.of("contact_name", "Ada"), Column.of("type", ContactType.MOBILE), Column.of("information", "11 1231231 123")));
    columns.add(asList(Column.of("contact_name", "Ada"), Column.of("type", ContactType.PHONE), Column.of("information", "phone")));
    entity.add(Column.of("contacts", columns));
    AppointmentBook appointmentBook = converter.toEntity(entity);
    List<Contact> contacts = appointmentBook.getContacts();
    assertEquals("ids", appointmentBook.getId());
    assertEquals("Ada", contacts.stream().map(Contact::getName).distinct().findFirst().get());
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) AppointmentBook(jakarta.nosql.tck.entities.AppointmentBook) Contact(jakarta.nosql.tck.entities.Contact) Test(org.junit.jupiter.api.Test)

Example 37 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class DefaultColumnEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubColumn2.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubColumn2() {
    Movie movie = new Movie("Matrix", 2012, singleton("Actor"));
    Director director = Director.builderDirector().withAge(12).withId(12).withName("Otavio").withPhones(asList("234", "2342")).withMovie(movie).build();
    ColumnEntity entity = converter.toColumn(director);
    entity.remove("movie");
    entity.add(Column.of("movie", Arrays.asList(Column.of("title", "Matrix"), Column.of("year", 2012), Column.of("actors", singleton("Actor")))));
    Director director1 = converter.toEntity(entity);
    assertEquals(movie, director1.getMovie());
    assertEquals(director.getName(), director1.getName());
    assertEquals(director.getAge(), director1.getAge());
    assertEquals(director.getId(), director1.getId());
}
Also used : Movie(jakarta.nosql.tck.entities.Movie) ColumnEntity(jakarta.nosql.column.ColumnEntity) Director(jakarta.nosql.tck.entities.Director) Test(org.junit.jupiter.api.Test)

Example 38 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class DefaultColumnEntityConverterTest method shouldCreateUserScope2.

@Test
public void shouldCreateUserScope2() {
    ColumnEntity entity = ColumnEntity.of("UserScope");
    entity.add("_id", "userName");
    entity.add("scope", "scope");
    entity.add("properties", Column.of("halo", "weld"));
    UserScope user = converter.toEntity(entity);
    Assertions.assertNotNull(user);
    Assertions.assertEquals("userName", user.getUserName());
    Assertions.assertEquals("scope", user.getScope());
    Assertions.assertEquals(Collections.singletonMap("halo", "weld"), user.getProperties());
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Example 39 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class DefaultColumnEntityConverterTest method shouldReturnErrorWhenToEntityIsNull.

@Test
public void shouldReturnErrorWhenToEntityIsNull() {
    ColumnEntity entity = ColumnEntity.of("Actor");
    Stream.of(columns).forEach(entity::add);
    Actor actor = Actor.actorBuilder().build();
    assertThrows(NullPointerException.class, () -> converter.toEntity(null, entity));
    assertThrows(NullPointerException.class, () -> converter.toEntity(actor, null));
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Actor(jakarta.nosql.tck.entities.Actor) Test(org.junit.jupiter.api.Test)

Example 40 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity in project jnosql-diana by eclipse.

the class DefaultColumnEntityConverterTest method shouldConvertEntityFromColumnEntity.

@Test
public void shouldConvertEntityFromColumnEntity() {
    Person person = Person.builder().withAge().withId(12).withName("Otavio").withPhones(asList("234", "2342")).build();
    ColumnEntity entity = converter.toColumn(person);
    assertEquals("Person", entity.getName());
    assertEquals(4, entity.size());
    assertThat(entity.getColumns(), containsInAnyOrder(Column.of("_id", 12L), Column.of("age", 10), Column.of("name", "Otavio"), Column.of("phones", Arrays.asList("234", "2342"))));
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnEntity (jakarta.nosql.column.ColumnEntity)146 Test (org.junit.jupiter.api.Test)103 Column (jakarta.nosql.column.Column)39 ColumnQuery (jakarta.nosql.column.ColumnQuery)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 ValueSource (org.junit.jupiter.params.provider.ValueSource)23 Duration (java.time.Duration)13 ArrayList (java.util.ArrayList)13 List (java.util.List)13 Arrays.asList (java.util.Arrays.asList)11 Person (jakarta.nosql.tck.entities.Person)9 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Value (jakarta.nosql.Value)6 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)6 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)5 Actor (jakarta.nosql.tck.entities.Actor)5 Director (jakarta.nosql.tck.entities.Director)5 Movie (jakarta.nosql.tck.entities.Movie)5