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