Skip to content

Commit

Permalink
Test filtering by nested list properties
Browse files Browse the repository at this point in the history
  • Loading branch information
gediminasmorkys committed Sep 22, 2023
1 parent fce58bf commit 19a6152
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
@Autowired
ComplexRepository complexRepository;

@Autowired
ScheduledRepository scheduledRepository;

@Autowired
EntityStream es;

Expand Down Expand Up @@ -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<Scheduled> 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);

}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<Filter> filters;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.redis.om.spring.annotations.document.fixtures;

import com.redis.om.spring.repository.RedisDocumentRepository;

public interface ScheduledRepository extends RedisDocumentRepository<Scheduled, String> {
}

0 comments on commit 19a6152

Please sign in to comment.