DATAKV-169 - Add support for IN keyword in derived queries.

We now support `In` keyword in derived finder methods (eg. `findByFirstnameIn(Collection<String> firstnames)`) when using SpEL based queries.

Original pull request: #23.
This commit is contained in:
Christoph Strobl
2017-04-13 15:39:37 +02:00
committed by Mark Paluch
parent 979f3a33a8
commit f67a66bf25
3 changed files with 109 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import org.joda.time.format.DateTimeFormatter;
@@ -260,6 +261,51 @@ public class SpelQueryCreatorUnitTests {
assertThat(evaluate("findByLastnameMatches", "^s.*w$").against(ROBB), is(false));
}
@Test // DATAKV-169
public void inReturnsMatchCorrectly() throws Exception {
ArrayList<String> list = new ArrayList<>();
list.add(ROBB.firstname);
assertThat(evaluate("findByFirstnameIn", list).against(ROBB), is(true));
}
@Test // DATAKV-169
public void inNotMatchingReturnsCorrectly() throws Exception {
ArrayList<String> list = new ArrayList<>();
list.add(ROBB.firstname);
assertThat(evaluate("findByFirstnameIn", list).against(JON), is(false));
}
@Test // DATAKV-169
public void inWithNullCompareValuesCorrectly() throws Exception {
ArrayList<String> list = new ArrayList<>();
list.add(null);
assertThat(evaluate("findByFirstnameIn", list).against(JON), is(false));
}
@Test // DATAKV-169
public void inWithNullSourceValuesMatchesCorrectly() throws Exception {
ArrayList<String> list = new ArrayList<>();
list.add(ROBB.firstname);
assertThat(evaluate("findByFirstnameIn", list).against(new Person(null, 10)), is(false));
}
@Test // DATAKV-169
public void inMatchesNullValuesCorrectly() throws Exception {
ArrayList<String> list = new ArrayList<>();
list.add(null);
assertThat(evaluate("findByFirstnameIn", list).against(new Person(null, 10)), is(true));
}
private Evaluation evaluate(String methodName, Object... args) throws Exception {
return new Evaluation((SpelExpression) createQueryForMethodWithArgs(methodName, args).getCritieria());
}
@@ -344,6 +390,9 @@ public class SpelQueryCreatorUnitTests {
// Type.REGEX
Person findByLastnameMatches(String lastname);
// Type.IN
Person findByFirstnameIn(ArrayList<String> in);
}
static class Evaluation {