|
36 | 36 | import org.springframework.context.annotation.Configuration;
|
37 | 37 | import org.springframework.data.neo4j.config.AbstractNeo4jConfig;
|
38 | 38 | import org.springframework.data.neo4j.core.Neo4jTemplate;
|
| 39 | +import org.springframework.data.neo4j.repository.Neo4jRepository; |
| 40 | +import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; |
39 | 41 | import org.springframework.data.neo4j.test.Neo4jExtension;
|
40 | 42 | import org.springframework.data.neo4j.test.Neo4jIntegrationTest;
|
41 | 43 | import org.springframework.transaction.annotation.EnableTransactionManagement;
|
@@ -83,6 +85,62 @@ static void setupData(@Autowired Driver driver) throws IOException {
|
83 | 85 | }
|
84 | 86 | }
|
85 | 87 |
|
| 88 | + interface MovieProjection { |
| 89 | + |
| 90 | + String getTitle(); |
| 91 | + |
| 92 | + List<Actor> getActors(); |
| 93 | + } |
| 94 | + |
| 95 | + static class MovieDTO { |
| 96 | + |
| 97 | + private final String title; |
| 98 | + |
| 99 | + private final List<Actor> actors; |
| 100 | + |
| 101 | + MovieDTO(String title, List<Actor> actors) { |
| 102 | + this.title = title; |
| 103 | + this.actors = actors; |
| 104 | + } |
| 105 | + |
| 106 | + public String getTitle() { |
| 107 | + return title; |
| 108 | + } |
| 109 | + |
| 110 | + public List<Actor> getActors() { |
| 111 | + return actors; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + interface MovieRepository extends Neo4jRepository<Movie, String> { |
| 116 | + |
| 117 | + MovieProjection findProjectionByTitle(String title); |
| 118 | + |
| 119 | + MovieDTO findDTOByTitle(String title); |
| 120 | + } |
| 121 | + |
| 122 | + @Test // GH-2117 |
| 123 | + void bothCyclicAndNonCyclicRelationshipsAreExcludedFromProjections(@Autowired MovieRepository movieRepository) { |
| 124 | + |
| 125 | + // The movie domain is a good fit for this test |
| 126 | + // as the cyclic dependencies is pretty slow to retrieve from Neo4j |
| 127 | + // this does OOM in most setups. |
| 128 | + MovieProjection projection = movieRepository.findProjectionByTitle("The Matrix"); |
| 129 | + assertThat(projection.getTitle()).isNotNull(); |
| 130 | + assertThat(projection.getActors()).isNotEmpty(); |
| 131 | + } |
| 132 | + |
| 133 | + @Test // GH-2117 |
| 134 | + void bothCyclicAndNonCyclicRelationshipsAreExcludedFromDTOProjections(@Autowired MovieRepository movieRepository) { |
| 135 | + |
| 136 | + // The movie domain is a good fit for this test |
| 137 | + // as the cyclic dependencies is pretty slow to retrieve from Neo4j |
| 138 | + // this does OOM in most setups. |
| 139 | + MovieDTO dtoProjection = movieRepository.findDTOByTitle("The Matrix"); |
| 140 | + assertThat(dtoProjection.getTitle()).isNotNull(); |
| 141 | + assertThat(dtoProjection.getActors()).isNotEmpty(); |
| 142 | + } |
| 143 | + |
86 | 144 | @Test // GH-2114
|
87 | 145 | void bothStartAndEndNodeOfPathsMustBeLookedAt(@Autowired Neo4jTemplate template) {
|
88 | 146 |
|
@@ -237,6 +295,7 @@ void pathMappingWithAdditionalInformationShouldWork(@Autowired Neo4jTemplate tem
|
237 | 295 |
|
238 | 296 | @Configuration
|
239 | 297 | @EnableTransactionManagement
|
| 298 | + @EnableNeo4jRepositories(considerNestedRepositories = true) |
240 | 299 | static class Config extends AbstractNeo4jConfig {
|
241 | 300 |
|
242 | 301 | @Bean
|
|
0 commit comments