use of org.jnosql.diana.api.document.DocumentEntity 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());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-artemis by eclipse.
the class DefaultDocumentEntityConverterTest method shouldConvertFromListEmbeddable.
@Test
public void shouldConvertFromListEmbeddable() {
DocumentEntity entity = DocumentEntity.of("AppointmentBook");
entity.add(Document.of("_id", "ids"));
List<List<Document>> documents = new ArrayList<>();
documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.EMAIL), Document.of("information", "ada@lovelace.com")));
documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.MOBILE), Document.of("information", "11 1231231 123")));
documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.PHONE), Document.of("information", "phone")));
entity.add(Document.of("contacts", documents));
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 org.jnosql.diana.api.document.DocumentEntity in project jnosql-artemis by eclipse.
the class DefaultDocumentEntityConverterTest method shouldConvertToDocumentWhenHaConverter.
@Test
public void shouldConvertToDocumentWhenHaConverter() {
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);
DocumentEntity entity = converter.toDocument(worker);
assertEquals("Worker", entity.getName());
assertEquals("Bob", entity.find("name").get().get());
Document subDocument = entity.find("job").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, Matchers.containsInAnyOrder(Document.of("city", "Sao Paulo"), Document.of("description", "Java Developer")));
assertEquals("BRL 10", entity.find("money").get().get());
}
use of org.jnosql.diana.api.document.DocumentEntity 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());
}
use of org.jnosql.diana.api.document.DocumentEntity 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());
}
Aggregations