Skip to content

Commit 8422bf9

Browse files
committed
GH-2289 - Improved check for observe detection more tests.
1 parent 6efee93 commit 8422bf9

File tree

1 file changed

+130
-5
lines changed

1 file changed

+130
-5
lines changed

src/test/java/org/springframework/data/neo4j/core/mapping/DefaultNeo4jPersistentEntityTest.java

+130-5
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ void doesFailOnRelationshipPropertiesWithMissingTargetNode() {
131131
.withMessageContaining("Missing @TargetNode declaration in");
132132
}
133133

134-
@Test // DATAGRAPH-2289
135-
void correctlyFindRelationshipObverse() {
134+
@Test // DATAGRAPH-2189
135+
void correctlyFindRelationshipObverseSameEntity() {
136136
Neo4jMappingContext neo4jMappingContext = new Neo4jMappingContext();
137137
Neo4jPersistentEntity<?> persistentEntity = neo4jMappingContext.getPersistentEntity(EntityWithBidirectionalRelationship.class);
138138
persistentEntity.doWithAssociations((AssociationHandler<Neo4jPersistentProperty>) a -> {
@@ -141,15 +141,60 @@ void correctlyFindRelationshipObverse() {
141141
});
142142
}
143143

144-
@Test // DATAGRAPH-2289
144+
@Test // DATAGRAPH-2189
145+
void correctlyFindRelationshipObverse() {
146+
Neo4jMappingContext neo4jMappingContext = new Neo4jMappingContext();
147+
Neo4jPersistentEntity<?> persistentEntity = neo4jMappingContext.getPersistentEntity(EntityWithBidirectionalRelationshipToOtherEntity.class);
148+
persistentEntity.doWithAssociations((AssociationHandler<Neo4jPersistentProperty>) a -> {
149+
RelationshipDescription rd = (RelationshipDescription) a;
150+
assertThat(rd.getRelationshipObverse()).isNotNull();
151+
});
152+
persistentEntity = neo4jMappingContext.getPersistentEntity(OtherEntityWithBidirectionalRelationship.class);
153+
persistentEntity.doWithAssociations((AssociationHandler<Neo4jPersistentProperty>) a -> {
154+
RelationshipDescription rd = (RelationshipDescription) a;
155+
assertThat(rd.getRelationshipObverse()).isNotNull();
156+
});
157+
}
158+
159+
@Test // DATAGRAPH-2189
145160
void correctlyFindRelationshipObverseWithRelationshipProperties() {
161+
Neo4jMappingContext neo4jMappingContext = new Neo4jMappingContext();
162+
Neo4jPersistentEntity<?> persistentEntity = neo4jMappingContext.getPersistentEntity(EntityWithBidirectionalRelationshipToOtherEntityWithRelationshipProperties.class);
163+
persistentEntity.doWithAssociations((AssociationHandler<Neo4jPersistentProperty>) a -> {
164+
RelationshipDescription rd = (RelationshipDescription) a;
165+
assertThat(rd.getRelationshipObverse()).isNotNull();
166+
});
167+
persistentEntity = neo4jMappingContext.getPersistentEntity(OtherEntityWithBidirectionalRelationship.class);
168+
persistentEntity.doWithAssociations((AssociationHandler<Neo4jPersistentProperty>) a -> {
169+
RelationshipDescription rd = (RelationshipDescription) a;
170+
assertThat(rd.getRelationshipObverse()).isNotNull();
171+
});
172+
}
173+
174+
@Test // DATAGRAPH-2189
175+
void correctlyFindSameEntityRelationshipObverseWithRelationshipProperties() {
146176
Neo4jMappingContext neo4jMappingContext = new Neo4jMappingContext();
147177
Neo4jPersistentEntity<?> persistentEntity = neo4jMappingContext.getPersistentEntity(EntityWithBidirectionalRelationshipProperties.class);
148178
persistentEntity.doWithAssociations((AssociationHandler<Neo4jPersistentProperty>) a -> {
149179
RelationshipDescription rd = (RelationshipDescription) a;
150180
assertThat(rd.getRelationshipObverse()).isNotNull();
151181
});
152182
}
183+
184+
@Test // DATAGRAPH-2189
185+
void correctlyDontFindRelationshipObverse() {
186+
Neo4jMappingContext neo4jMappingContext = new Neo4jMappingContext();
187+
Neo4jPersistentEntity<?> persistentEntity = neo4jMappingContext.getPersistentEntity(EntityLooksLikeHasObserve.class);
188+
persistentEntity.doWithAssociations((AssociationHandler<Neo4jPersistentProperty>) a -> {
189+
RelationshipDescription rd = (RelationshipDescription) a;
190+
assertThat(rd.getRelationshipObverse()).isNull();
191+
});
192+
persistentEntity = neo4jMappingContext.getPersistentEntity(OtherEntityLooksLikeHasObserve.class);
193+
persistentEntity.doWithAssociations((AssociationHandler<Neo4jPersistentProperty>) a -> {
194+
RelationshipDescription rd = (RelationshipDescription) a;
195+
assertThat(rd.getRelationshipObverse()).isNull();
196+
});
197+
}
153198
}
154199

155200
@Nested
@@ -522,11 +567,73 @@ static class EntityWithBidirectionalRelationship {
522567
@Relationship("KNOWS")
523568
List<EntityWithBidirectionalRelationship> knows;
524569

525-
@Relationship(type = "KNOWS" , direction = Relationship.Direction.INCOMING)
570+
@Relationship(type = "KNOWS", direction = Relationship.Direction.INCOMING)
526571
List<EntityWithBidirectionalRelationship> knownBy;
527572

528573
}
529574

575+
@Node
576+
static class EntityWithBidirectionalRelationshipToOtherEntity {
577+
578+
@Id @GeneratedValue
579+
private Long id;
580+
581+
@Relationship("KNOWS")
582+
List<OtherEntityWithBidirectionalRelationship> knows;
583+
584+
}
585+
586+
@Node
587+
static class OtherEntityWithBidirectionalRelationship {
588+
589+
@Id @GeneratedValue
590+
private Long id;
591+
592+
@Relationship(type = "KNOWS", direction = Relationship.Direction.INCOMING)
593+
List<EntityWithBidirectionalRelationshipToOtherEntity> knownBy;
594+
595+
}
596+
597+
@Node
598+
static class EntityWithBidirectionalRelationshipToOtherEntityWithRelationshipProperties {
599+
600+
@Id @GeneratedValue
601+
private Long id;
602+
603+
@Relationship("KNOWS")
604+
List<OtherEntityWithBidirectionalRelationshipWithRelationshipPropertiesProperties> knows;
605+
606+
}
607+
608+
@Node
609+
static class OtherEntityWithBidirectionalRelationshipWithRelationshipProperties {
610+
611+
@Id @GeneratedValue
612+
private Long id;
613+
614+
@Relationship(type = "KNOWS", direction = Relationship.Direction.INCOMING)
615+
List<EntityWithBidirectionalRelationshipWithRelationshipPropertiesProperties> knownBy;
616+
617+
}
618+
619+
@RelationshipProperties
620+
static class OtherEntityWithBidirectionalRelationshipWithRelationshipPropertiesProperties {
621+
@Id @GeneratedValue
622+
private Long id;
623+
624+
@TargetNode
625+
OtherEntityWithBidirectionalRelationshipWithRelationshipProperties target;
626+
}
627+
628+
@RelationshipProperties
629+
static class EntityWithBidirectionalRelationshipWithRelationshipPropertiesProperties {
630+
@Id @GeneratedValue
631+
private Long id;
632+
633+
@TargetNode
634+
EntityWithBidirectionalRelationshipToOtherEntityWithRelationshipProperties target;
635+
}
636+
530637
@Node
531638
static class EntityWithBidirectionalRelationshipProperties {
532639

@@ -536,7 +643,7 @@ static class EntityWithBidirectionalRelationshipProperties {
536643
@Relationship("KNOWS")
537644
List<BidirectionalRelationshipProperties> knows;
538645

539-
@Relationship(type = "KNOWS" , direction = Relationship.Direction.INCOMING)
646+
@Relationship(type = "KNOWS", direction = Relationship.Direction.INCOMING)
540647
List<BidirectionalRelationshipProperties> knownBy;
541648

542649
}
@@ -551,4 +658,22 @@ static class BidirectionalRelationshipProperties {
551658
EntityWithBidirectionalRelationshipProperties target;
552659
}
553660

661+
@Node
662+
static class EntityLooksLikeHasObserve {
663+
@Id @GeneratedValue
664+
private Long id;
665+
666+
@Relationship("KNOWS")
667+
private List<OtherEntityLooksLikeHasObserve> knows;
668+
}
669+
670+
@Node
671+
static class OtherEntityLooksLikeHasObserve {
672+
@Id @GeneratedValue
673+
private Long id;
674+
675+
@Relationship("KNOWS")
676+
private List<EntityLooksLikeHasObserve> knows;
677+
}
678+
554679
}

0 commit comments

Comments
 (0)