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