Skip to content

Commit

Permalink
refactor: Add a test for GH-2872.
Browse files Browse the repository at this point in the history
Closes #2872.
  • Loading branch information
michael-simons committed Mar 14, 2024
1 parent 99e9b55 commit 5f617e4
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
import org.springframework.data.neo4j.integration.issues.gh2819.GH2819Repository;
import org.springframework.data.neo4j.integration.issues.gh2858.GH2858;
import org.springframework.data.neo4j.integration.issues.gh2858.GH2858Repository;
import org.springframework.data.neo4j.integration.issues.gh2872.UserChangesRepository;
import org.springframework.data.neo4j.integration.issues.qbe.A;
import org.springframework.data.neo4j.integration.issues.qbe.ARepository;
import org.springframework.data.neo4j.integration.issues.qbe.B;
Expand Down Expand Up @@ -205,6 +206,7 @@ protected static void setupData(@Autowired BookmarkCapture bookmarkCapture) {
setupGH2459(transaction);
setupGH2572(transaction);
setupGH2583(transaction);
setupGH2872(transaction);

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

Expand All @@ -214,6 +216,21 @@ protected static void setupData(@Autowired BookmarkCapture bookmarkCapture) {
}
}

private static void setupGH2872(QueryRunner queryRunner) {
queryRunner.run("""
CREATE (p:`UserChanges`:`Gh2872Entity` {nodeId: randomUUID(), someField: -10}),
(c:`UserChanges`:`Gh2872Entity` {nodeId: randomUUID(), someField: 0}),
(n10:`UserChanges`:`Gh2872Entity` {nodeId: randomUUID(), someField: 10}),
(n20:`UserChanges`:`Gh2872Entity` {nodeId: randomUUID(), someField: 20}),
(p)-[:HAS_USER_CHANGES]->(c),
(c)-[:PREVIOUS_USER_CHANGE]->(p),
(c)-[:HAS_USER_CHANGES]->(n10),
(c)-[:HAS_USER_CHANGES]->(n20),
(n10)-[:PREVIOUS_USER_CHANGE]->(c),
(n20)-[:PREVIOUS_USER_CHANGE]->(c)
""").consume();
}

private static void setupGH2168(QueryRunner queryRunner) {
queryRunner.run("CREATE (:DomainObject{id: 'A'})").consume();
}
Expand Down Expand Up @@ -300,6 +317,29 @@ void qbeWithRelationship(@Autowired ARepository repository) {
assertThat(allResults).hasSize(1);
}


@Test
@Tag("GH-2872")
void findAllWithPossibleCircles(@Autowired UserChangesRepository userChangesRepository) {
var results = userChangesRepository.findAll();
assertThat(results).hasSize(4);
for (var result : results) {
var someField = result.getSomeField();
assertThat(someField).isNotNull();
if (someField.equals(0)) {
assertThat(result.getPrevious()).isNotNull();
assertThat(result.getPrevious().getSomeField()).isEqualTo(-10);
} else if (someField.equals(-10)) {
assertThat(result.getPrevious()).isNull();
assertThat(result.getUsers()).hasSize(1).first().matches(e -> e.getSomeField().equals(0));
} else {
assertThat(result.getPrevious()).isNotNull();
assertThat(result.getPrevious().getSomeField()).isEqualTo(0);
assertThat(result.getUsers()).isEmpty();
}
}
}

@Test
@Tag("GH-2168")
void findByIdShouldWork(@Autowired DomainObjectRepository domainObjectRepository) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2011-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.integration.issues.gh2872;

import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;

/**
* Test-reproducer.
*/
@Node("Gh2872Entity")
public class Gh2872Entity {

@Id
@GeneratedValue(GeneratedValue.UUIDGenerator.class)
protected String nodeId;

public String getNodeId() {
return nodeId;
}

public void setNodeId(String nodeId) {
this.nodeId = nodeId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2011-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.integration.issues.gh2872;

import java.util.List;

import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Relationship;

/**
* Test-reproducer.
*/
@Node("UserChanges")
public class Gh2872UserChangesEntity extends Gh2872Entity {

private Integer someField;

@Relationship(type = "HAS_USER_CHANGES")
private List<Gh2872UserChangesEntity> users;

@Relationship(type = "PREVIOUS_USER_CHANGE")
Gh2872UserChangesEntity previous;

public Integer getSomeField() {
return someField;
}

public void setSomeField(Integer someField) {
this.someField = someField;
}

public List<Gh2872UserChangesEntity> getUsers() {
return users;
}

public void setUsers(List<Gh2872UserChangesEntity> users) {
this.users = users;
}

public Gh2872UserChangesEntity getPrevious() {
return previous;
}

public void setPrevious(Gh2872UserChangesEntity previous) {
this.previous = previous;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2011-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.integration.issues.gh2872;

import org.springframework.data.neo4j.repository.Neo4jRepository;

/**
* Test-reproducer.
*/
public interface UserChangesRepository extends Neo4jRepository<Gh2872UserChangesEntity, String> {
}
2 changes: 1 addition & 1 deletion src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<logger name="OutboundMessageHandler" level="info"/>
<logger name="InboundMessageDispatcher" level="info"/>

<logger name="org.springframework.data.neo4j.cypher" level="info"/>
<logger name="org.springframework.data.neo4j.cypher" level="debug"/>
<logger name="org.springframework.data.neo4j.cypher.performance" level="error"/>
<logger name="org.springframework.data.neo4j.cypher.hint" level="error"/>
<logger name="org.springframework.data.neo4j.cypher.unrecognized" level="error"/>
Expand Down

0 comments on commit 5f617e4

Please sign in to comment.