Search in sources :

Example 41 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana 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("contact_name", "Ada"), Document.of("type", ContactType.EMAIL), Document.of("information", "ada@lovelace.com")));
    documents.add(asList(Document.of("contact_name", "Ada"), Document.of("type", ContactType.MOBILE), Document.of("information", "11 1231231 123")));
    documents.add(asList(Document.of("contact_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(jakarta.nosql.document.DocumentEntity) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) AppointmentBook(jakarta.nosql.tck.entities.AppointmentBook) Contact(jakarta.nosql.tck.entities.Contact) Test(org.junit.jupiter.api.Test)

Example 42 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.

the class DefaultDocumentEntityConverterTest method shouldCreateLazilyEntity.

@Test
public void shouldCreateLazilyEntity() {
    DocumentEntity entity = DocumentEntity.of("Citizen");
    entity.add("id", "10");
    entity.add("name", "Salvador");
    Citizen citizen = converter.toEntity(entity);
    Assertions.assertNotNull(citizen);
    assertNull(citizen.getCity());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Citizen(org.eclipse.jnosql.mapping.document.entities.Citizen) Test(org.junit.jupiter.api.Test)

Example 43 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.

the class DefaultDocumentEntityConverterTest method shouldConvertAndDoNotUseUnmodifiableCollection.

@Test
public void shouldConvertAndDoNotUseUnmodifiableCollection() {
    DocumentEntity entity = DocumentEntity.of("vendors");
    entity.add("name", "name");
    entity.add("prefixes", Arrays.asList("value", "value2"));
    Vendor vendor = converter.toEntity(entity);
    vendor.add("value3");
    Assertions.assertEquals(3, vendor.getPrefixes().size());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Vendor(jakarta.nosql.tck.entities.Vendor) Test(org.junit.jupiter.api.Test)

Example 44 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.

the class DefaultDocumentEntityConverterTest method shouldConvertToEntityWhenHasConverter.

@Test
public void shouldConvertToEntityWhenHasConverter() {
    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);
    Worker worker1 = converter.toEntity(entity);
    assertEquals(worker.getSalary(), worker1.getSalary());
    assertEquals(job.getCity(), worker1.getJob().getCity());
    assertEquals(job.getDescription(), worker1.getJob().getDescription());
}
Also used : Money(jakarta.nosql.tck.entities.Money) DocumentEntity(jakarta.nosql.document.DocumentEntity) Worker(jakarta.nosql.tck.entities.Worker) Job(jakarta.nosql.tck.entities.Job) Test(org.junit.jupiter.api.Test)

Example 45 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.

the class DefaultDocumentEntityConverterTest method shouldConvertDocumentEntityFromEntity2.

@Test
public void shouldConvertDocumentEntityFromEntity2() {
    DocumentEntity entity = DocumentEntity.of("Actor");
    Stream.of(documents).forEach(entity::add);
    Actor actor = converter.toEntity(Actor.class, entity);
    assertNotNull(actor);
    assertEquals(10, actor.getAge());
    assertEquals(12L, actor.getId());
    assertEquals(Arrays.asList("234", "2342"), actor.getPhones());
    assertEquals(Collections.singletonMap("JavaZone", "Jedi"), actor.getMovieCharacter());
    assertEquals(Collections.singletonMap("JavaZone", 10), actor.getMovieRating());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Actor(jakarta.nosql.tck.entities.Actor) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentEntity (jakarta.nosql.document.DocumentEntity)312 Test (org.junit.jupiter.api.Test)238 DocumentQuery (jakarta.nosql.document.DocumentQuery)131 Document (jakarta.nosql.document.Document)129 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)62 List (java.util.List)54 Arrays.asList (java.util.Arrays.asList)51 ArrayList (java.util.ArrayList)46 Duration (java.time.Duration)31 HashMap (java.util.HashMap)30 Map (java.util.Map)27 Collectors (java.util.stream.Collectors)27 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)25 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 ValueSource (org.junit.jupiter.params.provider.ValueSource)23 TypeReference (jakarta.nosql.TypeReference)21 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)21 Matchers.contains (org.hamcrest.Matchers.contains)21 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)21