-
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.
chore: update and crete querymapper select record
Signed-off-by: Otavio Santana <[email protected]>
- Loading branch information
1 parent
7ce3cea
commit f6057e7
Showing
1 changed file
with
120 additions
and
1 deletion.
There are no files selected for viewing
121 changes: 120 additions & 1 deletion
121
tck/src/main/java/jakarta/nosql/tck/QueryMapperSelectRecordTest.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 |
---|---|---|
@@ -1,4 +1,123 @@ | ||
/* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
package jakarta.nosql.tck; | ||
|
||
public class QueryMapperSelectRecordTest { | ||
import jakarta.nosql.tck.entities.Book; | ||
import jakarta.nosql.tck.factories.BookSupplier; | ||
import org.assertj.core.api.SoftAssertions; | ||
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 QueryMapperSelectRecordTest extends AbstractTemplateTest { | ||
|
||
|
||
@BeforeEach | ||
void cleanDatabase() { | ||
template.delete(Book.class).execute(); | ||
} | ||
|
||
@ParameterizedTest | ||
@ArgumentsSource(BookSupplier.class) | ||
@DisplayName("Should insert book and select with no conditions") | ||
void shouldInsertBookAndSelectWithNoConditions(List<Book> books) { | ||
books.forEach(book -> template.insert(book)); | ||
|
||
try { | ||
List<Book> result = template.select(Book.class) | ||
.result(); | ||
|
||
SoftAssertions.assertSoftly(soft -> { | ||
soft.assertThat(result) | ||
.isNotEmpty() | ||
.hasSize(books.size()); | ||
}); | ||
} catch (UnsupportedOperationException exp) { | ||
SoftAssertions.assertSoftly(soft -> { | ||
soft.assertThat(exp).isInstanceOf(UnsupportedOperationException.class); | ||
}); | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ArgumentsSource(BookSupplier.class) | ||
@DisplayName("Should select book by title") | ||
void shouldSelectBookByTitle(List<Book> books) { | ||
books.forEach(book -> template.insert(book)); | ||
|
||
try { | ||
var result = template.select(Book.class) | ||
.where("title") | ||
.eq(books.get(0).title()) | ||
.<Book>result(); | ||
|
||
SoftAssertions.assertSoftly(soft -> { | ||
soft.assertThat(result) | ||
.isNotEmpty() | ||
.allMatch(book -> book.title().equals(books.get(0).title())); | ||
}); | ||
} catch (UnsupportedOperationException exp) { | ||
SoftAssertions.assertSoftly(soft -> { | ||
soft.assertThat(exp).isInstanceOf(UnsupportedOperationException.class); | ||
}); | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ArgumentsSource(BookSupplier.class) | ||
@DisplayName("Should select book with 'like' condition") | ||
void shouldSelectBookWithLikeCondition(List<Book> books) { | ||
books.forEach(book -> template.insert(book)); | ||
|
||
try { | ||
var result = template.select(Book.class) | ||
.where("title") | ||
.like(books.get(0).title()) | ||
.<Book>result(); | ||
|
||
SoftAssertions.assertSoftly(soft -> { | ||
soft.assertThat(result) | ||
.isNotEmpty() | ||
.allMatch(book -> book.title().contains(books.get(0).title())); | ||
}); | ||
} catch (UnsupportedOperationException exp) { | ||
SoftAssertions.assertSoftly(soft -> { | ||
soft.assertThat(exp).isInstanceOf(UnsupportedOperationException.class); | ||
}); | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ArgumentsSource(BookSupplier.class) | ||
@DisplayName("Should select book by genre") | ||
void shouldSelectBookByGenre(List<Book> books) { | ||
books.forEach(book -> template.insert(book)); | ||
|
||
try { | ||
var result = template.select(Book.class) | ||
.where("genre") | ||
.eq(books.get(0).genre()) | ||
.<Book>result(); | ||
|
||
SoftAssertions.assertSoftly(soft -> { | ||
soft.assertThat(result) | ||
.isNotEmpty() | ||
.allMatch(book -> book.genre().equals(books.get(0).genre())); | ||
}); | ||
} catch (UnsupportedOperationException exp) { | ||
SoftAssertions.assertSoftly(soft -> { | ||
soft.assertThat(exp).isInstanceOf(UnsupportedOperationException.class); | ||
}); | ||
} | ||
} | ||
} |