From 2485f2721eaab2939603ef0aed267f74cfd65396 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 29 Mar 2025 09:04:21 +0000 Subject: [PATCH 1/6] test: generate initial structure to the bug scenarion Signed-off-by: Otavio Santana --- .../jnosql/databases/mongodb/integration/Computer.java | 4 ++++ .../eclipse/jnosql/databases/mongodb/integration/Program.java | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Computer.java create mode 100644 jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Program.java diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Computer.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Computer.java new file mode 100644 index 000000000..23254c2d8 --- /dev/null +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Computer.java @@ -0,0 +1,4 @@ +package org.eclipse.jnosql.databases.mongodb.integration; + +public class Computer { +} diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Program.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Program.java new file mode 100644 index 000000000..050309e6a --- /dev/null +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Program.java @@ -0,0 +1,4 @@ +package org.eclipse.jnosql.databases.mongodb.integration; + +public record Program() { +} From 650a213da5dbac3ff156b7604793bdee59a013aa Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 29 Mar 2025 09:08:40 +0000 Subject: [PATCH 2/6] test: enhance program and comoputer using the factory method Signed-off-by: Otavio Santana --- .../mongodb/integration/Computer.java | 69 ++++++++++++++++++ .../mongodb/integration/Program.java | 72 ++++++++++++++++++- .../integration/TemplateIntegrationTest.java | 5 ++ 3 files changed, 144 insertions(+), 2 deletions(-) diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Computer.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Computer.java index 23254c2d8..0ed6c9eb0 100644 --- a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Computer.java +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Computer.java @@ -1,4 +1,73 @@ +/* + * Copyright (c) 2025 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.databases.mongodb.integration; +import jakarta.nosql.Column; +import jakarta.nosql.Entity; +import jakarta.nosql.Id; + +import java.util.Map; +import java.util.Objects; + +@Entity public class Computer { + @Id + private String name; + + @Column + private Map programs; + + private Computer(String name, Map programs) { + this.name = name; + this.programs = programs; + } + + @Deprecated + Computer() { + } + + public String getName() { + return name; + } + + public Map getPrograms() { + return programs; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) return false; + Computer computer = (Computer) o; + return Objects.equals(name, computer.name); + } + + @Override + public int hashCode() { + return Objects.hashCode(name); + } + + @Override + public String toString() { + return "Computer{" + + "name='" + name + '\'' + + ", programs=" + programs + + '}'; + } + + + public static Computer of(String name, Map programs) { + return new Computer(name, programs); + } } diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Program.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Program.java index 050309e6a..92d3e1c88 100644 --- a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Program.java +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Program.java @@ -1,4 +1,72 @@ +/* + * Copyright (c) 2025 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.databases.mongodb.integration; -public record Program() { -} +import jakarta.nosql.Column; +import jakarta.nosql.Embeddable; +import jakarta.nosql.Id; + +import java.util.Map; +import java.util.Objects; + +@Embeddable +public class Program { + @Id + private String name; + + @Column + private Map socialMedia; + + public String getName() { + return name; + } + + public Map getSocialMedia() { + return socialMedia; + } + + private Program(String name, Map socialMedia) { + this.name = name; + this.socialMedia = socialMedia; + } + + + @Deprecated + Program() { + } + + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) { + return false; + } + Program program = (Program) o; + return Objects.equals(name, program.name); + } + + @Override + public int hashCode() { + return Objects.hashCode(name); + } + + @Override + public String toString() { + return "Program{" + + "name='" + name + '\'' + + ", socialMedia=" + socialMedia + + '}'; + } +} \ No newline at end of file diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java index 3f4df7e7f..63e913265 100644 --- a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java @@ -159,4 +159,9 @@ void shouldUpdateEmbeddable() { soft.assertThat(result.availableTransitions().get(0).restrictedRoleGroups().get(0)).isEqualTo("ADMIN"); }); } + + @Test + void shouldInsertEntityWithMap() { + + } } From 5353807c6aed96587c9cb9c27e79fc78dbdcaf62 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 29 Mar 2025 09:14:46 +0000 Subject: [PATCH 3/6] test: generate sample using class Signed-off-by: Otavio Santana --- .../databases/mongodb/integration/Program.java | 4 ++++ .../integration/TemplateIntegrationTest.java | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Program.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Program.java index 92d3e1c88..3b580fd4c 100644 --- a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Program.java +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/Program.java @@ -69,4 +69,8 @@ public String toString() { ", socialMedia=" + socialMedia + '}'; } + + public static Program of(String name, Map socialMedia) { + return new Program(name, socialMedia); + } } \ No newline at end of file diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java index 63e913265..712c451c0 100644 --- a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java @@ -34,6 +34,7 @@ import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import java.util.List; +import java.util.Map; import java.util.Optional; import static java.util.UUID.randomUUID; @@ -162,6 +163,22 @@ void shouldUpdateEmbeddable() { @Test void shouldInsertEntityWithMap() { + var program = Program.of( + "Renamer", + Map.of("twitter", "x") + ); + var computer = Computer.of("Computer",Map.of("Renamer", program)); + var result = this.template.insert(computer); + + SoftAssertions.assertSoftly(soft ->{ + soft.assertThat(result).isNotNull(); + soft.assertThat(result.getName()).isEqualTo("Computer"); + soft.assertThat(result.getPrograms()).hasSize(1); + soft.assertThat(result.getPrograms().get("Renamer")).isNotNull(); + soft.assertThat(result.getPrograms().get("Renamer").getName()).isEqualTo("Renamer"); + soft.assertThat(result.getPrograms().get("Renamer").getSocialMedia()).hasSize(1); + soft.assertThat(result.getPrograms().get("Renamer").getSocialMedia().get("twitter")).isEqualTo("x"); + }); } } From c9e7133323bea0634ca93570dd175e46267492fc Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sat, 29 Mar 2025 09:19:15 +0000 Subject: [PATCH 4/6] test: update template integration with record sample as well Signed-off-by: Otavio Santana --- .../mongodb/integration/ComputerRecord.java | 26 +++++++++++++++++++ .../mongodb/integration/ProgramRecord.java | 26 +++++++++++++++++++ .../integration/TemplateIntegrationTest.java | 21 +++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/ComputerRecord.java create mode 100644 jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/ProgramRecord.java diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/ComputerRecord.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/ComputerRecord.java new file mode 100644 index 000000000..939329690 --- /dev/null +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/ComputerRecord.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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.databases.mongodb.integration; + +import jakarta.nosql.Column; +import jakarta.nosql.Entity; +import jakarta.nosql.Id; + +import java.util.Map; + +@Entity +public record ComputerRecord (@Id String name, @Column Map programs){ + +} diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/ProgramRecord.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/ProgramRecord.java new file mode 100644 index 000000000..cd1b1d215 --- /dev/null +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/ProgramRecord.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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.databases.mongodb.integration; + +import jakarta.nosql.Column; +import jakarta.nosql.Embeddable; +import jakarta.nosql.Id; + +import java.util.Map; + +@Embeddable +public record ProgramRecord(@Id String name, @Column Map socialMedia) { + +} \ No newline at end of file diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java index 712c451c0..700d412d2 100644 --- a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java @@ -181,4 +181,25 @@ void shouldInsertEntityWithMap() { soft.assertThat(result.getPrograms().get("Renamer").getSocialMedia().get("twitter")).isEqualTo("x"); }); } + + @Test + void shouldInsertEntityWithMapUsingRecord() { + var program = new ProgramRecord( + "Renamer", + Map.of("twitter", "x") + ); + var computer = new ComputerRecord("Computer",Map.of("Renamer", program)); + + var result = this.template.insert(computer); + + SoftAssertions.assertSoftly(soft ->{ + soft.assertThat(result).isNotNull(); + soft.assertThat(result.name()).isEqualTo("Computer"); + soft.assertThat(result.programs()).hasSize(1); + soft.assertThat(result.programs().get("Renamer")).isNotNull(); + soft.assertThat(result.programs().get("Renamer").name()).isEqualTo("Renamer"); + soft.assertThat(result.programs().get("Renamer").socialMedia()).hasSize(1); + soft.assertThat(result.programs().get("Renamer").socialMedia().get("twitter")).isEqualTo("x"); + }); + } } From 86efe37ff49ad44461d8d82ac37bd7d1bc8d6a63 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sun, 30 Mar 2025 04:25:58 +0100 Subject: [PATCH 5/6] generate Signed-off-by: Otavio Santana --- .../integration/TemplateIntegrationTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java index 700d412d2..53d7df824 100644 --- a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java @@ -182,6 +182,33 @@ void shouldInsertEntityWithMap() { }); } + @Test + void shouldInsertEntityWithTwoMap() { + var program = Program.of( + "Renamer", + Map.of("twitter", "x") + ); + + var program2 = Program.of( + "Apple", + Map.of("instagram", "x") + ); + var computer = Computer.of("Computer",Map.of("Renamer", program, + "Apple", program2)); + + var result = this.template.insert(computer); + + SoftAssertions.assertSoftly(soft ->{ + soft.assertThat(result).isNotNull(); + soft.assertThat(result.getName()).isEqualTo("Computer"); + soft.assertThat(result.getPrograms()).hasSize(1); + soft.assertThat(result.getPrograms().get("Renamer")).isNotNull(); + soft.assertThat(result.getPrograms().get("Renamer").getName()).isEqualTo("Renamer"); + soft.assertThat(result.getPrograms().get("Renamer").getSocialMedia()).hasSize(1); + soft.assertThat(result.getPrograms().get("Renamer").getSocialMedia().get("twitter")).isEqualTo("x"); + }); + } + @Test void shouldInsertEntityWithMapUsingRecord() { var program = new ProgramRecord( From 2797417abdd6ff47206128aefa56491dac202aa2 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Sun, 30 Mar 2025 19:26:27 +0100 Subject: [PATCH 6/6] test: update template integration test Signed-off-by: Otavio Santana --- .../mongodb/integration/TemplateIntegrationTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java index 53d7df824..cbe4026f8 100644 --- a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java @@ -167,13 +167,14 @@ void shouldInsertEntityWithMap() { "Renamer", Map.of("twitter", "x") ); - var computer = Computer.of("Computer",Map.of("Renamer", program)); + var id = "Computer" + randomUUID(); + var computer = Computer.of(id,Map.of("Renamer", program)); var result = this.template.insert(computer); SoftAssertions.assertSoftly(soft ->{ soft.assertThat(result).isNotNull(); - soft.assertThat(result.getName()).isEqualTo("Computer"); + soft.assertThat(result.getName()).isEqualTo(id); soft.assertThat(result.getPrograms()).hasSize(1); soft.assertThat(result.getPrograms().get("Renamer")).isNotNull(); soft.assertThat(result.getPrograms().get("Renamer").getName()).isEqualTo("Renamer"); @@ -193,15 +194,16 @@ void shouldInsertEntityWithTwoMap() { "Apple", Map.of("instagram", "x") ); - var computer = Computer.of("Computer",Map.of("Renamer", program, + var id = "Computer" + randomUUID(); + var computer = Computer.of(id,Map.of("Renamer", program, "Apple", program2)); var result = this.template.insert(computer); SoftAssertions.assertSoftly(soft ->{ soft.assertThat(result).isNotNull(); - soft.assertThat(result.getName()).isEqualTo("Computer"); - soft.assertThat(result.getPrograms()).hasSize(1); + soft.assertThat(result.getName()).isEqualTo(id); + soft.assertThat(result.getPrograms()).hasSize(2); soft.assertThat(result.getPrograms().get("Renamer")).isNotNull(); soft.assertThat(result.getPrograms().get("Renamer").getName()).isEqualTo("Renamer"); soft.assertThat(result.getPrograms().get("Renamer").getSocialMedia()).hasSize(1);