Skip to content

Commit 5f617e4

Browse files
refactor: Add a test for GH-2872.
Closes #2872.
1 parent 99e9b55 commit 5f617e4

File tree

5 files changed

+164
-1
lines changed

5 files changed

+164
-1
lines changed

src/test/java/org/springframework/data/neo4j/integration/issues/IssuesIT.java

+40
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
import org.springframework.data.neo4j.integration.issues.gh2819.GH2819Repository;
148148
import org.springframework.data.neo4j.integration.issues.gh2858.GH2858;
149149
import org.springframework.data.neo4j.integration.issues.gh2858.GH2858Repository;
150+
import org.springframework.data.neo4j.integration.issues.gh2872.UserChangesRepository;
150151
import org.springframework.data.neo4j.integration.issues.qbe.A;
151152
import org.springframework.data.neo4j.integration.issues.qbe.ARepository;
152153
import org.springframework.data.neo4j.integration.issues.qbe.B;
@@ -205,6 +206,7 @@ protected static void setupData(@Autowired BookmarkCapture bookmarkCapture) {
205206
setupGH2459(transaction);
206207
setupGH2572(transaction);
207208
setupGH2583(transaction);
209+
setupGH2872(transaction);
208210

209211
transaction.run("CREATE (:A {name: 'A name', id: randomUUID()}) -[:HAS] ->(:B {anotherName: 'Whatever', id: randomUUID()})");
210212

@@ -214,6 +216,21 @@ protected static void setupData(@Autowired BookmarkCapture bookmarkCapture) {
214216
}
215217
}
216218

219+
private static void setupGH2872(QueryRunner queryRunner) {
220+
queryRunner.run("""
221+
CREATE (p:`UserChanges`:`Gh2872Entity` {nodeId: randomUUID(), someField: -10}),
222+
(c:`UserChanges`:`Gh2872Entity` {nodeId: randomUUID(), someField: 0}),
223+
(n10:`UserChanges`:`Gh2872Entity` {nodeId: randomUUID(), someField: 10}),
224+
(n20:`UserChanges`:`Gh2872Entity` {nodeId: randomUUID(), someField: 20}),
225+
(p)-[:HAS_USER_CHANGES]->(c),
226+
(c)-[:PREVIOUS_USER_CHANGE]->(p),
227+
(c)-[:HAS_USER_CHANGES]->(n10),
228+
(c)-[:HAS_USER_CHANGES]->(n20),
229+
(n10)-[:PREVIOUS_USER_CHANGE]->(c),
230+
(n20)-[:PREVIOUS_USER_CHANGE]->(c)
231+
""").consume();
232+
}
233+
217234
private static void setupGH2168(QueryRunner queryRunner) {
218235
queryRunner.run("CREATE (:DomainObject{id: 'A'})").consume();
219236
}
@@ -300,6 +317,29 @@ void qbeWithRelationship(@Autowired ARepository repository) {
300317
assertThat(allResults).hasSize(1);
301318
}
302319

320+
321+
@Test
322+
@Tag("GH-2872")
323+
void findAllWithPossibleCircles(@Autowired UserChangesRepository userChangesRepository) {
324+
var results = userChangesRepository.findAll();
325+
assertThat(results).hasSize(4);
326+
for (var result : results) {
327+
var someField = result.getSomeField();
328+
assertThat(someField).isNotNull();
329+
if (someField.equals(0)) {
330+
assertThat(result.getPrevious()).isNotNull();
331+
assertThat(result.getPrevious().getSomeField()).isEqualTo(-10);
332+
} else if (someField.equals(-10)) {
333+
assertThat(result.getPrevious()).isNull();
334+
assertThat(result.getUsers()).hasSize(1).first().matches(e -> e.getSomeField().equals(0));
335+
} else {
336+
assertThat(result.getPrevious()).isNotNull();
337+
assertThat(result.getPrevious().getSomeField()).isEqualTo(0);
338+
assertThat(result.getUsers()).isEmpty();
339+
}
340+
}
341+
}
342+
303343
@Test
304344
@Tag("GH-2168")
305345
void findByIdShouldWork(@Autowired DomainObjectRepository domainObjectRepository) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2011-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.gh2872;
17+
18+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
19+
import org.springframework.data.neo4j.core.schema.Id;
20+
import org.springframework.data.neo4j.core.schema.Node;
21+
22+
/**
23+
* Test-reproducer.
24+
*/
25+
@Node("Gh2872Entity")
26+
public class Gh2872Entity {
27+
28+
@Id
29+
@GeneratedValue(GeneratedValue.UUIDGenerator.class)
30+
protected String nodeId;
31+
32+
public String getNodeId() {
33+
return nodeId;
34+
}
35+
36+
public void setNodeId(String nodeId) {
37+
this.nodeId = nodeId;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2011-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.gh2872;
17+
18+
import java.util.List;
19+
20+
import org.springframework.data.neo4j.core.schema.Node;
21+
import org.springframework.data.neo4j.core.schema.Relationship;
22+
23+
/**
24+
* Test-reproducer.
25+
*/
26+
@Node("UserChanges")
27+
public class Gh2872UserChangesEntity extends Gh2872Entity {
28+
29+
private Integer someField;
30+
31+
@Relationship(type = "HAS_USER_CHANGES")
32+
private List<Gh2872UserChangesEntity> users;
33+
34+
@Relationship(type = "PREVIOUS_USER_CHANGE")
35+
Gh2872UserChangesEntity previous;
36+
37+
public Integer getSomeField() {
38+
return someField;
39+
}
40+
41+
public void setSomeField(Integer someField) {
42+
this.someField = someField;
43+
}
44+
45+
public List<Gh2872UserChangesEntity> getUsers() {
46+
return users;
47+
}
48+
49+
public void setUsers(List<Gh2872UserChangesEntity> users) {
50+
this.users = users;
51+
}
52+
53+
public Gh2872UserChangesEntity getPrevious() {
54+
return previous;
55+
}
56+
57+
public void setPrevious(Gh2872UserChangesEntity previous) {
58+
this.previous = previous;
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2011-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.gh2872;
17+
18+
import org.springframework.data.neo4j.repository.Neo4jRepository;
19+
20+
/**
21+
* Test-reproducer.
22+
*/
23+
public interface UserChangesRepository extends Neo4jRepository<Gh2872UserChangesEntity, String> {
24+
}

src/test/resources/logback-test.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<logger name="OutboundMessageHandler" level="info"/>
3030
<logger name="InboundMessageDispatcher" level="info"/>
3131

32-
<logger name="org.springframework.data.neo4j.cypher" level="info"/>
32+
<logger name="org.springframework.data.neo4j.cypher" level="debug"/>
3333
<logger name="org.springframework.data.neo4j.cypher.performance" level="error"/>
3434
<logger name="org.springframework.data.neo4j.cypher.hint" level="error"/>
3535
<logger name="org.springframework.data.neo4j.cypher.unrecognized" level="error"/>

0 commit comments

Comments
 (0)