From e2b0a43998f197eb2a68af02b50ce0df7efbe8df Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 15 Oct 2024 04:27:55 +0100 Subject: [PATCH 01/11] test: create guest and room scenarios Signed-off-by: Otavio Santana --- .../semistructured/entities/Guest.java | 8 +++++++ .../mapping/semistructured/entities/Room.java | 9 ++++++++ .../entities/constructor/Guest.java | 22 ++++++++++++++++++ .../entities/constructor/Room.java | 23 +++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Guest.java create mode 100644 jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Room.java create mode 100644 jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/constructor/Guest.java create mode 100644 jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/constructor/Room.java diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Guest.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Guest.java new file mode 100644 index 000000000..ed41222f1 --- /dev/null +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Guest.java @@ -0,0 +1,8 @@ +package org.eclipse.jnosql.mapping.semistructured.entities; + +import jakarta.nosql.Column; +import jakarta.nosql.Embeddable; + +@Embeddable +public record Guest (@Column String documentNumber, @Column String name) { +} diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Room.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Room.java new file mode 100644 index 000000000..ddf52c6b8 --- /dev/null +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Room.java @@ -0,0 +1,9 @@ +package org.eclipse.jnosql.mapping.semistructured.entities; + +import jakarta.nosql.Column; +import jakarta.nosql.Entity; +import jakarta.nosql.Id; + +@Entity +public record Room (@Id int number, @Column Guest guest) { +} diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/constructor/Guest.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/constructor/Guest.java new file mode 100644 index 000000000..3063def00 --- /dev/null +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/constructor/Guest.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Apache License v2.0 which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. + * + * You may elect to redistribute this code under either of these licenses. + * + * Contributors: + * + * Otavio Santana + */ +package org.eclipse.jnosql.mapping.semistructured.entities.constructor; + +import jakarta.nosql.Column; +import jakarta.nosql.Embeddable; + +@Embeddable +public record Guest (@Column String documentNumber, @Column String name) { +} diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/constructor/Room.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/constructor/Room.java new file mode 100644 index 000000000..a0dd32d75 --- /dev/null +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/constructor/Room.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Apache License v2.0 which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. + * + * You may elect to redistribute this code under either of these licenses. + * + * Contributors: + * + * Otavio Santana + */ +package org.eclipse.jnosql.mapping.semistructured.entities.constructor; + +import jakarta.nosql.Column; +import jakarta.nosql.Entity; +import jakarta.nosql.Id; + +@Entity +public record Room (@Id int number, @Column Guest guest) { +} From 78d7f68ee92489f9694eb113b873be86ae5e3b94 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 15 Oct 2024 04:32:00 +0100 Subject: [PATCH 02/11] test: create constructor builder Signed-off-by: Otavio Santana --- .../EntityConverterConstructorTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterConstructorTest.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterConstructorTest.java index 965e12c6c..398d578c3 100644 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterConstructorTest.java +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterConstructorTest.java @@ -31,7 +31,9 @@ import org.eclipse.jnosql.mapping.semistructured.entities.constructor.BookBag; import org.eclipse.jnosql.mapping.semistructured.entities.constructor.BookUser; import org.eclipse.jnosql.mapping.semistructured.entities.constructor.Computer; +import org.eclipse.jnosql.mapping.semistructured.entities.constructor.Guest; import org.eclipse.jnosql.mapping.semistructured.entities.constructor.PetOwner; +import org.eclipse.jnosql.mapping.semistructured.entities.constructor.Room; import org.eclipse.jnosql.mapping.semistructured.entities.constructor.SocialMediaFollowers; import org.eclipse.jnosql.mapping.semistructured.entities.constructor.SocialMediaFollowersRecord; import org.eclipse.jnosql.mapping.semistructured.entities.constructor.SuperHero; @@ -361,4 +363,22 @@ void shouldConvertArrayTypes() { } + @Test + void shouldConvertFromFlat() { + + CommunicationEntity communication = CommunicationEntity.of(Room.class.getSimpleName()); + communication.add("_id", "12"); + communication.add("documentNumber", "123"); + communication.add("name", "Ada"); + Room entity = converter.toEntity(communication); + + SoftAssertions.assertSoftly(softly->{ + softly.assertThat(entity).isNotNull(); + softly.assertThat(entity.guest()).isNotNull(); + softly.assertThat(entity.guest().documentNumber()).isEqualTo("123"); + softly.assertThat(entity.guest().name()).isEqualTo("Ada"); + softly.assertThat(entity.number()).isEqualTo("12"); + }); + } + } From eb28840dd29d7a3f8b3cb1c237eb67d63c8908d2 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 15 Oct 2024 04:55:42 +0100 Subject: [PATCH 03/11] feat: include a converter case when it is flat Signed-off-by: Otavio Santana --- .../mapping/semistructured/EntityConverter.java | 12 +++++++++--- .../mapping/semistructured/entities/Guest.java | 8 -------- .../jnosql/mapping/semistructured/entities/Room.java | 9 --------- 3 files changed, 9 insertions(+), 20 deletions(-) delete mode 100644 jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Guest.java delete mode 100644 jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Room.java diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/main/java/org/eclipse/jnosql/mapping/semistructured/EntityConverter.java b/jnosql-mapping/jnosql-mapping-semistructured/src/main/java/org/eclipse/jnosql/mapping/semistructured/EntityConverter.java index 4e7c9d57d..8943dfac2 100644 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/main/java/org/eclipse/jnosql/mapping/semistructured/EntityConverter.java +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/main/java/org/eclipse/jnosql/mapping/semistructured/EntityConverter.java @@ -179,12 +179,18 @@ protected T toEntity(Class type, List elements) { private T convertEntityByConstructor(List elements, EntityMetadata mapping) { ConstructorBuilder builder = ConstructorBuilder.of(mapping.constructor()); for (ParameterMetaData parameter : builder.parameters()) { + Predicate matchName = c -> c.name().equals(parameter.name()); + boolean isFlatEmbedded = EMBEDDED.equals(parameter.mappingType()); Optional element = elements.stream() - .filter(c -> c.name().equals(parameter.name())) + .filter(matchName.or(e -> isFlatEmbedded)) .findFirst(); element.ifPresentOrElse(c -> { - ParameterConverter converter = ParameterConverter.of(parameter, entities()); - converter.convert(this, c, parameter, builder); + var converter = ParameterConverter.of(parameter, entities()); + if (isFlatEmbedded) { + converter.convert(this, Element.of("_", elements), parameter, builder); + } else { + converter.convert(this, c, parameter, builder); + } }, builder::addEmptyParameter); } return builder.build(); diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Guest.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Guest.java deleted file mode 100644 index ed41222f1..000000000 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Guest.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.eclipse.jnosql.mapping.semistructured.entities; - -import jakarta.nosql.Column; -import jakarta.nosql.Embeddable; - -@Embeddable -public record Guest (@Column String documentNumber, @Column String name) { -} diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Room.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Room.java deleted file mode 100644 index ddf52c6b8..000000000 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/entities/Room.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eclipse.jnosql.mapping.semistructured.entities; - -import jakarta.nosql.Column; -import jakarta.nosql.Entity; -import jakarta.nosql.Id; - -@Entity -public record Room (@Id int number, @Column Guest guest) { -} From 868df1336dbb09a0a15fde496b17882fdd1b3d78 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 15 Oct 2024 04:56:12 +0100 Subject: [PATCH 04/11] feat: add embbed flat in the case Signed-off-by: Otavio Santana --- .../jnosql/mapping/semistructured/ParameterConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/main/java/org/eclipse/jnosql/mapping/semistructured/ParameterConverter.java b/jnosql-mapping/jnosql-mapping-semistructured/src/main/java/org/eclipse/jnosql/mapping/semistructured/ParameterConverter.java index c88d9b2ca..03e26c2c0 100644 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/main/java/org/eclipse/jnosql/mapping/semistructured/ParameterConverter.java +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/main/java/org/eclipse/jnosql/mapping/semistructured/ParameterConverter.java @@ -116,7 +116,7 @@ static ParameterConverter of(ParameterMetaData parameter, EntitiesMetadata entit case COLLECTION -> collectionConverter(parameter, entities); case ARRAY -> arrayConverter(parameter, entities); case MAP -> MAP; - case ENTITY, EMBEDDED_GROUP -> ENTITY; + case ENTITY, EMBEDDED_GROUP, EMBEDDED -> ENTITY; default -> DEFAULT; }; } From 27b0edb172c7e79b60f3f88b2a0d19b259be0cb3 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 15 Oct 2024 04:56:25 +0100 Subject: [PATCH 05/11] test: create test scenario to flat Signed-off-by: Otavio Santana --- .../semistructured/EntityConverterConstructorTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterConstructorTest.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterConstructorTest.java index 398d578c3..505e642d2 100644 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterConstructorTest.java +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterConstructorTest.java @@ -367,7 +367,7 @@ void shouldConvertArrayTypes() { void shouldConvertFromFlat() { CommunicationEntity communication = CommunicationEntity.of(Room.class.getSimpleName()); - communication.add("_id", "12"); + communication.add("_id", 12); communication.add("documentNumber", "123"); communication.add("name", "Ada"); Room entity = converter.toEntity(communication); @@ -377,7 +377,7 @@ void shouldConvertFromFlat() { softly.assertThat(entity.guest()).isNotNull(); softly.assertThat(entity.guest().documentNumber()).isEqualTo("123"); softly.assertThat(entity.guest().name()).isEqualTo("Ada"); - softly.assertThat(entity.number()).isEqualTo("12"); + softly.assertThat(entity.number()).isEqualTo(12); }); } From 40b7a8104ed1e2e0fc80d9b6a924acbc524d1efc Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 15 Oct 2024 05:00:44 +0100 Subject: [PATCH 06/11] test: create sample with flat embeeded Signed-off-by: Otavio Santana --- .../jnosql/mapping/semistructured/Course.java | 47 +++++++++++++++++++ .../mapping/semistructured/Student.java | 46 ++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Course.java create mode 100644 jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Student.java diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Course.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Course.java new file mode 100644 index 000000000..54eb54755 --- /dev/null +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Course.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Apache License v2.0 which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. + * + * You may elect to redistribute this code under either of these licenses. + * + * Contributors: + * + * Otavio Santana + */ +package org.eclipse.jnosql.mapping.semistructured; + +import jakarta.nosql.Column; +import jakarta.nosql.Entity; +import jakarta.nosql.Id; + +@Entity +public class Course { + + @Id + private String id; + + @Column + private Student student; + + public String getId() { + return id; + } + + public Course setId(String id) { + this.id = id; + return this; + } + + public Student getStudent() { + return student; + } + + public Course setStudent(Student student) { + this.student = student; + return this; + } +} diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Student.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Student.java new file mode 100644 index 000000000..64271e55a --- /dev/null +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Student.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Apache License v2.0 which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. + * + * You may elect to redistribute this code under either of these licenses. + * + * Contributors: + * + * Otavio Santana + */ +package org.eclipse.jnosql.mapping.semistructured; + +import jakarta.nosql.Column; +import jakarta.nosql.Embeddable; + +@Embeddable +public class Student { + + @Column + private String studentId; + + @Column + private String fullName; + + public String getStudentId() { + return studentId; + } + + public Student setStudentId(String studentId) { + this.studentId = studentId; + return this; + } + + public String getFullName() { + return fullName; + } + + public Student setFullName(String fullName) { + this.fullName = fullName; + return this; + } +} From 9155852f491eb950a1bdbdfbeab2c0e2732e0dd0 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 15 Oct 2024 05:02:05 +0100 Subject: [PATCH 07/11] test: create constructor scenario Signed-off-by: Otavio Santana --- .../EntityConverterConstructorTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterConstructorTest.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterConstructorTest.java index 505e642d2..4400b6057 100644 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterConstructorTest.java +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterConstructorTest.java @@ -364,7 +364,7 @@ void shouldConvertArrayTypes() { } @Test - void shouldConvertFromFlat() { + void shouldConvertFromFlatCommunicationFromEntity() { CommunicationEntity communication = CommunicationEntity.of(Room.class.getSimpleName()); communication.add("_id", 12); @@ -381,4 +381,17 @@ void shouldConvertFromFlat() { }); } + @Test + void shouldConvertFromFlatCommunicationFromEntityToCommunication() { + var room = new Room(12, new Guest("123", "Ada")); + CommunicationEntity communication = converter.toCommunication(room); + + SoftAssertions.assertSoftly(softly->{ + softly.assertThat(communication).isNotNull(); + softly.assertThat(communication.find("_id").orElseThrow().get()).isEqualTo(12); + softly.assertThat(communication.find("documentNumber").orElseThrow().get()).isEqualTo("123"); + softly.assertThat(communication.find("name").orElseThrow().get()).isEqualTo("Ada"); + }); + } + } From 1ffcaf0f5e78a4b7444e8e3b887c40fedfd0ed51 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 15 Oct 2024 05:06:43 +0100 Subject: [PATCH 08/11] test: create constructor at course Signed-off-by: Otavio Santana --- .../org/eclipse/jnosql/mapping/semistructured/Course.java | 8 ++++++++ .../eclipse/jnosql/mapping/semistructured/Student.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Course.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Course.java index 54eb54755..a567adad2 100644 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Course.java +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Course.java @@ -27,6 +27,14 @@ public class Course { @Column private Student student; + public Course(String id, Student student) { + this.id = id; + this.student = student; + } + + public Course() { + } + public String getId() { return id; } diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Student.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Student.java index 64271e55a..b2e2c1eaf 100644 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Student.java +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/Student.java @@ -26,6 +26,14 @@ public class Student { @Column private String fullName; + public Student(String studentId, String fullName) { + this.studentId = studentId; + this.fullName = fullName; + } + + public Student() { + } + public String getStudentId() { return studentId; } From f1baba9087c54b8c0f51a95c3dfa60fa4e7acfce Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 15 Oct 2024 05:07:13 +0100 Subject: [PATCH 09/11] test: create scenario to not constructor Signed-off-by: Otavio Santana --- .../semistructured/EntityConverterTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterTest.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterTest.java index 5ccb25523..4987a0f25 100644 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterTest.java +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterTest.java @@ -50,6 +50,8 @@ import org.eclipse.jnosql.mapping.semistructured.entities.WorkflowStep; import org.eclipse.jnosql.mapping.semistructured.entities.ZipCode; import org.eclipse.jnosql.mapping.semistructured.entities.constructor.BookBag; +import org.eclipse.jnosql.mapping.semistructured.entities.constructor.Guest; +import org.eclipse.jnosql.mapping.semistructured.entities.constructor.Room; import org.jboss.weld.junit5.auto.AddExtensions; import org.jboss.weld.junit5.auto.AddPackages; import org.jboss.weld.junit5.auto.EnableAutoWeld; @@ -936,6 +938,37 @@ void shouldConvertEntityFromRecordEntityWithColumnArray() { } + @Test + void shouldConvertFromFlatCommunicationFromEntity() { + + CommunicationEntity communication = CommunicationEntity.of(Course.class.getSimpleName()); + communication.add("_id", 12); + communication.add("studentId", "123"); + communication.add("fullName", "Ada"); + Course entity = converter.toEntity(communication); + + SoftAssertions.assertSoftly(softly->{ + softly.assertThat(entity).isNotNull(); + softly.assertThat(entity.getStudent()).isNotNull(); + softly.assertThat(entity.getStudent().getStudentId()).isEqualTo("123"); + softly.assertThat(entity.getStudent().getFullName()).isEqualTo("Ada"); + softly.assertThat(entity.getId()).isEqualTo(12); + }); + } + + @Test + void shouldConvertFromFlatCommunicationFromEntityToCommunication() { + var course = new Course("12", new Student("123", "Ada")); + CommunicationEntity communication = converter.toCommunication(course); + + SoftAssertions.assertSoftly(softly->{ + softly.assertThat(communication).isNotNull(); + softly.assertThat(communication.find("_id").orElseThrow().get()).isEqualTo("12"); + softly.assertThat(communication.find("studentId").orElseThrow().get()).isEqualTo("123"); + softly.assertThat(communication.find("fullName").orElseThrow().get()).isEqualTo("Ada"); + }); + } + private Object getValue(Optional column) { return column.map(Element::value).map(Value::get).orElse(null); From 768be9ba0b632153451e33d10186846b058349b0 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 15 Oct 2024 05:09:10 +0100 Subject: [PATCH 10/11] test: update scenario to jnosql Signed-off-by: Otavio Santana --- .../jnosql/mapping/semistructured/EntityConverterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterTest.java b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterTest.java index 4987a0f25..052a5dbdd 100644 --- a/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterTest.java +++ b/jnosql-mapping/jnosql-mapping-semistructured/src/test/java/org/eclipse/jnosql/mapping/semistructured/EntityConverterTest.java @@ -952,7 +952,7 @@ void shouldConvertFromFlatCommunicationFromEntity() { softly.assertThat(entity.getStudent()).isNotNull(); softly.assertThat(entity.getStudent().getStudentId()).isEqualTo("123"); softly.assertThat(entity.getStudent().getFullName()).isEqualTo("Ada"); - softly.assertThat(entity.getId()).isEqualTo(12); + softly.assertThat(entity.getId()).isEqualTo("12"); }); } From 39a7a0d9d79c090ba3f7482b1a18cfd87790eb2f Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 15 Oct 2024 05:13:17 +0100 Subject: [PATCH 11/11] docs: enhance documentation at changelog Signed-off-by: Otavio Santana --- CHANGELOG.adoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 3cb3e6957..05765bb48 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -8,6 +8,10 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version == [Unreleased] +=== Fixed + +- Fix flat embeddable in the constructor builder + == [1.1.2] - 2023-09-15 === Added