Search in sources :

Example 6 with Director

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

the class DefaultDocumentEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubDocument3.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubDocument3() {
    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");
    Map<String, Object> map = new HashMap<>();
    map.put("title", "Matrix");
    map.put("year", 2012);
    map.put("actors", singleton("Actor"));
    entity.add(Document.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) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) HashMap(java.util.HashMap) Director(org.jnosql.artemis.model.Director) Test(org.junit.jupiter.api.Test)

Example 7 with Director

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

the class DefaultDocumentEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubDocument.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubDocument() {
    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);
    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)

Example 8 with Director

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

the class DefaultDocumentEntityConverterTest method shouldConvertEntityFromDocumentEntity2.

@Test
public void shouldConvertEntityFromDocumentEntity2() {
    Movie movie = new Movie("Matriz", 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);
    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());
    Document subdocument = entity.find("movie").get();
    List<Document> documents = subdocument.get(new TypeReference<List<Document>>() {
    });
    assertEquals(3, documents.size());
    assertEquals("movie", subdocument.getName());
    assertEquals(movie.getTitle(), getValue(documents.stream().filter(d -> "title".equals(d.getName())).findFirst()));
    assertEquals(movie.getYear(), getValue(documents.stream().filter(d -> "year".equals(d.getName())).findFirst()));
    assertEquals(movie.getActors(), getValue(documents.stream().filter(d -> "actors".equals(d.getName())).findFirst()));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Document(org.jnosql.diana.api.document.Document) Arrays(java.util.Arrays) Money(org.jnosql.artemis.model.Money) TypeReference(org.jnosql.diana.api.TypeReference) Address(org.jnosql.artemis.model.Address) HashMap(java.util.HashMap) Job(org.jnosql.artemis.model.Job) ArrayList(java.util.ArrayList) Person(org.jnosql.artemis.model.Person) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) BigDecimal(java.math.BigDecimal) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Collections.singleton(java.util.Collections.singleton) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Actor(org.jnosql.artemis.model.Actor) Collection(java.util.Collection) ContactType(org.jnosql.artemis.model.ContactType) Matchers(org.hamcrest.Matchers) Zipcode(org.jnosql.artemis.model.Zipcode) Director(org.jnosql.artemis.model.Director) Test(org.junit.jupiter.api.Test) AppointmentBook(org.jnosql.artemis.model.AppointmentBook) List(java.util.List) Stream(java.util.stream.Stream) Movie(org.jnosql.artemis.model.Movie) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Value(org.jnosql.diana.api.Value) Optional(java.util.Optional) Contact(org.jnosql.artemis.model.Contact) Collections(java.util.Collections) Worker(org.jnosql.artemis.model.Worker) Movie(org.jnosql.artemis.model.Movie) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Director(org.jnosql.artemis.model.Director) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(org.jnosql.diana.api.document.Document) 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