|
18 | 18 | import static org.assertj.core.api.Assertions.assertThat;
|
19 | 19 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
20 | 20 |
|
| 21 | +import java.util.ArrayList; |
21 | 22 | import java.util.Arrays;
|
22 | 23 | import java.util.Collections;
|
23 | 24 | import java.util.List;
|
@@ -307,6 +308,39 @@ void shouldDoThings(@Autowired VersionedThingRepository repository) {
|
307 | 308 | }
|
308 | 309 | }
|
309 | 310 |
|
| 311 | + @Test // GH-2191 |
| 312 | + void shouldNotTraverseToBidiRelatedThingsWithOldVersion(@Autowired VersionedThingRepository repository) { |
| 313 | + VersionedThing thing1 = new VersionedThing("Thing1"); |
| 314 | + VersionedThing thing2 = new VersionedThing("Thing2"); |
| 315 | + VersionedThing thing3 = new VersionedThing("Thing3"); |
| 316 | + VersionedThing thing4 = new VersionedThing("Thing4"); |
| 317 | + |
| 318 | + List<VersionedThing> thing1Relationships = new ArrayList<>(); |
| 319 | + thing1Relationships.add(thing2); |
| 320 | + thing1Relationships.add(thing3); |
| 321 | + thing1Relationships.add(thing4); |
| 322 | + thing1.setOtherVersionedThings(thing1Relationships); |
| 323 | + repository.save(thing1); |
| 324 | + // Initially creates: |
| 325 | + // Thing1-[:HAS]->Thing2 |
| 326 | + // Thing1-[:HAS]->Thing3 |
| 327 | + // Thing1-[:HAS]->Thing4 |
| 328 | + |
| 329 | + thing1 = repository.findById(thing1.getId()).get(); |
| 330 | + thing3 = repository.findById(thing3.getId()).get(); |
| 331 | + thing3.setOtherVersionedThings(Collections.singletonList(thing1)); |
| 332 | + repository.save(thing3); |
| 333 | + // adds |
| 334 | + // Thing3-[:HAS]->Thing1 |
| 335 | + |
| 336 | + try (Session session = driver.session()) { |
| 337 | + Long relationshipCount = session |
| 338 | + .run("MATCH (:VersionedThing)-[r:HAS]->(:VersionedThing) return count(r) as relationshipCount") |
| 339 | + .single().get("relationshipCount").asLong(); |
| 340 | + assertThat(relationshipCount).isEqualTo(4); |
| 341 | + } |
| 342 | + } |
| 343 | + |
310 | 344 | interface VersionedThingRepository extends Neo4jRepository<VersionedThing, Long> {}
|
311 | 345 |
|
312 | 346 | interface VersionedThingWithAssignedIdRepository extends Neo4jRepository<VersionedThingWithAssignedId, Long> {}
|
|
0 commit comments