-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: enables explicitely indexed @id fields (resolves gh292)
- Loading branch information
Showing
8 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...rc/test/java/com/redis/om/spring/annotations/document/ExplicitelyIndexedIdFieldsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.redis.om.spring.annotations.document; | ||
|
||
import com.google.common.collect.Sets; | ||
import com.redis.om.spring.AbstractBaseDocumentTest; | ||
import com.redis.om.spring.annotations.document.fixtures.*; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.geo.Distance; | ||
import org.springframework.data.geo.Point; | ||
import org.springframework.data.redis.connection.RedisGeoCommands; | ||
import redis.clients.jedis.json.Path; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SuppressWarnings("SpellCheckingInspection") | ||
class ExplicitelyIndexedIdFieldsTest extends AbstractBaseDocumentTest { | ||
|
||
@Autowired | ||
DocWithIndexedIdRepository docWithIndexedIdRepository; | ||
|
||
@Autowired | ||
DocWithSearchableIdRepository docWithSearchableIdRepository; | ||
|
||
@Autowired | ||
DocWithTagIndexedIdRepository docWithTagIndexedIdRepository; | ||
|
||
@BeforeEach | ||
void cleanUp() { | ||
docWithIndexedIdRepository.saveAll(List.of(DocWithIndexedId.of("DWII01", "DWII01"), DocWithIndexedId.of("DWII02", "DWII02"))); | ||
docWithSearchableIdRepository.saveAll(List.of(DocWithSearchableId.of("DWSI01", "DWSI01"), DocWithSearchableId.of("DWSI02", "DWSI02"))); | ||
docWithTagIndexedIdRepository.saveAll(List.of(DocWithTagIndexedId.of("DWTII01", "DWTII01"), DocWithTagIndexedId.of("DWTII02", "DWTII02"))); | ||
} | ||
|
||
@Test void testFindById() { | ||
Optional<DocWithIndexedId> maybeDWII01 = docWithIndexedIdRepository.findById("DWII01"); | ||
Optional<DocWithSearchableId> maybeDWSI01 = docWithSearchableIdRepository.findById("DWSI01"); | ||
Optional<DocWithTagIndexedId> maybeDWTII01 = docWithTagIndexedIdRepository.findById("DWTII01"); | ||
|
||
assertAll( // | ||
() -> assertThat(maybeDWII01).isPresent(), // | ||
() -> assertThat(maybeDWSI01).isPresent(), // | ||
() -> assertThat(maybeDWTII01).isPresent() // | ||
); | ||
} | ||
|
||
@Test void testFindAll() { | ||
var allDWII = docWithIndexedIdRepository.findAll(); | ||
var allDWSI = docWithSearchableIdRepository.findAll(); | ||
var allDWTII = docWithTagIndexedIdRepository.findAll(); | ||
|
||
assertAll( // | ||
() -> assertThat(allDWII).hasSize(2), // | ||
() -> assertThat(allDWSI).hasSize(2), // | ||
() -> assertThat(allDWTII).hasSize(2) // | ||
); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ing/src/test/java/com/redis/om/spring/annotations/document/fixtures/DocWithIndexedId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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; | ||
|
||
@Data | ||
@RequiredArgsConstructor(staticName = "of") | ||
@Document | ||
public class DocWithIndexedId { | ||
@Id | ||
@Indexed | ||
@NonNull | ||
protected String id; | ||
|
||
@NonNull | ||
private String name; | ||
} |
6 changes: 6 additions & 0 deletions
6
...st/java/com/redis/om/spring/annotations/document/fixtures/DocWithIndexedIdRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 DocWithIndexedIdRepository extends RedisDocumentRepository<DocWithIndexedId, String> { | ||
} |
21 changes: 21 additions & 0 deletions
21
.../src/test/java/com/redis/om/spring/annotations/document/fixtures/DocWithSearchableId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.redis.om.spring.annotations.document.fixtures; | ||
|
||
import com.redis.om.spring.annotations.Document; | ||
import com.redis.om.spring.annotations.Searchable; | ||
import lombok.Data; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.annotation.Id; | ||
|
||
@Data | ||
@RequiredArgsConstructor(staticName = "of") | ||
@Document | ||
public class DocWithSearchableId { | ||
@Id | ||
@Searchable | ||
@NonNull | ||
protected String id; | ||
|
||
@NonNull | ||
private String name; | ||
} |
6 changes: 6 additions & 0 deletions
6
...java/com/redis/om/spring/annotations/document/fixtures/DocWithSearchableIdRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 DocWithSearchableIdRepository extends RedisDocumentRepository<DocWithSearchableId, String> { | ||
} |
21 changes: 21 additions & 0 deletions
21
.../src/test/java/com/redis/om/spring/annotations/document/fixtures/DocWithTagIndexedId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.redis.om.spring.annotations.document.fixtures; | ||
|
||
import com.redis.om.spring.annotations.Document; | ||
import com.redis.om.spring.annotations.TagIndexed; | ||
import lombok.Data; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.annotation.Id; | ||
|
||
@Data | ||
@RequiredArgsConstructor(staticName = "of") | ||
@Document | ||
public class DocWithTagIndexedId { | ||
@Id | ||
@TagIndexed | ||
@NonNull | ||
protected String id; | ||
|
||
@NonNull | ||
private String name; | ||
} |
6 changes: 6 additions & 0 deletions
6
...java/com/redis/om/spring/annotations/document/fixtures/DocWithTagIndexedIdRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 DocWithTagIndexedIdRepository extends RedisDocumentRepository<DocWithTagIndexedId, String> { | ||
} |