From 361e7f02a5693afaf6f98357224adb71220195c0 Mon Sep 17 00:00:00 2001
From: Otavio Santana <otaviopolianasantana@gmail.com>
Date: Tue, 24 Dec 2024 11:07:12 +0000
Subject: [PATCH] feat: update query mapper delete fr inheritance

Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
---
 ...ryMapperDeleteTemplateInheritanceTest.java | 154 ++++++++++++++++++
 1 file changed, 154 insertions(+)
 create mode 100644 tck/src/main/java/jakarta/nosql/tck/QueryMapperDeleteTemplateInheritanceTest.java

diff --git a/tck/src/main/java/jakarta/nosql/tck/QueryMapperDeleteTemplateInheritanceTest.java b/tck/src/main/java/jakarta/nosql/tck/QueryMapperDeleteTemplateInheritanceTest.java
new file mode 100644
index 000000000..86a7dc196
--- /dev/null
+++ b/tck/src/main/java/jakarta/nosql/tck/QueryMapperDeleteTemplateInheritanceTest.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2024 Contributors to the Eclipse Foundation
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the Eclipse
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
+ * with the GNU Classpath Exception which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+package jakarta.nosql.tck;
+
+import jakarta.nosql.tck.entities.Animal;
+import jakarta.nosql.tck.factories.AnimalListSupplier;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import java.util.List;
+
+public class QueryMapperDeleteTemplateInheritanceTest extends AbstractTemplateTest {
+
+    @BeforeEach
+    void cleanDatabase() {
+        template.delete(Animal.class).execute();
+    }
+
+    @ParameterizedTest
+    @ArgumentsSource(AnimalListSupplier.class)
+    @DisplayName("Should insert Iterable and delete with no conditions")
+    void shouldInsertIterableAndDeleteNoCondition(List<Animal> entities) {
+        entities.forEach(entity -> template.insert(entity));
+
+        try {
+            template.delete(Animal.class).execute();
+
+            List<Animal> result = template.select(Animal.class).result();
+            Assertions.assertThat(result).isEmpty();
+
+        } catch (UnsupportedOperationException exp) {
+            Assertions.assertThat(exp).isInstanceOf(UnsupportedOperationException.class);
+        }
+    }
+
+    @ParameterizedTest
+    @ArgumentsSource(AnimalListSupplier.class)
+    @DisplayName("Should insert Iterable and delete with simple condition")
+    void shouldInsertIterableAndDeleteWithSimpleCondition(List<Animal> entities) {
+        entities.forEach(entity -> template.insert(entity));
+
+        try {
+            template.delete(Animal.class)
+                    .where("name")
+                    .eq(entities.get(0).getName())
+                    .execute();
+
+            List<Animal> result = template.select(Animal.class)
+                    .where("name")
+                    .eq(entities.get(0).getName())
+                    .result();
+            Assertions.assertThat(result).isEmpty();
+
+        } catch (UnsupportedOperationException exp) {
+            Assertions.assertThat(exp).isInstanceOf(UnsupportedOperationException.class);
+        }
+    }
+
+    @ParameterizedTest
+    @ArgumentsSource(AnimalListSupplier.class)
+    @DisplayName("Should insert Iterable and delete with 'in' condition")
+    void shouldInsertIterableAndDeleteWithInCondition(List<Animal> entities) {
+        // Insert the entities
+        entities.forEach(entity -> template.insert(entity));
+
+        try {
+            // Delete based on the 'name' field (in a list of values)
+            template.delete(Animal.class)
+                    .where("name")
+                    .in(List.of(entities.get(0).getName()))
+                    .execute();
+
+            // Verify that no animals with the given names exist
+            List<Animal> result = template.select(Animal.class)
+                    .where("name")
+                    .in(List.of(entities.get(0).getName()))
+                    .result();
+            Assertions.assertThat(result).isEmpty();
+
+        } catch (UnsupportedOperationException exp) {
+            // Expected for key-value or unsupported NoSQL databases
+            Assertions.assertThat(exp).isInstanceOf(UnsupportedOperationException.class);
+        }
+    }
+
+    @ParameterizedTest
+    @ArgumentsSource(AnimalListSupplier.class)
+    @DisplayName("Should insert Iterable and delete with 'between' condition")
+    void shouldInsertIterableAndDeleteWithBetweenCondition(List<Animal> entities) {
+        entities.forEach(entity -> template.insert(entity));
+
+        try {
+            template.delete(Animal.class)
+                    .where("species")
+                    .between(entities.get(0).getSpecies(), "Zebra") // Example condition
+                    .execute();
+
+            List<Animal> result = template.select(Animal.class)
+                    .where("species")
+                    .between(entities.get(0).getSpecies(), "Zebra") // Example condition
+                    .result();
+            Assertions.assertThat(result).isEmpty();
+
+        } catch (UnsupportedOperationException exp) {
+            // Expected for key-value or unsupported NoSQL databases
+            Assertions.assertThat(exp).isInstanceOf(UnsupportedOperationException.class);
+        }
+    }
+
+    @ParameterizedTest
+    @ArgumentsSource(AnimalListSupplier.class)
+    @DisplayName("Should insert Iterable and delete with 'complex' query")
+    void shouldInsertIterableAndDeleteWithComplexQuery(List<Animal> entities) {
+        // Insert the entities
+        entities.forEach(entity -> template.insert(entity));
+
+        try {
+            template.delete(Animal.class)
+                    .where("genus")
+                    .eq(entities.get(0).getGenus())
+                    .and("species")
+                    .eq(entities.get(0).getSpecies())
+                    .execute();
+
+            List<Animal> result = template.select(Animal.class)
+                    .where("genus")
+                    .eq(entities.get(0).getGenus())
+                    .and("species")
+                    .eq(entities.get(0).getSpecies())
+                    .result();
+            Assertions.assertThat(result).isEmpty();
+
+        } catch (UnsupportedOperationException exp) {
+            // Expected for key-value or unsupported NoSQL databases
+            Assertions.assertThat(exp).isInstanceOf(UnsupportedOperationException.class);
+        }
+    }
+}