Skip to content

Commit f841eb2

Browse files
committed
GH-2305 - Add test case.
1 parent 02a80c6 commit f841eb2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/test/java/org/springframework/data/neo4j/integration/imperative/RepositoryIT.java

+30
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,33 @@ void shouldFindOneToOneWithWildcardReturn(@Autowired OneToOneRepository reposito
12881288
List<OneToOneSource> oneToOnes = repository.findAllWithCustomQueryReturnStar();
12891289
assertOneToOneScenario(oneToOnes);
12901290
}
1291+
1292+
private void createOneToOneScenarioForNullValues() {
1293+
doWithSession(session -> {
1294+
try (Transaction tx = session.beginTransaction()) {
1295+
tx.run("CREATE (s:OneToOneSource {name: 's1'}) -[:OWNS]->(t:OneToOneTarget {name: 't1'})");
1296+
tx.run("CREATE (s:OneToOneSource {name: 's2'})");
1297+
tx.commit();
1298+
}
1299+
return null;
1300+
}
1301+
);
1302+
}
1303+
1304+
private void assertOneToOneScenarioWithNulls(List<OneToOneSource> oneToOnes) {
1305+
assertThat(oneToOnes).hasSize(2);
1306+
assertThat(oneToOnes).extracting(OneToOneSource::getName).containsExactlyInAnyOrder("s1", "s2");
1307+
assertThat(oneToOnes).filteredOn(s -> s.getTarget() != null)
1308+
.extracting(s -> s.getTarget().getName()).containsExactly("t1");
1309+
}
1310+
1311+
@Test // GH-2305
1312+
void shouldFindOneToOneWithNullValues(@Autowired OneToOneRepository repository) {
1313+
createOneToOneScenarioForNullValues();
1314+
1315+
List<OneToOneSource> oneToOnes = repository.findAllWithNullValues();
1316+
assertOneToOneScenarioWithNulls(oneToOnes);
1317+
}
12911318
}
12921319

12931320
@Nested
@@ -4118,6 +4145,9 @@ interface OneToOneRepository extends Neo4jRepository<OneToOneSource, String> {
41184145

41194146
@Query("MATCH (p1:#{#staticLabels})-[r:OWNS]-(p2) return *")
41204147
List<OneToOneSource> findAllWithCustomQueryReturnStar();
4148+
4149+
@Query("MATCH (p1:#{#staticLabels}) OPTIONAL MATCH (p1)-[r:OWNS]->(p2) return p1, r, p2")
4150+
List<OneToOneSource> findAllWithNullValues();
41214151
}
41224152

41234153
interface RelationshipRepository extends Neo4jRepository<PersonWithRelationship, Long> {

0 commit comments

Comments
 (0)