use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class DefaultDocumentEntityConverterTest method shouldConvertEntityFromDocumentEntity2.
@Test
public void shouldConvertEntityFromDocumentEntity2() {
Movie movie = new Movie("Matrix", 2012, singleton("Actor"));
Director director = Director.builderDirector().withAge(12).withId(12).withName("Otavio").withPhones(Arrays.asList("234", "2342")).withMovie(movie).build();
DocumentEntity entity = converter.toDocument(director);
assertEquals(5, entity.size());
assertEquals(getValue(entity.find("name")), director.getName());
assertEquals(getValue(entity.find("age")), director.getAge());
assertEquals(getValue(entity.find("_id")), director.getId());
assertEquals(getValue(entity.find("phones")), director.getPhones());
Document subdocument = entity.find("movie").get();
List<Document> documents = subdocument.get(new TypeReference<List<Document>>() {
});
assertEquals(3, documents.size());
assertEquals("movie", subdocument.getName());
assertEquals(movie.getTitle(), getValue(documents.stream().filter(d -> "title".equals(d.getName())).findFirst()));
assertEquals(movie.getYear(), getValue(documents.stream().filter(d -> "year".equals(d.getName())).findFirst()));
assertEquals(movie.getActors(), getValue(documents.stream().filter(d -> "actors".equals(d.getName())).findFirst()));
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class DefaultDocumentEntityConverterTest method shouldConvertToListEmbeddable.
@Test
public void shouldConvertToListEmbeddable() {
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("contact_name")).count());
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class DefaultDocumentEntityConverterTest method shouldCreateUserScope.
@Test
public void shouldCreateUserScope() {
DocumentEntity entity = DocumentEntity.of("UserScope");
entity.add("_id", "userName");
entity.add("scope", "scope");
entity.add("properties", Collections.singletonList(Document.of("halo", "weld")));
UserScope user = converter.toEntity(entity);
Assertions.assertNotNull(user);
Assertions.assertEquals("userName", user.getUserName());
Assertions.assertEquals("scope", user.getScope());
Assertions.assertEquals(Collections.singletonMap("halo", "weld"), user.getProperties());
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class DefaultDocumentEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubDocument3.
@Test
public void shouldConvertToEmbeddedClassWhenHasSubDocument3() {
Movie movie = new Movie("Matrix", 2012, singleton("Actor"));
Director director = Director.builderDirector().withAge(12).withId(12).withName("Otavio").withPhones(Arrays.asList("234", "2342")).withMovie(movie).build();
DocumentEntity entity = converter.toDocument(director);
entity.remove("movie");
Map<String, Object> map = new HashMap<>();
map.put("title", "Matrix");
map.put("year", 2012);
map.put("actors", singleton("Actor"));
entity.add(Document.of("movie", map));
Director director1 = converter.toEntity(entity);
assertEquals(movie, director1.getMovie());
assertEquals(director.getName(), director1.getName());
assertEquals(director.getAge(), director1.getAge());
assertEquals(director.getId(), director1.getId());
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class DefaultDocumentEntityConverterTest method shouldConvertDocumentEntityFromEntity3.
@Test
public void shouldConvertDocumentEntityFromEntity3() {
DocumentEntity entity = DocumentEntity.of("Actor");
Stream.of(documents).forEach(entity::add);
Actor actor = converter.toEntity(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