-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
523676f
commit efec4c3
Showing
5 changed files
with
131 additions
and
12 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
11 changes: 11 additions & 0 deletions
11
redis-om-spring/src/test/java/com/redis/om/spring/repository/DocumentProjection.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,11 @@ | ||
package com.redis.om.spring.repository; | ||
|
||
public interface DocumentProjection { | ||
String getName(); | ||
RecursiveSummary getRecursiveProjection(); | ||
|
||
interface RecursiveSummary { | ||
String getRecursiveProp1(); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
redis-om-spring/src/test/java/com/redis/om/spring/repository/DocumentProjectionPojo.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,30 @@ | ||
package com.redis.om.spring.repository; | ||
|
||
import com.redis.om.spring.annotations.Document; | ||
import lombok.Data; | ||
import org.springframework.data.annotation.Id; | ||
|
||
import java.util.UUID; | ||
|
||
@Document | ||
@Data | ||
public class DocumentProjectionPojo { | ||
|
||
@Id | ||
private String id; | ||
|
||
private String name; | ||
|
||
private RecursiveProjection recursiveProjection; | ||
|
||
public DocumentProjectionPojo() { | ||
this.id = UUID.randomUUID().toString(); | ||
} | ||
|
||
|
||
@Data | ||
static class RecursiveProjection { | ||
private String recursiveProp1; | ||
private String recursiveProp2; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...-om-spring/src/test/java/com/redis/om/spring/repository/DocumentProjectionRepository.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,9 @@ | ||
package com.redis.om.spring.repository; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
public interface DocumentProjectionRepository extends RedisDocumentRepository<DocumentProjectionPojo, String> { | ||
Optional<DocumentProjection> findByName(String name); | ||
Collection<DocumentProjection> findAllByName(String name); | ||
} |
64 changes: 64 additions & 0 deletions
64
redis-om-spring/src/test/java/com/redis/om/spring/repository/DocumentProjectionTest.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,64 @@ | ||
package com.redis.om.spring.repository; | ||
|
||
import com.redis.om.spring.AbstractBaseDocumentTest; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class DocumentProjectionTest extends AbstractBaseDocumentTest { | ||
|
||
public static final String TEST_NAME = "testName"; | ||
public static final String TEST_REC_1 = "test1"; | ||
public static final String TEST_REC_2 = "test2"; | ||
private final DocumentProjectionRepository documentProjectionRepository; | ||
|
||
@Autowired | ||
DocumentProjectionTest(DocumentProjectionRepository documentProjectionRepository) { | ||
this.documentProjectionRepository = documentProjectionRepository; | ||
} | ||
|
||
@BeforeEach | ||
void setUp() { | ||
for (int i = 0; i < 2; i++) { | ||
DocumentProjectionPojo entity = new DocumentProjectionPojo(); | ||
entity.setName(TEST_NAME); | ||
DocumentProjectionPojo.RecursiveProjection recursiveProjection = new DocumentProjectionPojo.RecursiveProjection(); | ||
recursiveProjection.setRecursiveProp1(TEST_REC_1); | ||
recursiveProjection.setRecursiveProp2(TEST_REC_2); | ||
entity.setRecursiveProjection(recursiveProjection); | ||
documentProjectionRepository.save(entity); | ||
} | ||
} | ||
|
||
@Test | ||
void testEntityProjection() { | ||
Optional<DocumentProjection> byNameProjection = documentProjectionRepository.findByName(TEST_NAME); | ||
assertTrue(byNameProjection.isPresent()); | ||
assertEquals(TEST_NAME, byNameProjection.get().getName()); | ||
assertNotNull(byNameProjection.get().getRecursiveProjection()); | ||
assertEquals(TEST_REC_1, byNameProjection.get().getRecursiveProjection().getRecursiveProp1()); | ||
} | ||
|
||
@Test | ||
void testCollectionProjection() { | ||
Collection<DocumentProjection> byNameProjection = documentProjectionRepository.findAllByName(TEST_NAME); | ||
assertNotNull(byNameProjection); | ||
assertEquals(2, byNameProjection.size()); | ||
byNameProjection.forEach(documentProjection -> { | ||
assertNotNull(documentProjection.getName()); | ||
assertNotNull(documentProjection.getRecursiveProjection()); | ||
}); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
documentProjectionRepository.deleteAll(); | ||
} | ||
|
||
} |