use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.
the class DefaultColumnEntityConverterTest method shouldConvertSubEntity.
@Test
public void shouldConvertSubEntity() {
Zipcode zipcode = new Zipcode();
zipcode.setZip("12321");
zipcode.setPlusFour("1234");
Address address = new Address();
address.setCity("Salvador");
address.setState("Bahia");
address.setStreet("Rua Engenheiro Jose Anasoh");
address.setZipcode(zipcode);
ColumnEntity columnEntity = converter.toColumn(address);
List<Column> columns = columnEntity.getColumns();
assertEquals("Address", columnEntity.getName());
assertEquals(5, columns.size());
assertEquals("Rua Engenheiro Jose Anasoh", getValue(columnEntity.find("street")));
assertEquals("Salvador", getValue(columnEntity.find("city")));
assertEquals("Bahia", getValue(columnEntity.find("state")));
assertEquals("12321", getValue(columnEntity.find("zip")));
assertEquals("1234", getValue(columnEntity.find("plusFour")));
}
use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.
the class DefaultColumnEntityConverterTest method shouldConvertEntityToColumnEntity2.
@Test
public void shouldConvertEntityToColumnEntity2() {
Movie movie = new Movie("Matrix", 2012, Collections.singleton("Actor"));
Director director = Director.builderDiretor().withAge(12).withId(12).withName("Otavio").withPhones(asList("234", "2342")).withMovie(movie).build();
ColumnEntity entity = converter.toColumn(director);
assertEquals(5, entity.size());
assertEquals(getValue(entity.find("name")), director.getName());
assertEquals(getValue(entity.find("age")), director.getAge());
assertEquals(getValue(entity.find("_id")), director.getId());
assertEquals(getValue(entity.find("phones")), director.getPhones());
Column subColumn = entity.find("movie").get();
List<Column> columns = subColumn.get(new TypeReference<List<Column>>() {
});
assertEquals(3, columns.size());
assertEquals("movie", subColumn.getName());
assertEquals(movie.getTitle(), columns.stream().filter(c -> "title".equals(c.getName())).findFirst().get().get());
assertEquals(movie.getYear(), columns.stream().filter(c -> "year".equals(c.getName())).findFirst().get().get());
assertEquals(movie.getActors(), columns.stream().filter(c -> "actors".equals(c.getName())).findFirst().get().get());
}
use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.
the class DefaultColumnEntityConverterTest method shouldConvertToColumnWhenHaConverter.
@Test
public void shouldConvertToColumnWhenHaConverter() {
Worker worker = new Worker();
Job job = new Job();
job.setCity("Sao Paulo");
job.setDescription("Java Developer");
worker.setName("Bob");
worker.setSalary(new Money("BRL", BigDecimal.TEN));
worker.setJob(job);
ColumnEntity entity = converter.toColumn(worker);
assertEquals("Worker", entity.getName());
assertEquals("Bob", entity.find("name").get().get());
Column subColumn = entity.find("job").get();
List<Column> columns = subColumn.get(new TypeReference<List<Column>>() {
});
assertThat(columns, Matchers.containsInAnyOrder(Column.of("city", "Sao Paulo"), Column.of("description", "Java Developer")));
assertEquals("BRL 10", entity.find("money").get().get());
}
use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.
the class DefaultColumnEntityConverterTest method shouldConvertColumnInSubEntity.
@Test
public void shouldConvertColumnInSubEntity() {
ColumnEntity entity = ColumnEntity.of("Address");
entity.add(Column.of("street", "Rua Engenheiro Jose Anasoh"));
entity.add(Column.of("city", "Salvador"));
entity.add(Column.of("state", "Bahia"));
entity.add(Column.of("zip", "12321"));
entity.add(Column.of("plusFour", "1234"));
Address address = converter.toEntity(entity);
assertEquals("Rua Engenheiro Jose Anasoh", address.getStreet());
assertEquals("Salvador", address.getCity());
assertEquals("Bahia", address.getState());
assertEquals("12321", address.getZipcode().getZip());
assertEquals("1234", address.getZipcode().getPlusFour());
}
use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.
the class DefaultColumnEntityConverterTest method shouldConvertColumnEntityToEntity2.
@Test
public void shouldConvertColumnEntityToEntity2() {
ColumnEntity entity = ColumnEntity.of("Actor");
Stream.of(columns).forEach(entity::add);
Actor actor = converter.toEntity(entity);
assertNotNull(actor);
assertEquals(10, actor.getAge());
assertEquals(12L, actor.getId());
assertEquals(asList("234", "2342"), actor.getPhones());
assertEquals(Collections.singletonMap("JavaZone", "Jedi"), actor.getMovieCharacter());
assertEquals(Collections.singletonMap("JavaZone", 10), actor.getMovieRating());
}
Aggregations