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:
Oliver Gierke
2013-05-04 11:46:18 +02:00
parent 617423797d
commit 31006e1866
2 changed files with 26 additions and 4 deletions

View File

@@ -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));