Add support for executing derived existsBy queries.
Closes: #385 Original pull request: #386.
This commit is contained in:
committed by
Mark Paluch
parent
8f1c0ece24
commit
8c32f0ae6d
@@ -137,10 +137,32 @@ class KeyValuePartTreeQueryUnitTests {
|
||||
assertThat(query.getRows()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test // GH-385
|
||||
void shouldUseCountForExists() throws NoSuchMethodException {
|
||||
|
||||
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
|
||||
when(metadataMock.getReturnType(any(Method.class)))
|
||||
.thenReturn((TypeInformation) ClassTypeInformation.from(Boolean.class));
|
||||
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Boolean.class);
|
||||
|
||||
QueryMethod qm = new QueryMethod(Repo.class.getMethod("existsByFirstname", String.class), metadataMock,
|
||||
projectionFactoryMock);
|
||||
|
||||
KeyValuePartTreeQuery partTreeQuery = new KeyValuePartTreeQuery(qm, QueryMethodEvaluationContextProvider.DEFAULT,
|
||||
kvOpsMock, SpelQueryCreator.class);
|
||||
|
||||
KeyValueQuery<?> query = partTreeQuery.prepareQuery(new Object[] { "firstname" });
|
||||
partTreeQuery.doExecute(new Object[] { "firstname" }, query);
|
||||
|
||||
verify(kvOpsMock).count(eq(query), eq(Person.class));
|
||||
}
|
||||
|
||||
interface Repo {
|
||||
|
||||
List<Person> findByFirstname(String firstname);
|
||||
|
||||
boolean existsByFirstname(String firstname);
|
||||
|
||||
List<Person> findBy(Pageable page);
|
||||
|
||||
List<Person> findTop3By();
|
||||
|
||||
Reference in New Issue
Block a user