DATACMNS-650 - Polishing.
Added stream to the list of supported query method prefixes. Allow Stream to be used as return type for paginating queries, too. Renamed Java8StreamUtils to StreamUtils. Some additional JavaDoc. Original pull request: #116.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2014 the original author or authors.
|
||||
* Copyright 2008-2015 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.
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -138,6 +139,30 @@ public class QueryMethodUnitTests {
|
||||
assertThat(new QueryMethod(method, repositoryMetadata).isCollectionQuery(), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-650
|
||||
*/
|
||||
@Test
|
||||
public void considersMethodReturningAStreamStreaming() throws Exception {
|
||||
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
Method method = SampleRepository.class.getMethod("streaming");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata).isStreamQuery(), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-650
|
||||
*/
|
||||
@Test
|
||||
public void doesNotRejectStreamingForPagination() throws Exception {
|
||||
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
Method method = SampleRepository.class.getMethod("streaming", Pageable.class);
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata).isStreamQuery(), is(true));
|
||||
}
|
||||
|
||||
interface SampleRepository extends Repository<User, Serializable> {
|
||||
|
||||
String pagingMethodWithInvalidReturnType(Pageable pageable);
|
||||
@@ -157,6 +182,10 @@ public class QueryMethodUnitTests {
|
||||
Slice<User> sliceOfUsers();
|
||||
|
||||
User[] arrayOfUsers();
|
||||
|
||||
Stream<String> streaming();
|
||||
|
||||
Stream<String> streaming(Pageable pageable);
|
||||
}
|
||||
|
||||
class User {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2014 the original author or authors.
|
||||
* Copyright 2008-2015 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. You may obtain a copy of
|
||||
@@ -46,7 +46,7 @@ import org.springframework.data.repository.query.parser.PartTree.OrPart;
|
||||
*/
|
||||
public class PartTreeUnitTests {
|
||||
|
||||
private String[] PREFIXES = { "find", "read", "get", "query", "count", "delete", "remove" };
|
||||
private String[] PREFIXES = { "find", "read", "get", "query", "stream", "count", "delete", "remove" };
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullSource() throws Exception {
|
||||
@@ -650,25 +650,26 @@ public class PartTreeUnitTests {
|
||||
assertLimiting("countFirst10DistinctUsersByLastname", User.class, false, null, true);
|
||||
assertLimiting("countTop10DistinctUsersByLastname", User.class, false, null, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see DATACMNS-581
|
||||
*/
|
||||
@Test
|
||||
public void parsesIsNotContainingCorrectly() throws Exception {
|
||||
assertType(asList("firstnameIsNotContaining", "firstnameNotContaining", "firstnameNotContains"), NOT_CONTAINING, "firstname");
|
||||
assertType(asList("firstnameIsNotContaining", "firstnameNotContaining", "firstnameNotContains"), NOT_CONTAINING,
|
||||
"firstname");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see DATACMNS-581
|
||||
*/
|
||||
@Test
|
||||
public void buildsPartTreeForNotContainingCorrectly() throws Exception {
|
||||
|
||||
|
||||
PartTree tree = new PartTree("findAllByLegalNameNotContaining", Organization.class);
|
||||
assertPart(tree, new Part[] { new Part("legalNameNotContaining", Organization.class) });
|
||||
}
|
||||
|
||||
|
||||
private static void assertLimiting(String methodName, Class<?> entityType, boolean limiting, Integer maxResults) {
|
||||
assertLimiting(methodName, entityType, limiting, maxResults, false);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.util;
|
||||
|
||||
import static org.springframework.data.util.StreamUtils.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -29,9 +30,9 @@ import org.junit.Test;
|
||||
* Spring Data specific Java {@link Stream} utility methods and classes.
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
* @since 1.8
|
||||
* @since 1.10
|
||||
*/
|
||||
public class Java8StreamUtilsTests {
|
||||
public class StreamUtilsTests {
|
||||
|
||||
/**
|
||||
* @see DATACMNS-650
|
||||
@@ -40,7 +41,7 @@ public class Java8StreamUtilsTests {
|
||||
public void shouldConvertAnIteratorToAStream() {
|
||||
|
||||
List<String> input = Arrays.asList("a", "b", "c");
|
||||
Stream<String> stream = Java8StreamUtils.createStreamFromIterator(input.iterator());
|
||||
Stream<String> stream = createStreamFromIterator(input.iterator());
|
||||
List<String> output = stream.collect(Collectors.<String> toList());
|
||||
|
||||
assertThat(input, is(equalTo(output)));
|
||||
Reference in New Issue
Block a user