|
20 | 20 | import static org.mockito.Mockito.doReturn;
|
21 | 21 | import static org.mockito.Mockito.when;
|
22 | 22 |
|
| 23 | +import java.util.Collections; |
23 | 24 | import java.util.Map;
|
24 | 25 | import java.util.Optional;
|
| 26 | +import java.util.regex.Pattern; |
25 | 27 | import java.util.stream.Stream;
|
26 | 28 |
|
27 | 29 | import org.junit.Assert;
|
|
30 | 32 | import org.junit.jupiter.params.provider.Arguments;
|
31 | 33 | import org.junit.jupiter.params.provider.MethodSource;
|
32 | 34 | import org.mockito.Mockito;
|
| 35 | +import org.neo4j.cypherdsl.core.Cypher; |
33 | 36 | import org.neo4j.cypherdsl.core.Statement;
|
34 | 37 | import org.neo4j.cypherdsl.core.renderer.Renderer;
|
35 | 38 | import org.springframework.data.domain.Sort;
|
@@ -139,6 +142,44 @@ void shouldCreateRelationshipRemoveQueryWithoutUsingInternalIds() {
|
139 | 142 | Assert.assertEquals(expectedQuery, Renderer.getDefaultRenderer().render(statement));
|
140 | 143 | }
|
141 | 144 |
|
| 145 | + @Test |
| 146 | + void shouldCreateDynamicRelationshipPathQueryForEnumsWithoutWildcardRelationships() { |
| 147 | + Neo4jPersistentEntity<?> persistentEntity = new Neo4jMappingContext() |
| 148 | + .getPersistentEntity(CyclicEntityWithEnumeratedDynamicRelationship1.class); |
| 149 | + |
| 150 | + org.neo4j.cypherdsl.core.Node rootNode = Cypher.anyNode(Constants.NAME_OF_ROOT_NODE); |
| 151 | + Statement statement = CypherGenerator.INSTANCE.createPathMatchWithCondition(null, persistentEntity, |
| 152 | + Collections.emptyList(), null, rootNode).returning(rootNode).build(); |
| 153 | + |
| 154 | + // we want to ensure that the pattern occurs three times but do not care about the order |
| 155 | + // of the relationship types |
| 156 | + Pattern pattern = Pattern.compile( |
| 157 | + "\\[:(`CORNERED`\\|`ROUND`|`ROUND`\\|`CORNERED`)\\*.*" + |
| 158 | + "\\[:(`CORNERED`\\|`ROUND`|`ROUND`\\|`CORNERED`)\\*.*" + |
| 159 | + "\\[:(`CORNERED`\\|`ROUND`|`ROUND`\\|`CORNERED`)\\*"); |
| 160 | + |
| 161 | + String renderedStatement = Renderer.getDefaultRenderer().render(statement); |
| 162 | + assertThat(renderedStatement).containsPattern(pattern); |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + void shouldCreateDynamicRelationshipPathQueryForStringsWithWildcardRelationships() { |
| 167 | + Neo4jPersistentEntity<?> persistentEntity = new Neo4jMappingContext() |
| 168 | + .getPersistentEntity(CyclicEntityWithStringDynamicRelationship1.class); |
| 169 | + |
| 170 | + org.neo4j.cypherdsl.core.Node rootNode = Cypher.anyNode(Constants.NAME_OF_ROOT_NODE); |
| 171 | + Statement statement = CypherGenerator.INSTANCE.createPathMatchWithCondition(null, persistentEntity, |
| 172 | + Collections.emptyList(), null, rootNode).returning(rootNode).build(); |
| 173 | + |
| 174 | + Pattern pattern = Pattern.compile( |
| 175 | + "\\[\\*0\\.\\.1].*" + |
| 176 | + "\\[\\*0\\.\\.1].*" + |
| 177 | + "\\[\\*0\\.\\.].*"); |
| 178 | + |
| 179 | + String renderedStatement = Renderer.getDefaultRenderer().render(statement); |
| 180 | + assertThat(renderedStatement).containsPattern(pattern); |
| 181 | + } |
| 182 | + |
142 | 183 | private static Stream<Arguments> pageables() {
|
143 | 184 | return Stream.of(
|
144 | 185 | Arguments.of(Sort.by("a", "b").and(
|
@@ -219,4 +260,41 @@ private static class MultipleLabelEntity2 {
|
219 | 260 | private Map<String, MultipleLabelEntity2> dynamicRelationships;
|
220 | 261 | }
|
221 | 262 |
|
| 263 | + enum CyclicRelationship { |
| 264 | + ROUND, |
| 265 | + CORNERED |
| 266 | + } |
| 267 | + |
| 268 | + @Node |
| 269 | + private static class CyclicEntityWithEnumeratedDynamicRelationship1 { |
| 270 | + |
| 271 | + @Id private Long id; |
| 272 | + |
| 273 | + private Map<CyclicRelationship, CyclicEntityWithEnumeratedDynamicRelationship2> dynamicRelationship; |
| 274 | + } |
| 275 | + |
| 276 | + @Node |
| 277 | + private static class CyclicEntityWithEnumeratedDynamicRelationship2 { |
| 278 | + |
| 279 | + @Id private Long id; |
| 280 | + |
| 281 | + private Map<CyclicRelationship, CyclicEntityWithEnumeratedDynamicRelationship1> dynamicRelationship; |
| 282 | + } |
| 283 | + |
| 284 | + @Node |
| 285 | + private static class CyclicEntityWithStringDynamicRelationship1 { |
| 286 | + |
| 287 | + @Id private Long id; |
| 288 | + |
| 289 | + private Map<String, CyclicEntityWithStringDynamicRelationship2> dynamicRelationship; |
| 290 | + } |
| 291 | + |
| 292 | + @Node |
| 293 | + private static class CyclicEntityWithStringDynamicRelationship2 { |
| 294 | + |
| 295 | + @Id private Long id; |
| 296 | + |
| 297 | + private Map<String, CyclicEntityWithStringDynamicRelationship1> dynamicRelationship; |
| 298 | + } |
| 299 | + |
222 | 300 | }
|
0 commit comments