|
17 | 17 |
|
18 | 18 | import static org.assertj.core.api.Assertions.assertThat;
|
19 | 19 |
|
| 20 | +import org.neo4j.driver.Record; |
| 21 | +import org.neo4j.driver.Session; |
| 22 | +import org.springframework.data.neo4j.repository.Neo4jRepository; |
20 | 23 | import reactor.test.StepVerifier;
|
21 | 24 |
|
| 25 | +import java.util.ArrayList; |
22 | 26 | import java.util.Arrays;
|
23 | 27 | import java.util.Collections;
|
24 | 28 | import java.util.List;
|
@@ -302,6 +306,41 @@ void childrenShouldNotBeRecreatedForNoReasons(@Autowired ReactiveNeo4jTemplate t
|
302 | 306 | .verifyComplete();
|
303 | 307 | }
|
304 | 308 |
|
| 309 | + @Test // GH-2223 |
| 310 | + void saveWithGeneratedIdsWithMultipleRelationshipsToOneNode(@Autowired Driver driver, |
| 311 | + @Autowired ImmutablePersonWithGeneratedIdRepository repository) { |
| 312 | + |
| 313 | + ImmutablePersonWithGeneratedId person1 = new ImmutablePersonWithGeneratedId(); |
| 314 | + ImmutablePersonWithGeneratedId person2 = ImmutablePersonWithGeneratedId.fallback(person1); |
| 315 | + List<ImmutablePersonWithGeneratedId> onboardedBy = new ArrayList<>(); |
| 316 | + onboardedBy.add(person1); |
| 317 | + onboardedBy.add(person2); |
| 318 | + ImmutablePersonWithGeneratedId person3 = ImmutablePersonWithGeneratedId.wasOnboardedBy(onboardedBy); |
| 319 | + |
| 320 | + StepVerifier.create(repository.save(person3)) |
| 321 | + .assertNext(savedPerson -> { |
| 322 | + assertThat(savedPerson.id).isNotNull(); |
| 323 | + assertThat(savedPerson.wasOnboardedBy).allMatch(ob -> ob.id != null); |
| 324 | + |
| 325 | + ImmutablePersonWithGeneratedId savedPerson2 = savedPerson.wasOnboardedBy.stream().filter(p -> p.fallback != null).findFirst().get(); |
| 326 | + assertThat(savedPerson2.fallback.id).isNotNull(); |
| 327 | + }) |
| 328 | + .verifyComplete(); |
| 329 | + |
| 330 | + try (Session session = driver.session()) { |
| 331 | + List<Record> result = session.run( |
| 332 | + "MATCH (person3:ImmutablePersonWithGeneratedId) " + |
| 333 | + "-[:ONBOARDED_BY]->(person2:ImmutablePersonWithGeneratedId) " + |
| 334 | + "-[:FALLBACK]->(person1:ImmutablePersonWithGeneratedId), " + |
| 335 | + "(person3)-[:ONBOARDED_BY]->(person1) " + |
| 336 | + "return person3") |
| 337 | + .list(); |
| 338 | + assertThat(result).hasSize(1); |
| 339 | + } |
| 340 | + } |
| 341 | + |
| 342 | + interface ImmutablePersonWithGeneratedIdRepository extends ReactiveNeo4jRepository<ImmutablePersonWithGeneratedId, Long> {} |
| 343 | + |
305 | 344 | @Configuration
|
306 | 345 | @EnableReactiveNeo4jRepositories(considerNestedRepositories = true)
|
307 | 346 | @EnableTransactionManagement
|
|
0 commit comments