Search in sources :

Example 1 with Director

use of org.jnosql.artemis.model.Director in project jnosql-artemis by eclipse.

the class DefaultColumnEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubColumn.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubColumn() {
    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);
    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(org.jnosql.artemis.model.Movie) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Director(org.jnosql.artemis.model.Director) Test(org.junit.jupiter.api.Test)

Example 2 with Director

use of org.jnosql.artemis.model.Director in project jnosql-artemis by eclipse.

the class DefaultColumnEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubColumn3.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubColumn3() {
    Movie movie = new Movie("Matrix", 2012, singleton("Actor"));
    Director director = Director.builderDiretor().withAge(12).withId(12).withName("Otavio").withPhones(asList("234", "2342")).withMovie(movie).build();
    ColumnEntity entity = converter.toColumn(director);
    entity.remove("movie");
    Map<String, Object> map = new HashMap<>();
    map.put("title", "Matrix");
    map.put("year", 2012);
    map.put("actors", singleton("Actor"));
    entity.add(Column.of("movie", map));
    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(org.jnosql.artemis.model.Movie) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) HashMap(java.util.HashMap) Director(org.jnosql.artemis.model.Director) Test(org.junit.jupiter.api.Test)

Example 3 with Director

use of org.jnosql.artemis.model.Director 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());
}
Also used : Movie(org.jnosql.artemis.model.Movie) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Column(org.jnosql.diana.api.column.Column) Director(org.jnosql.artemis.model.Director) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 4 with Director

use of org.jnosql.artemis.model.Director in project jnosql-artemis by eclipse.

the class DefaultColumnEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubColumn2.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubColumn2() {
    Movie movie = new Movie("Matrix", 2012, singleton("Actor"));
    Director director = Director.builderDiretor().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("title", "Matrix"));
    entity.add(Column.of("year", 2012));
    entity.add(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(org.jnosql.artemis.model.Movie) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Director(org.jnosql.artemis.model.Director) Test(org.junit.jupiter.api.Test)

Example 5 with Director

use of org.jnosql.artemis.model.Director in project jnosql-artemis by eclipse.

the class DefaultDocumentEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubDocument2.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubDocument2() {
    Movie movie = new Movie("Matrix", 2012, singleton("Actor"));
    Director director = Director.builderDiretor().withAge(12).withId(12).withName("Otavio").withPhones(Arrays.asList("234", "2342")).withMovie(movie).build();
    DocumentEntity entity = converter.toDocument(director);
    entity.remove("movie");
    entity.add(Document.of("title", "Matrix"));
    entity.add(Document.of("year", 2012));
    entity.add(Document.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(org.jnosql.artemis.model.Movie) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Director(org.jnosql.artemis.model.Director) Test(org.junit.jupiter.api.Test)

Aggregations

Director (org.jnosql.artemis.model.Director)8 Movie (org.jnosql.artemis.model.Movie)8 Test (org.junit.jupiter.api.Test)8 ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)4 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 BigDecimal (java.math.BigDecimal)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.singleton (java.util.Collections.singleton)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Stream (java.util.stream.Stream)1 Inject (javax.inject.Inject)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers (org.hamcrest.Matchers)1