Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test filtering by nested list properties #352

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> {
}