Added sort validation

This commit now validates that the value passed via a PageRequest to
sort the results by is a valid value.

Resolves #739

Fixed to allow for all letter cases
This commit is contained in:
Michael Minella
2020-11-03 10:50:25 -06:00
committed by Glenn Renfro
parent bb7d235900
commit 704b8df2ad
2 changed files with 52 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,12 +46,14 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Executes unit tests on JdbcTaskExecutionDao.
*
* @author Glenn Renfro
* @author Gunnar Hillert
* @author Michael Minella
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration(
@@ -209,6 +211,31 @@ public class JdbcTaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
expectedTaskExecution.getExecutionId()));
}
@Test
@DirtiesContext
public void testFindRunningTaskExecutions() {
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
assertThat(this.dao.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("START_TIME"))).getTotalElements())
.isEqualTo(4);
}
@Test
@DirtiesContext
public void testFindRunningTaskExecutionsIllegalSort() {
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
assertThatThrownBy(() -> this.dao.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("ILLEGAL_SORT"))).getTotalElements())
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid sort option selected: ILLEGAL_SORT");
}
@Test
@DirtiesContext
public void testFindRunningTaskExecutionsSortWithDifferentCase() {
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
assertThat(this.dao.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("StArT_TiMe"))).getTotalElements())
.isEqualTo(4);
}
private TaskExecution initializeTaskExecutionWithExternalExecutionId() {
TaskExecution expectedTaskExecution = TestVerifierUtils
.createSampleTaskExecutionNoArg();