Skip to content

Commit

Permalink
DATAJPA-1140 - Added test for reproducing the issue.
Browse files Browse the repository at this point in the history
Original PR: #205
  • Loading branch information
kevin-peters authored and schauder committed Jul 4, 2017
1 parent c76584f commit 0529f69
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Expand Up @@ -88,6 +88,7 @@
* @author Thomas Darimont
* @author Christoph Strobl
* @author Mark Paluch
* @author Kevin Peters
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:application-context.xml")
Expand Down Expand Up @@ -1540,6 +1541,47 @@ public void shouldFindUsersInNativeQueryWithPagination() {

assertThat(users.getContent()).hasSize(2).containsExactly(thirdUser, fourthUser);
}

@Test // DATAJPA-1140
public void shouldFindUsersByUserFirstnameAsSpELExpressionAndLastnameAsStringInStringBasedQuery() {

flushTestUsers();

List<User> users = repository.findUsersByUserFirstnameAsSpELExpressionAndLastnameAsString(firstUser, firstUser.getLastname());

assertThat(users).containsOnly(firstUser);
}

@Test // DATAJPA-1140
public void shouldFindUsersByFirstnameAsStringAndUserLastnameAsSpELExpressionInStringBasedQuery() {

flushTestUsers();

List<User> users = repository.findUsersByFirstnameAsStringAndUserLastnameAsSpELExpression(firstUser.getFirstname(), firstUser);

assertThat(users).containsOnly(firstUser);
}


@Test // DATAJPA-1140
public void shouldFindUsersByUserFirstnameAsSpELExpressionAndLastnameAsFakeSpELExpressionInStringBasedQuery() {

flushTestUsers();

List<User> users = repository.findUsersByUserFirstnameAsSpELExpressionAndLastnameAsFakeSpELExpression(firstUser, firstUser.getLastname());

assertThat(users).containsOnly(firstUser);
}

@Test // DATAJPA-1140
public void shouldFindUsersByFirstnameAsFakeSpELExpressionAndUserLastnameAsSpELExpressionInStringBasedQuery() {

flushTestUsers();

List<User> users = repository.findUsersByFirstnameAsFakeSpELExpressionAndUserLastnameAsSpELExpression(firstUser.getFirstname(), firstUser);

assertThat(users).containsOnly(firstUser);
}

@Test // DATAJPA-629
public void shouldfindUsersBySpELExpressionParametersWithSpelTemplateExpression() {
Expand Down
Expand Up @@ -48,6 +48,7 @@
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Kevin Peters
*/
public interface UserRepository
extends JpaRepository<User, Integer>, JpaSpecificationExecutor<User>, UserRepositoryCustom {
Expand Down Expand Up @@ -429,6 +430,22 @@ public interface UserRepository
value = "select * from (select rownum() as RN, u.* from SD_User u) where RN between ?#{ #pageable.offset -1} and ?#{#pageable.offset + #pageable.pageSize}",
countQuery = "select count(u.id) from SD_User u", nativeQuery = true)
Page<User> findUsersInNativeQueryWithPagination(Pageable pageable);

// DATAJPA-1140
@Query("select u from User u where u.firstname =:#{#user.firstname} and u.lastname =:lastname")
List<User> findUsersByUserFirstnameAsSpELExpressionAndLastnameAsString(@Param("user") User user, @Param("lastname") String lastname);

// DATAJPA-1140
@Query("select u from User u where u.firstname =:firstname and u.lastname =:#{#user.lastname}")
List<User> findUsersByFirstnameAsStringAndUserLastnameAsSpELExpression(@Param("firstname") String firstname, @Param("user") User user);

// DATAJPA-1140
@Query("select u from User u where u.firstname =:#{#user.firstname} and u.lastname =:#{#lastname}")
List<User> findUsersByUserFirstnameAsSpELExpressionAndLastnameAsFakeSpELExpression(@Param("user") User user, @Param("lastname") String lastname);

// DATAJPA-1140
@Query("select u from User u where u.firstname =:#{#firstname} and u.lastname =:#{#user.lastname}")
List<User> findUsersByFirstnameAsFakeSpELExpressionAndUserLastnameAsSpELExpression(@Param("firstname") String firstname, @Param("user") User user);

// DATAJPA-629
@Query("select u from #{#entityName} u where u.firstname = ?#{[0]} and u.lastname = ?#{[1]}")
Expand Down

0 comments on commit 0529f69

Please sign in to comment.