Search in sources :

Example 76 with DocumentEntity

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());
}
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 77 with DocumentEntity

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());
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) AppointmentBook(org.jnosql.artemis.model.AppointmentBook) Contact(org.jnosql.artemis.model.Contact) Test(org.junit.jupiter.api.Test)

Example 78 with DocumentEntity

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());
}
Also used : Money(org.jnosql.artemis.model.Money) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Worker(org.jnosql.artemis.model.Worker) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Job(org.jnosql.artemis.model.Job) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 79 with DocumentEntity

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());
}
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 80 with DocumentEntity

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

DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)205 Test (org.junit.jupiter.api.Test)167 Document (org.jnosql.diana.api.document.Document)107 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)101 List (java.util.List)63 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)47 Arrays.asList (java.util.Arrays.asList)38 ArrayList (java.util.ArrayList)36 AtomicReference (java.util.concurrent.atomic.AtomicReference)29 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)25 Duration (java.time.Duration)22 HashMap (java.util.HashMap)21 Consumer (java.util.function.Consumer)19 Arrays (java.util.Arrays)17 Collectors (java.util.stream.Collectors)17 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)17 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 Map (java.util.Map)15 Optional (java.util.Optional)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15