|
189 | 189 | import org.springframework.data.neo4j.integration.issues.gh2918.ConditionRepository;
|
190 | 190 | import org.springframework.data.neo4j.integration.issues.gh2963.MyModel;
|
191 | 191 | import org.springframework.data.neo4j.integration.issues.gh2963.MyRepository;
|
| 192 | +import org.springframework.data.neo4j.integration.issues.gh2973.BaseNode; |
| 193 | +import org.springframework.data.neo4j.integration.issues.gh2973.BaseRelationship; |
| 194 | +import org.springframework.data.neo4j.integration.issues.gh2973.Gh2973Repository; |
| 195 | +import org.springframework.data.neo4j.integration.issues.gh2973.RelationshipA; |
| 196 | +import org.springframework.data.neo4j.integration.issues.gh2973.RelationshipB; |
| 197 | +import org.springframework.data.neo4j.integration.issues.gh2973.RelationshipC; |
| 198 | +import org.springframework.data.neo4j.integration.issues.gh2973.RelationshipD; |
192 | 199 | import org.springframework.data.neo4j.integration.issues.qbe.A;
|
193 | 200 | import org.springframework.data.neo4j.integration.issues.qbe.ARepository;
|
194 | 201 | import org.springframework.data.neo4j.integration.issues.qbe.B;
|
@@ -1698,6 +1705,72 @@ void customQueriesShouldKeepWorkingWithoutSpecifyingTheRelDirectionInTheirQuerie
|
1698 | 1705 | assertThat(rootModelFromDbCustom).map(MyModel::getMyNestedModel).isPresent();
|
1699 | 1706 | }
|
1700 | 1707 |
|
| 1708 | + @Tag("GH-2973") |
| 1709 | + @Test |
| 1710 | + void abstractedRelationshipTypesShouldBeMappedCorrectly(@Autowired Gh2973Repository gh2973Repository) { |
| 1711 | + var node = new BaseNode(); |
| 1712 | + var nodeFail = new BaseNode(); |
| 1713 | + RelationshipA a1 = new RelationshipA(); |
| 1714 | + RelationshipA a2 = new RelationshipA(); |
| 1715 | + RelationshipA a3 = new RelationshipA(); |
| 1716 | + RelationshipB b1 = new RelationshipB(); |
| 1717 | + RelationshipB b2 = new RelationshipB(); |
| 1718 | + RelationshipC c1 = new RelationshipC(); |
| 1719 | + RelationshipD d1 = new RelationshipD(); |
| 1720 | + |
| 1721 | + a1.setTargetNode(new BaseNode()); |
| 1722 | + a1.setA("a1"); |
| 1723 | + a2.setTargetNode(new BaseNode()); |
| 1724 | + a2.setA("a2"); |
| 1725 | + a3.setTargetNode(new BaseNode()); |
| 1726 | + a3.setA("a3"); |
| 1727 | + |
| 1728 | + b1.setTargetNode(new BaseNode()); |
| 1729 | + b1.setB("b1"); |
| 1730 | + b2.setTargetNode(new BaseNode()); |
| 1731 | + b2.setB("b2"); |
| 1732 | + |
| 1733 | + c1.setTargetNode(new BaseNode()); |
| 1734 | + c1.setC("c1"); |
| 1735 | + |
| 1736 | + d1.setTargetNode(new BaseNode()); |
| 1737 | + d1.setD("d1"); |
| 1738 | + |
| 1739 | + node.setRelationships(Map.of( |
| 1740 | + "a", List.of( |
| 1741 | + a1, a2, b2 |
| 1742 | + ), |
| 1743 | + "b", List.of( |
| 1744 | + b1, a3 |
| 1745 | + ) |
| 1746 | + )); |
| 1747 | + nodeFail.setRelationships(Map.of( |
| 1748 | + "c", List.of( |
| 1749 | + c1, d1 |
| 1750 | + ) |
| 1751 | + )); |
| 1752 | + var persistedNode = gh2973Repository.save(node); |
| 1753 | + var persistedNodeFail = gh2973Repository.save(nodeFail); |
| 1754 | + |
| 1755 | + // with type info, the relationships are of the correct type |
| 1756 | + var loadedNode = gh2973Repository.findById(persistedNode.getId()).get(); |
| 1757 | + List<BaseRelationship> relationshipsA = loadedNode.getRelationships().get("a"); |
| 1758 | + List<BaseRelationship> relationshipsB = loadedNode.getRelationships().get("b"); |
| 1759 | + assertThat(relationshipsA).satisfiesExactlyInAnyOrder( |
| 1760 | + r1 -> assertThat(r1).isOfAnyClassIn(RelationshipA.class), |
| 1761 | + r2 -> assertThat(r2).isOfAnyClassIn(RelationshipA.class), |
| 1762 | + r3 -> assertThat(r3).isOfAnyClassIn(RelationshipB.class) |
| 1763 | + ); |
| 1764 | + assertThat(relationshipsB).satisfiesExactlyInAnyOrder( |
| 1765 | + r1 -> assertThat(r1).isOfAnyClassIn(RelationshipA.class), |
| 1766 | + r2 -> assertThat(r2).isOfAnyClassIn(RelationshipB.class) |
| 1767 | + ); |
| 1768 | + // without type info, the relationships are all same type and not the base class BaseRelationship |
| 1769 | + var loadedNodeFail = gh2973Repository.findById(persistedNodeFail.getId()).get(); |
| 1770 | + List<BaseRelationship> relationshipsCFail = loadedNodeFail.getRelationships().get("c"); |
| 1771 | + assertThat(relationshipsCFail.get(0)).isNotExactlyInstanceOf(BaseRelationship.class); |
| 1772 | + } |
| 1773 | + |
1701 | 1774 | @Configuration
|
1702 | 1775 | @EnableTransactionManagement
|
1703 | 1776 | @EnableNeo4jRepositories(namedQueriesLocation = "more-custom-queries.properties")
|
@@ -1855,4 +1928,6 @@ private static EntitiesAndProjections.GH2533Entity createData(GH2533Repository r
|
1855 | 1928 |
|
1856 | 1929 | return repository.save(n1);
|
1857 | 1930 | }
|
| 1931 | + |
| 1932 | + |
1858 | 1933 | }
|
0 commit comments