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