Skip to content

Commit

Permalink
chore: update and crete querymapper select record
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <[email protected]>
  • Loading branch information
otaviojava committed Dec 24, 2024
1 parent 7ce3cea commit f6057e7
Showing 1 changed file with 120 additions and 1 deletion.
121 changes: 120 additions & 1 deletion tck/src/main/java/jakarta/nosql/tck/QueryMapperSelectRecordTest.java
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);
});
}
}
}

0 comments on commit f6057e7

Please sign in to comment.