Search in sources :

Example 1 with AppointmentBook

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

the class DefaultColumnEntityConverterTest method shouldConvertoListEmbeddable.

@Test
public void shouldConvertoListEmbeddable() {
    AppointmentBook appointmentBook = new AppointmentBook("ids");
    appointmentBook.add(Contact.builder().withType(ContactType.EMAIL).withName("Ada").withInformation("ada@lovelace.com").build());
    appointmentBook.add(Contact.builder().withType(ContactType.MOBILE).withName("Ada").withInformation("11 1231231 123").build());
    appointmentBook.add(Contact.builder().withType(ContactType.PHONE).withName("Ada").withInformation("12 123 1231 123123").build());
    ColumnEntity entity = converter.toColumn(appointmentBook);
    Column contacts = entity.find("contacts").get();
    assertEquals("ids", appointmentBook.getId());
    List<List<Column>> columns = (List<List<Column>>) contacts.get();
    assertEquals(3L, columns.stream().flatMap(Collection::stream).filter(c -> c.getName().equals("name")).count());
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Column(org.jnosql.diana.api.column.Column) AppointmentBook(org.jnosql.artemis.model.AppointmentBook) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 2 with AppointmentBook

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

the class DefaultColumnEntityConverterTest method shouldConvertFromListEmbeddable.

@Test
public void shouldConvertFromListEmbeddable() {
    ColumnEntity entity = ColumnEntity.of("AppointmentBook");
    entity.add(Column.of("_id", "ids"));
    List<List<Column>> columns = new ArrayList<>();
    columns.add(asList(Column.of("name", "Ada"), Column.of("type", ContactType.EMAIL), Column.of("information", "ada@lovelace.com")));
    columns.add(asList(Column.of("name", "Ada"), Column.of("type", ContactType.MOBILE), Column.of("information", "11 1231231 123")));
    columns.add(asList(Column.of("name", "Ada"), Column.of("type", ContactType.PHONE), Column.of("information", "phone")));
    entity.add(Column.of("contacts", columns));
    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 : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) 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 3 with AppointmentBook

use of org.jnosql.artemis.model.AppointmentBook 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 4 with AppointmentBook

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

the class DefaultDocumentEntityConverterTest method shouldConvertoListEmbeddable.

@Test
public void shouldConvertoListEmbeddable() {
    AppointmentBook appointmentBook = new AppointmentBook("ids");
    appointmentBook.add(Contact.builder().withType(ContactType.EMAIL).withName("Ada").withInformation("ada@lovelace.com").build());
    appointmentBook.add(Contact.builder().withType(ContactType.MOBILE).withName("Ada").withInformation("11 1231231 123").build());
    appointmentBook.add(Contact.builder().withType(ContactType.PHONE).withName("Ada").withInformation("12 123 1231 123123").build());
    DocumentEntity entity = converter.toDocument(appointmentBook);
    Document contacts = entity.find("contacts").get();
    assertEquals("ids", appointmentBook.getId());
    List<List<Document>> documents = (List<List<Document>>) contacts.get();
    assertEquals(3L, documents.stream().flatMap(Collection::stream).filter(c -> c.getName().equals("name")).count());
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) AppointmentBook(org.jnosql.artemis.model.AppointmentBook) 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

ArrayList (java.util.ArrayList)4 Arrays.asList (java.util.Arrays.asList)4 List (java.util.List)4 AppointmentBook (org.jnosql.artemis.model.AppointmentBook)4 Test (org.junit.jupiter.api.Test)4 Contact (org.jnosql.artemis.model.Contact)2 ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)2 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)2 Column (org.jnosql.diana.api.column.Column)1 Document (org.jnosql.diana.api.document.Document)1