|
30 | 30 | import org.junit.jupiter.params.ParameterizedTest;
|
31 | 31 | import org.junit.jupiter.params.provider.ValueSource;
|
32 | 32 | import org.springframework.data.annotation.Transient;
|
| 33 | +import org.springframework.data.mapping.AssociationHandler; |
33 | 34 | import org.springframework.data.mapping.MappingException;
|
34 | 35 | import org.springframework.data.neo4j.core.schema.DynamicLabels;
|
35 | 36 | import org.springframework.data.neo4j.core.schema.GeneratedValue;
|
@@ -129,6 +130,26 @@ void doesFailOnRelationshipPropertiesWithMissingTargetNode() {
|
129 | 130 | .getPersistentEntity(EntityWithInCorrectRelationshipProperties.class))
|
130 | 131 | .withMessageContaining("Missing @TargetNode declaration in");
|
131 | 132 | }
|
| 133 | + |
| 134 | + @Test // DATAGRAPH-2289 |
| 135 | + void correctlyFindRelationshipObverse() { |
| 136 | + Neo4jMappingContext neo4jMappingContext = new Neo4jMappingContext(); |
| 137 | + Neo4jPersistentEntity<?> persistentEntity = neo4jMappingContext.getPersistentEntity(EntityWithBidirectionalRelationship.class); |
| 138 | + persistentEntity.doWithAssociations((AssociationHandler<Neo4jPersistentProperty>) a -> { |
| 139 | + RelationshipDescription rd = (RelationshipDescription) a; |
| 140 | + assertThat(rd.getRelationshipObverse()).isNotNull(); |
| 141 | + }); |
| 142 | + } |
| 143 | + |
| 144 | + @Test // DATAGRAPH-2289 |
| 145 | + void correctlyFindRelationshipObverseWithRelationshipProperties() { |
| 146 | + Neo4jMappingContext neo4jMappingContext = new Neo4jMappingContext(); |
| 147 | + Neo4jPersistentEntity<?> persistentEntity = neo4jMappingContext.getPersistentEntity(EntityWithBidirectionalRelationshipProperties.class); |
| 148 | + persistentEntity.doWithAssociations((AssociationHandler<Neo4jPersistentProperty>) a -> { |
| 149 | + RelationshipDescription rd = (RelationshipDescription) a; |
| 150 | + assertThat(rd.getRelationshipObverse()).isNotNull(); |
| 151 | + }); |
| 152 | + } |
132 | 153 | }
|
133 | 154 |
|
134 | 155 | @Nested
|
@@ -491,4 +512,43 @@ static class HasNoTargetNodeRelationshipProperties {
|
491 | 512 | @Id @GeneratedValue
|
492 | 513 | private Long id;
|
493 | 514 | }
|
| 515 | + |
| 516 | + @Node |
| 517 | + static class EntityWithBidirectionalRelationship { |
| 518 | + |
| 519 | + @Id @GeneratedValue |
| 520 | + private Long id; |
| 521 | + |
| 522 | + @Relationship("KNOWS") |
| 523 | + List<EntityWithBidirectionalRelationship> knows; |
| 524 | + |
| 525 | + @Relationship(type = "KNOWS" , direction = Relationship.Direction.INCOMING) |
| 526 | + List<EntityWithBidirectionalRelationship> knownBy; |
| 527 | + |
| 528 | + } |
| 529 | + |
| 530 | + @Node |
| 531 | + static class EntityWithBidirectionalRelationshipProperties { |
| 532 | + |
| 533 | + @Id @GeneratedValue |
| 534 | + private Long id; |
| 535 | + |
| 536 | + @Relationship("KNOWS") |
| 537 | + List<BidirectionalRelationshipProperties> knows; |
| 538 | + |
| 539 | + @Relationship(type = "KNOWS" , direction = Relationship.Direction.INCOMING) |
| 540 | + List<BidirectionalRelationshipProperties> knownBy; |
| 541 | + |
| 542 | + } |
| 543 | + |
| 544 | + @RelationshipProperties |
| 545 | + static class BidirectionalRelationshipProperties { |
| 546 | + |
| 547 | + @Id @GeneratedValue |
| 548 | + private Long id; |
| 549 | + |
| 550 | + @TargetNode |
| 551 | + EntityWithBidirectionalRelationshipProperties target; |
| 552 | + } |
| 553 | + |
494 | 554 | }
|
0 commit comments