From 19a6152d0357b99615e6e4282a275bcc429f916e Mon Sep 17 00:00:00 2001 From: Gediminas Morkys Date: Fri, 22 Sep 2023 17:09:00 +0300 Subject: [PATCH] Test filtering by nested list properties --- .../document/ComplexDocumentSearchTest.java | 54 +++++++++++++++++++ .../annotations/document/fixtures/Filter.java | 34 ++++++++++++ .../document/fixtures/Scheduled.java | 25 +++++++++ .../fixtures/ScheduledRepository.java | 6 +++ 4 files changed, 119 insertions(+) create mode 100644 redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/fixtures/Filter.java create mode 100644 redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/fixtures/Scheduled.java create mode 100644 redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/fixtures/ScheduledRepository.java diff --git a/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/ComplexDocumentSearchTest.java b/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/ComplexDocumentSearchTest.java index 18b2e8f2..88a675af 100644 --- a/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/ComplexDocumentSearchTest.java +++ b/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/ComplexDocumentSearchTest.java @@ -33,6 +33,9 @@ @Autowired ComplexRepository complexRepository; + @Autowired + ScheduledRepository scheduledRepository; + @Autowired EntityStream es; @@ -362,4 +365,55 @@ void testListInsideAListTagSearch() { () -> assertThat(withTaradiddle).extracting("id").containsExactlyInAnyOrder("complex2", "complex3") // ); } + + @Test + void testValidFilterMatch() { + int startOf2022 = 1; + int endOf2022 = 2; + int startOf2023 = 3; + int endOf2023 = 5; + int mid2023 = 4; + + Scheduled scheduled1 = Scheduled.of( + "1", + List.of( + Filter.of( + 1L, + startOf2023, + endOf2023, + "admin", + "role" + ), + Filter.of( + 2L, + startOf2022, + endOf2022, + "user", + "role" + ) + )); + Scheduled scheduled2 = Scheduled.of( + "2", + List.of( + Filter.of( + 3L, + startOf2023, + endOf2023, + "user", + "role" + ) + )); + + scheduledRepository.save(scheduled1); + scheduledRepository.save(scheduled2); + + List adminRolesValidAtTime = es.of(Scheduled.class) + .filter(Scheduled$.FILTERS.VALID_FROM.lt(mid2023)) + .filter(Scheduled$.FILTERS.TYPE.equals("role")) + .filter(Scheduled$.FILTERS.VALUE.equals("admin")) + .collect(Collectors.toList()); + + assertThat(adminRolesValidAtTime.size()).isEqualTo(1); + + } } diff --git a/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/fixtures/Filter.java b/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/fixtures/Filter.java new file mode 100644 index 00000000..5b494fc8 --- /dev/null +++ b/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/fixtures/Filter.java @@ -0,0 +1,34 @@ +package com.redis.om.spring.annotations.document.fixtures; + +import com.redis.om.spring.annotations.Document; +import com.redis.om.spring.annotations.Indexed; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.data.annotation.Id; + +@Document +@Data +@RequiredArgsConstructor(staticName = "of") +public class Filter { + + @Id + @NonNull + private Long id; + + @Indexed + @NonNull + private Integer validFrom; + + @Indexed + @NonNull + private Integer validTo; + + @Indexed + @NonNull + private String value; + + @Indexed + @NonNull + private String type; +} diff --git a/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/fixtures/Scheduled.java b/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/fixtures/Scheduled.java new file mode 100644 index 00000000..50215e89 --- /dev/null +++ b/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/fixtures/Scheduled.java @@ -0,0 +1,25 @@ +package com.redis.om.spring.annotations.document.fixtures; + +import com.redis.om.spring.annotations.Document; +import com.redis.om.spring.annotations.Indexed; +import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.data.annotation.Id; + +import java.util.List; + +@Document +@Data +@RequiredArgsConstructor(staticName = "of") +public class Scheduled { + + @Id + @NonNull + private String id; + + @Indexed + @NonNull + private List filters; + +} diff --git a/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/fixtures/ScheduledRepository.java b/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/fixtures/ScheduledRepository.java new file mode 100644 index 00000000..405c7b55 --- /dev/null +++ b/redis-om-spring/src/test/java/com/redis/om/spring/annotations/document/fixtures/ScheduledRepository.java @@ -0,0 +1,6 @@ +package com.redis.om.spring.annotations.document.fixtures; + +import com.redis.om.spring.repository.RedisDocumentRepository; + +public interface ScheduledRepository extends RedisDocumentRepository { +}