DATACMNS-716 - Allow collection executions with wrapper types as return values.
We now support collection executions in query derivation in combination with wrapper types like (Future, Optional, CompletableFuture, ListenableFuture) that wrap a collection, e.g. Future<List<User>>. Previously we used the "raw" return type which tricked our detection for Collection / Page / Slice executions. Original pull request: #130.
This commit is contained in:
committed by
Oliver Gierke
parent
6b9b27956d
commit
7adb67351b
@@ -20,6 +20,9 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -34,6 +37,7 @@ import org.springframework.data.repository.core.support.DefaultRepositoryMetadat
|
||||
* Unit tests for {@link QueryMethod}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class QueryMethodUnitTests {
|
||||
|
||||
@@ -163,6 +167,54 @@ public class QueryMethodUnitTests {
|
||||
assertThat(new QueryMethod(method, repositoryMetadata).isStreamQuery(), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-716
|
||||
*/
|
||||
@Test
|
||||
public void doesNotRejectCompletableFutureQueryForSingleEntity() throws Exception {
|
||||
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
Method method = SampleRepository.class.getMethod("returnsCompletableFutureForSingleEntity");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata).isCollectionQuery(), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-716
|
||||
*/
|
||||
@Test
|
||||
public void doesNotRejectCompletableFutureQueryForEntityCollection() throws Exception {
|
||||
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
Method method = SampleRepository.class.getMethod("returnsCompletableFutureForEntityCollection");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata).isCollectionQuery(), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-716
|
||||
*/
|
||||
@Test
|
||||
public void doesNotRejectFutureQueryForSingleEntity() throws Exception {
|
||||
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
Method method = SampleRepository.class.getMethod("returnsFutureForSingleEntity");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata).isCollectionQuery(), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-716
|
||||
*/
|
||||
@Test
|
||||
public void doesNotRejectFutureQueryForEntityCollection() throws Exception {
|
||||
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
Method method = SampleRepository.class.getMethod("returnsFutureForEntityCollection");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata).isCollectionQuery(), is(true));
|
||||
}
|
||||
|
||||
interface SampleRepository extends Repository<User, Serializable> {
|
||||
|
||||
String pagingMethodWithInvalidReturnType(Pageable pageable);
|
||||
@@ -186,6 +238,26 @@ public class QueryMethodUnitTests {
|
||||
Stream<String> streaming();
|
||||
|
||||
Stream<String> streaming(Pageable pageable);
|
||||
|
||||
/**
|
||||
* @see DATACMNS-716
|
||||
*/
|
||||
CompletableFuture<User> returnsCompletableFutureForSingleEntity();
|
||||
|
||||
/**
|
||||
* @see DATACMNS-716
|
||||
*/
|
||||
CompletableFuture<List<User>> returnsCompletableFutureForEntityCollection();
|
||||
|
||||
/**
|
||||
* @see DATACMNS-716
|
||||
*/
|
||||
Future<User> returnsFutureForSingleEntity();
|
||||
|
||||
/**
|
||||
* @see DATACMNS-716
|
||||
*/
|
||||
Future<List<User>> returnsFutureForEntityCollection();
|
||||
}
|
||||
|
||||
class User {
|
||||
|
||||
Reference in New Issue
Block a user