DATAJPA-341 - Fixed regression introduced in advanced LIKE binding.
We now don't throw an exception anymore in case a normal LIKE binding is used in manually defined queries.
This commit is contained in:
@@ -25,18 +25,39 @@ import org.springframework.data.jpa.repository.query.StringQuery.LikeBinding;
|
||||
import org.springframework.data.repository.query.parser.Part.Type;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link StringQuery}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class StringQueryUnitTests {
|
||||
|
||||
/**
|
||||
* @see DATAJPA-341
|
||||
*/
|
||||
@Test
|
||||
public void doesNotConsiderPlainLikeABinding() {
|
||||
|
||||
String source = "select from User u where u.firstname like :firstname";
|
||||
StringQuery query = new StringQuery(source);
|
||||
|
||||
assertThat(query.hasLikeBindings(), is(true));
|
||||
assertThat(query.getQuery(), is(source));
|
||||
|
||||
List<LikeBinding> bindings = query.getLikeBindings();
|
||||
assertThat(bindings, hasSize(1));
|
||||
|
||||
LikeBinding binding = bindings.get(0);
|
||||
assertThat(binding.getType(), is(Type.LIKE));
|
||||
assertThat(binding.hasName("firstname"), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detectsPositionalLikeBindings() {
|
||||
|
||||
StringQuery query = new StringQuery("select u from User u where u.firstname like %?1% or u.lastname like %?2");
|
||||
|
||||
assertThat(query.hasLikeBindings(), is(true));
|
||||
assertThat(query.getQuery(),
|
||||
is("select u from User u where u.firstname like ?1 or u.lastname like ?2"));
|
||||
assertThat(query.getQuery(), is("select u from User u where u.firstname like ?1 or u.lastname like ?2"));
|
||||
|
||||
List<LikeBinding> bindings = query.getLikeBindings();
|
||||
assertThat(bindings, hasSize(2));
|
||||
|
||||
Reference in New Issue
Block a user