-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update query mapper delete fr inheritance
Signed-off-by: Otavio Santana <[email protected]>
- Loading branch information
1 parent
c01fabd
commit 361e7f0
Showing
1 changed file
with
154 additions
and
0 deletions.
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
tck/src/main/java/jakarta/nosql/tck/QueryMapperDeleteTemplateInheritanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |