diff --git a/src/main/asciidoc/new-features.adoc b/src/main/asciidoc/new-features.adoc index 9c1ec669e..8bad4f155 100644 --- a/src/main/asciidoc/new-features.adoc +++ b/src/main/asciidoc/new-features.adoc @@ -15,6 +15,7 @@ This section briefly covers items that are new and noteworthy in the latest rele * `BITFIELD`, `BITPOS`, and `OBJECT` command support. * Align return types of `BoundZSetOperations` with `ZSetOperations`. * Reactive `SCAN`, `HSCAN`, `SSCAN`, and `ZSCAN` support. +* Usage of `IsTrue` and `IsFalse` keywords in repository query methods. [[new-in-2.0.0]] == New in Spring Data Redis 2.0 diff --git a/src/main/java/org/springframework/data/redis/repository/query/RedisQueryCreator.java b/src/main/java/org/springframework/data/redis/repository/query/RedisQueryCreator.java index 6163d83b6..01d86f9a4 100644 --- a/src/main/java/org/springframework/data/redis/repository/query/RedisQueryCreator.java +++ b/src/main/java/org/springframework/data/redis/repository/query/RedisQueryCreator.java @@ -59,6 +59,12 @@ public class RedisQueryCreator extends AbstractQueryCreator result = repo.findPersonByAliveIsTrue(); + + assertThat(result, hasSize(1)); + assertThat(result, contains(eddard)); + } + @Test // DATAREDIS-547 public void shouldReturnEmptyListWhenPageableOutOfBoundsUsingFindAll() { @@ -374,6 +392,8 @@ public abstract class RedisRepositoryIntegrationTestBase { Page findPersonByLastname(String lastname, Pageable page); + List findPersonByAliveIsTrue(); + List findByFirstnameAndLastname(String firstname, String lastname); List findByFirstnameOrLastname(String firstname, String lastname); @@ -429,6 +449,7 @@ public abstract class RedisRepositoryIntegrationTestBase { @Id String id; @Indexed String firstname; + @Indexed Boolean alive; String lastname; @Reference City city; City hometown; diff --git a/src/test/java/org/springframework/data/redis/repository/query/RedisQueryCreatorUnitTests.java b/src/test/java/org/springframework/data/redis/repository/query/RedisQueryCreatorUnitTests.java index 27e3a8992..c330cc8e2 100644 --- a/src/test/java/org/springframework/data/redis/repository/query/RedisQueryCreatorUnitTests.java +++ b/src/test/java/org/springframework/data/redis/repository/query/RedisQueryCreatorUnitTests.java @@ -173,6 +173,30 @@ public class RedisQueryCreatorUnitTests { creator.createQuery(); } + @Test // DATAREDIS-771 + public void findByBooleanIsTrue() throws SecurityException, NoSuchMethodException { + + RedisQueryCreator creator = createQueryCreatorForMethodWithArgs( + SampleRepository.class.getMethod("findByAliveIsTrue"), new Object[0]); + + KeyValueQuery query = creator.createQuery(); + + assertThat(query.getCriteria().getSismember(), hasSize(1)); + assertThat(query.getCriteria().getSismember(), hasItem(new PathAndValue("alive", true))); + } + + @Test // DATAREDIS-771 + public void findByBooleanIsFalse() throws SecurityException, NoSuchMethodException { + + RedisQueryCreator creator = createQueryCreatorForMethodWithArgs( + SampleRepository.class.getMethod("findByAliveIsFalse"), new Object[0]); + + KeyValueQuery query = creator.createQuery(); + + assertThat(query.getCriteria().getSismember(), hasSize(1)); + assertThat(query.getCriteria().getSismember(), hasItem(new PathAndValue("alive", false))); + } + private RedisQueryCreator createQueryCreatorForMethodWithArgs(Method method, Object[] args) { PartTree partTree = new PartTree(method.getName(), method.getReturnType()); @@ -190,6 +214,10 @@ public class RedisQueryCreatorUnitTests { Person findByAgeOrFirstname(Integer age, String firstname); + Person findByAliveIsTrue(); + + Person findByAliveIsFalse(); + Person findByLocationWithin(Circle circle); Person findByLocationNear(Point point, Distance distance);