Skip to content

Commit 43805af

Browse files
schauderodrotbohm
authored andcommitted
DATAJPA-1185 - Added integration test for wrapped dynamic projections.
Original pull request: #223.
1 parent 2b78d8c commit 43805af

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import static org.springframework.data.domain.Example.*;
2222
import static org.springframework.data.domain.ExampleMatcher.*;
2323
import static org.springframework.data.domain.Sort.Direction.*;
24-
import static org.springframework.data.jpa.domain.Specifications.not;
2524
import static org.springframework.data.jpa.domain.Specifications.*;
25+
import static org.springframework.data.jpa.domain.Specifications.not;
2626
import static org.springframework.data.jpa.domain.sample.UserSpecifications.*;
2727

2828
import java.util.ArrayList;
@@ -33,6 +33,7 @@
3333
import java.util.List;
3434
import java.util.Set;
3535
import java.util.function.Consumer;
36+
import java.util.stream.Collectors;
3637
import java.util.stream.Stream;
3738

3839
import javax.persistence.EntityManager;
@@ -55,7 +56,6 @@
5556
import org.springframework.dao.InvalidDataAccessApiUsageException;
5657
import org.springframework.data.domain.Example;
5758
import org.springframework.data.domain.ExampleMatcher;
58-
import org.springframework.data.domain.ExampleMatcher.*;
5959
import org.springframework.data.domain.Page;
6060
import org.springframework.data.domain.PageImpl;
6161
import org.springframework.data.domain.PageRequest;
@@ -64,6 +64,7 @@
6464
import org.springframework.data.domain.Sort;
6565
import org.springframework.data.domain.Sort.Direction;
6666
import org.springframework.data.domain.Sort.Order;
67+
import org.springframework.data.domain.ExampleMatcher.*;
6768
import org.springframework.data.jpa.domain.Specification;
6869
import org.springframework.data.jpa.domain.sample.Address;
6970
import org.springframework.data.jpa.domain.sample.Role;
@@ -2142,7 +2143,27 @@ public void excutesPagedSpecificationSettingAnOrder() {
21422143
public void queryProvidesCorrectNumberOfParametersForNativeQuery() {
21432144

21442145
Query query = em.createNativeQuery("select 1 from User where firstname=? and lastname=?");
2145-
assertThat(query.getParameters(),hasSize(2));
2146+
assertThat(query.getParameters(), hasSize(2));
2147+
}
2148+
2149+
@Test // DATAJPA-1185
2150+
public void dynamicProjectionReturningStream() {
2151+
2152+
flushTestUsers();
2153+
2154+
Stream<User> users = repository.findAsStreamByFirstnameLike("%O%", User.class);
2155+
2156+
assertThat(users.collect(Collectors.toList()), hasSize(1));
2157+
}
2158+
2159+
@Test // DATAJPA-1185
2160+
public void dynamicProjectionReturningList() {
2161+
2162+
flushTestUsers();
2163+
2164+
List<User> users = repository.findAsListByFirstnameLike("%O%", User.class);
2165+
2166+
assertThat(users, hasSize(1));
21462167
}
21472168

21482169
private Page<User> executeSpecWithSort(Sort sort) {

src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,12 @@ List<User> findUsersByFirstnameForSpELExpressionWithParameterIndexOnlyWithEntity
468468

469469
List<RolesAndFirstname> findRolesAndFirstnameBy();
470470

471+
// DATAJPA-1185
472+
<T> Stream<T> findAsStreamByFirstnameLike(String name, Class<T> projectionType);
473+
474+
// DATAJPA-1185
475+
<T> List<T> findAsListByFirstnameLike(String name, Class<T> projectionType);
476+
471477
static interface RolesAndFirstname {
472478

473479
String getFirstname();

0 commit comments

Comments
 (0)