15
15
*/
16
16
package org .springframework .data .neo4j .integration .imperative ;
17
17
18
+ import org .junit .jupiter .api .BeforeEach ;
18
19
import org .junit .jupiter .api .Test ;
19
20
import org .neo4j .driver .Driver ;
21
+ import org .neo4j .driver .Record ;
22
+ import org .neo4j .driver .Session ;
20
23
import org .springframework .beans .factory .annotation .Autowired ;
21
24
import org .springframework .context .annotation .Bean ;
22
25
import org .springframework .context .annotation .Configuration ;
36
39
import org .springframework .data .neo4j .test .Neo4jIntegrationTest ;
37
40
import org .springframework .transaction .annotation .EnableTransactionManagement ;
38
41
42
+ import java .util .ArrayList ;
39
43
import java .util .Arrays ;
40
44
import java .util .Collection ;
41
45
import java .util .Collections ;
@@ -54,6 +58,19 @@ public class ImmutableGeneratedIdsIT {
54
58
55
59
protected static Neo4jExtension .Neo4jConnectionSupport neo4jConnectionSupport ;
56
60
61
+ private final Driver driver ;
62
+
63
+ public ImmutableGeneratedIdsIT (@ Autowired Driver driver ) {
64
+ this .driver = driver ;
65
+ }
66
+
67
+ @ BeforeEach
68
+ void cleanUp () {
69
+ try (Session session = driver .session ()) {
70
+ session .run ("MATCH (n) DETACH DELETE n" ).consume ();
71
+ }
72
+ }
73
+
57
74
@ Test // GH-2141
58
75
void saveWithGeneratedIdsReturnsObjectWithIdSet (
59
76
@ Autowired ImmutablePersonWithGeneratedIdRepository repository ) {
@@ -295,6 +312,36 @@ void childrenShouldNotBeRecreatedForNoReasons(@Autowired Neo4jTemplate template)
295
312
assertThat (saved .getChildren ()).allMatch (c -> c .getId () != null && children .contains (c ));
296
313
}
297
314
315
+ @ Test // GH-2223
316
+ void saveWithGeneratedIdsWithMultipleRelationshipsToOneNode (
317
+ @ Autowired ImmutablePersonWithGeneratedIdRepository repository ) {
318
+
319
+ ImmutablePersonWithGeneratedId person1 = new ImmutablePersonWithGeneratedId ();
320
+ ImmutablePersonWithGeneratedId person2 = ImmutablePersonWithGeneratedId .fallback (person1 );
321
+ List <ImmutablePersonWithGeneratedId > onboardedBy = new ArrayList <>();
322
+ onboardedBy .add (person1 );
323
+ onboardedBy .add (person2 );
324
+ ImmutablePersonWithGeneratedId person3 = ImmutablePersonWithGeneratedId .wasOnboardedBy (onboardedBy );
325
+
326
+ ImmutablePersonWithGeneratedId savedPerson = repository .save (person3 );
327
+ assertThat (savedPerson .id ).isNotNull ();
328
+ assertThat (savedPerson .wasOnboardedBy ).allMatch (ob -> ob .id != null );
329
+
330
+ ImmutablePersonWithGeneratedId savedPerson2 = savedPerson .wasOnboardedBy .stream ().filter (p -> p .fallback != null ).findFirst ().get ();
331
+ assertThat (savedPerson2 .fallback .id ).isNotNull ();
332
+
333
+ try (Session session = driver .session ()) {
334
+ List <Record > result = session .run (
335
+ "MATCH (person3:ImmutablePersonWithGeneratedId) " +
336
+ "-[:ONBOARDED_BY]->(person2:ImmutablePersonWithGeneratedId) " +
337
+ "-[:FALLBACK]->(person1:ImmutablePersonWithGeneratedId), " +
338
+ "(person3)-[:ONBOARDED_BY]->(person1) " +
339
+ "return person3" )
340
+ .list ();
341
+ assertThat (result ).hasSize (1 );
342
+ }
343
+ }
344
+
298
345
@ Configuration
299
346
@ EnableNeo4jRepositories (considerNestedRepositories = true )
300
347
@ EnableTransactionManagement
0 commit comments