Search in sources :

Example 46 with DocumentEntity

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

the class DefaultDocumentEntityConverterTest method shouldConvertColumnEntityToExistEntity.

@Test
public void shouldConvertColumnEntityToExistEntity() {
    DocumentEntity entity = DocumentEntity.of("Actor");
    Stream.of(documents).forEach(entity::add);
    Actor actor = Actor.actorBuilder().build();
    Actor result = converter.toEntity(actor, entity);
    assertSame(actor, result);
    assertEquals(10, actor.getAge());
    assertEquals(12L, actor.getId());
    assertEquals(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)

Example 47 with DocumentEntity

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

the class DefaultDocumentEntityConverterTest method shouldConvertDocumentEntityFromEntity.

@Test
public void shouldConvertDocumentEntityFromEntity() {
    Person person = Person.builder().withAge().withId(12).withName("Otavio").withPhones(Arrays.asList("234", "2342")).build();
    DocumentEntity entity = converter.toDocument(person);
    assertEquals("Person", entity.getName());
    assertEquals(4, entity.size());
    assertThat(entity.getDocuments(), containsInAnyOrder(Document.of("_id", 12L), Document.of("age", 10), Document.of("name", "Otavio"), Document.of("phones", Arrays.asList("234", "2342"))));
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 48 with DocumentEntity

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

the class DefaultDocumentEntityConverterTest method shouldConvertSubEntity.

@Test
public void shouldConvertSubEntity() {
    ZipCode zipcode = new ZipCode();
    zipcode.setZip("12321");
    zipcode.setPlusFour("1234");
    Address address = new Address();
    address.setCity("Salvador");
    address.setState("Bahia");
    address.setStreet("Rua Engenheiro Jose Anasoh");
    address.setZipCode(zipcode);
    DocumentEntity documentEntity = converter.toDocument(address);
    List<Document> documents = documentEntity.getDocuments();
    assertEquals("Address", documentEntity.getName());
    assertEquals(4, documents.size());
    List<Document> zip = documentEntity.find("zipCode").map(d -> d.get(new TypeReference<List<Document>>() {
    })).orElse(Collections.emptyList());
    assertEquals("Rua Engenheiro Jose Anasoh", getValue(documentEntity.find("street")));
    assertEquals("Salvador", getValue(documentEntity.find("city")));
    assertEquals("Bahia", getValue(documentEntity.find("state")));
    assertEquals("12321", getValue(zip.stream().filter(d -> d.getName().equals("zip")).findFirst()));
    assertEquals("1234", getValue(zip.stream().filter(d -> d.getName().equals("plusFour")).findFirst()));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) AppointmentBook(jakarta.nosql.tck.entities.AppointmentBook) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Person(jakarta.nosql.tck.entities.Person) HashMap(java.util.HashMap) ContactType(jakarta.nosql.tck.entities.ContactType) ZipCode(jakarta.nosql.tck.entities.ZipCode) ArrayList(java.util.ArrayList) Address(jakarta.nosql.tck.entities.Address) Inject(javax.inject.Inject) Actor(jakarta.nosql.tck.entities.Actor) BigDecimal(java.math.BigDecimal) Vendor(jakarta.nosql.tck.entities.Vendor) TypeReference(jakarta.nosql.TypeReference) CDIExtension(jakarta.nosql.tck.test.CDIExtension) Citizen(org.eclipse.jnosql.mapping.document.entities.Citizen) Collections.singleton(java.util.Collections.singleton) Money(jakarta.nosql.tck.entities.Money) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Download(jakarta.nosql.tck.entities.Download) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Worker(jakarta.nosql.tck.entities.Worker) Director(jakarta.nosql.tck.entities.Director) Movie(jakarta.nosql.tck.entities.Movie) Contact(jakarta.nosql.tck.entities.Contact) Collection(java.util.Collection) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) DisplayName(org.junit.jupiter.api.DisplayName) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) Value(jakarta.nosql.Value) List(java.util.List) Stream(java.util.stream.Stream) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assertions(org.junit.jupiter.api.Assertions) Job(jakarta.nosql.tck.entities.Job) Optional(java.util.Optional) Collections(java.util.Collections) DocumentEntity(jakarta.nosql.document.DocumentEntity) Address(jakarta.nosql.tck.entities.Address) ZipCode(jakarta.nosql.tck.entities.ZipCode) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 49 with DocumentEntity

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

the class DefaultDocumentEntityConverterTest method shouldConvertEmbeddableLazily.

@Test
public void shouldConvertEmbeddableLazily() {
    DocumentEntity entity = DocumentEntity.of("Worker");
    entity.add("name", "Otavio");
    entity.add("money", "BRL 10");
    Worker worker = converter.toEntity(entity);
    assertEquals("Otavio", worker.getName());
    assertEquals(new Money("BRL", BigDecimal.TEN), worker.getSalary());
    assertNull(worker.getJob());
}
Also used : Money(jakarta.nosql.tck.entities.Money) DocumentEntity(jakarta.nosql.document.DocumentEntity) Worker(jakarta.nosql.tck.entities.Worker) Test(org.junit.jupiter.api.Test)

Example 50 with DocumentEntity

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

the class DefaultDocumentEntityConverterTest method shouldConvertEntityFromDocumentEntity.

@Test
public void shouldConvertEntityFromDocumentEntity() {
    DocumentEntity entity = converter.toDocument(actor);
    assertEquals("Actor", entity.getName());
    assertEquals(6, entity.size());
    assertThat(entity.getDocuments(), containsInAnyOrder(documents));
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) 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