Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests to cover all conditions in KiwiSpringMongoQueriesTest #458

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,16 @@ void shouldPaginate_GettingSecondPage(SoftAssertions softly) {
softly.assertThat(orderPage.getContent()).isEqualTo(expectedOrders);
}

@Test
void shouldPaginate_AndSetLimitToOne_WhenNoneIsGiven(SoftAssertions softly) {
var pageNumber = 0;

@ParameterizedTest
@CsvSource({
" 0 , ",
" 0, 0 ",
" 0, -1 ",
})
void shouldPaginate_AndSetLimitToOne_WhenInvalidLimitIsGiven(Integer pageNumber, Integer limit, SoftAssertions softly) {
var pagingParams = new PagingRequest();
pagingParams.setPage(pageNumber);
pagingParams.setLimit(limit);

var orderPage = KiwiSpringMongoQueries.paginate(mongoTemplate, pagingParams, Order.class);

Expand All @@ -234,11 +238,15 @@ void shouldPaginate_AndSetLimitToOne_WhenNoneIsGiven(SoftAssertions softly) {
softly.assertThat(orderPage.getContent()).isEqualTo(List.of(first(storedOrders)));
}

@Test
void shouldPaginate_AndSetPageToZero_WhenNoneIsGiven(SoftAssertions softly) {
var limit = 5;

@ParameterizedTest
@CsvSource({
" , 5 ",
" -1 , 5 ",
" -5 , 5 ",
})
void shouldPaginate_AndSetPageToZero_WhenInvalidPageIsGiven(Integer pageNumber, Integer limit, SoftAssertions softly) {
var pagingParams = new PagingRequest();
pagingParams.setPage(pageNumber);
pagingParams.setLimit(limit);

var orderPage = KiwiSpringMongoQueries.paginate(mongoTemplate, pagingParams, Order.class);
Expand Down Expand Up @@ -345,6 +353,34 @@ void shouldIgnoreAddDateBounds_WhenGivenNullStartAndEnd(SoftAssertions softly) {
softly.assertThat(orderPage.getContent()).isEqualTo(storedOrders.subList(0, limit));
}

@Test
void shouldIgnoreNullStartOrEnd_WhenAddingDateBounds(SoftAssertions softly) {
var pageNumber = 0;
var limit = 25;

var pagingParams = new PagingRequest();
pagingParams.setPage(pageNumber);
pagingParams.setLimit(limit);

var now = Instant.now();

// only lower bound
var startMillis = KiwiInstants.minusDays(now, 50).toEpochMilli();
var lowerBoundOrderPage = KiwiSpringMongoQueries.paginate(mongoTemplate, pagingParams, Order.class,
(pagingQuery, pagingRequest) ->
addDateBounds(pagingQuery, "dateReceived", startMillis, null));

softly.assertThat(lowerBoundOrderPage.getTotalElements()).isEqualTo(storedOrderCount);

// only upper bound
var endMillis = KiwiInstants.plusDays(now, 30).toEpochMilli();
var upperBoundOrderPage = KiwiSpringMongoQueries.paginate(mongoTemplate, pagingParams, Order.class,
(pagingQuery, pagingRequest) ->
addDateBounds(pagingQuery, "dateReceived", null, endMillis));

softly.assertThat(upperBoundOrderPage.getTotalElements()).isEqualTo(storedOrderCount);
}

@ParameterizedTest
@CsvSource({
" true , PARTIAL_MATCH ",
Expand Down