Search in sources :

Example 1 with Director

use of jakarta.nosql.tck.entities.Director in project jnosql-diana by eclipse.

the class DefaultDocumentEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubDocument2.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubDocument2() {
    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");
    entity.add(Document.of("movie", Arrays.asList(Document.of("title", "Matrix"), Document.of("year", 2012), Document.of("actors", singleton("Actor")))));
    Director director1 = converter.toEntity(entity);
    assertEquals(movie, director1.getMovie());
    assertEquals(director.getName(), director1.getName());
    assertEquals(director.getAge(), director1.getAge());
    assertEquals(director.getId(), director1.getId());
}
Also used : Movie(jakarta.nosql.tck.entities.Movie) DocumentEntity(jakarta.nosql.document.DocumentEntity) Director(jakarta.nosql.tck.entities.Director) Test(org.junit.jupiter.api.Test)

Example 2 with Director

use of jakarta.nosql.tck.entities.Director 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()));
}
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) Movie(jakarta.nosql.tck.entities.Movie) DocumentEntity(jakarta.nosql.document.DocumentEntity) Director(jakarta.nosql.tck.entities.Director) 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 3 with Director

use of jakarta.nosql.tck.entities.Director 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());
}
Also used : Movie(jakarta.nosql.tck.entities.Movie) DocumentEntity(jakarta.nosql.document.DocumentEntity) HashMap(java.util.HashMap) Director(jakarta.nosql.tck.entities.Director) Test(org.junit.jupiter.api.Test)

Example 4 with Director

use of jakarta.nosql.tck.entities.Director in project jnosql-diana by eclipse.

the class DefaultColumnEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubColumn2.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubColumn2() {
    Movie movie = new Movie("Matrix", 2012, singleton("Actor"));
    Director director = Director.builderDirector().withAge(12).withId(12).withName("Otavio").withPhones(asList("234", "2342")).withMovie(movie).build();
    ColumnEntity entity = converter.toColumn(director);
    entity.remove("movie");
    entity.add(Column.of("movie", Arrays.asList(Column.of("title", "Matrix"), Column.of("year", 2012), Column.of("actors", singleton("Actor")))));
    Director director1 = converter.toEntity(entity);
    assertEquals(movie, director1.getMovie());
    assertEquals(director.getName(), director1.getName());
    assertEquals(director.getAge(), director1.getAge());
    assertEquals(director.getId(), director1.getId());
}
Also used : Movie(jakarta.nosql.tck.entities.Movie) ColumnEntity(jakarta.nosql.column.ColumnEntity) Director(jakarta.nosql.tck.entities.Director) Test(org.junit.jupiter.api.Test)

Example 5 with Director

use of jakarta.nosql.tck.entities.Director in project jnosql-diana by eclipse.

the class DefaultDocumentEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubDocument.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubDocument() {
    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);
    Director director1 = converter.toEntity(entity);
    assertEquals(movie, director1.getMovie());
    assertEquals(director.getName(), director1.getName());
    assertEquals(director.getAge(), director1.getAge());
    assertEquals(director.getId(), director1.getId());
}
Also used : Movie(jakarta.nosql.tck.entities.Movie) DocumentEntity(jakarta.nosql.document.DocumentEntity) Director(jakarta.nosql.tck.entities.Director) Test(org.junit.jupiter.api.Test)

Aggregations

Director (jakarta.nosql.tck.entities.Director)8 Movie (jakarta.nosql.tck.entities.Movie)8 Test (org.junit.jupiter.api.Test)8 ColumnEntity (jakarta.nosql.column.ColumnEntity)4 DocumentEntity (jakarta.nosql.document.DocumentEntity)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 TypeReference (jakarta.nosql.TypeReference)1 Value (jakarta.nosql.Value)1 Column (jakarta.nosql.column.Column)1 Document (jakarta.nosql.document.Document)1 Actor (jakarta.nosql.tck.entities.Actor)1 Address (jakarta.nosql.tck.entities.Address)1 AppointmentBook (jakarta.nosql.tck.entities.AppointmentBook)1 Contact (jakarta.nosql.tck.entities.Contact)1 ContactType (jakarta.nosql.tck.entities.ContactType)1 Download (jakarta.nosql.tck.entities.Download)1 Job (jakarta.nosql.tck.entities.Job)1