Skip to content

Commit

Permalink
GH-952: Move test into separate surefire execution to fix Maven build.
Browse files Browse the repository at this point in the history
  • Loading branch information
nioertel committed Jul 26, 2023
1 parent 0543565 commit 0bbaf1a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 46 deletions.
26 changes: 26 additions & 0 deletions neo4j-ogm-tests/neo4j-ogm-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,17 @@
</configuration>

<executions>
<execution>
<id>default-test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>org.neo4j.ogm.persistence.session.capability.QueryCapabilityGH952Test</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>test-different-encoding</id>
<goals>
Expand All @@ -298,6 +309,21 @@
</includes>
</configuration>
</execution>
<execution>
<id>native-id-tests</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<!--
The tests for correct handling of overlapping native ids for nodes and relationships
(see GH-952) need to be executed on a clean Neo4j instance
-->
<includes>
<include>org.neo4j.ogm.persistence.session.capability.QueryCapabilityGH952Test</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import ch.qos.logback.classic.LoggerContext;

/**
* This test class is specifically for GH-952 because it requires special preparation magic that should be kept separate
* from other tests.
* This test class is specifically for GH-952 and needs to be executed separately within a clean JVM and new Neo4j
* instance so that native IDs are generated as expected.
*
* @author Niels Oertel
*/
Expand All @@ -64,47 +64,8 @@ public void init() throws IOException {
session.clear();
}

private long bringRelAndNodeIdsToSameLevel() {
long currentLargestNodeId = session.queryForObject(Long.class, ""//
+ "MERGE (n1:Dummy{i:0}) "//
+ "MERGE (n2:Dummy{i:1}) "//
+ "RETURN id(n2)", Collections.emptyMap());
long currentLargestRelId = session.queryForObject(Long.class, ""//
+ "MATCH (n1:Dummy{i:0}) "//
+ "MATCH (n2:Dummy{i:1}) "//
+ "MERGE (n1)-[r1:FOOBAR{i:0}]->(n2) "//
+ "RETURN id(r1)", Collections.emptyMap());

if (currentLargestNodeId == currentLargestRelId) {
return currentLargestNodeId + 1L;
} else if (currentLargestNodeId > currentLargestRelId) {
// need to create currentLargestNodeId - currentLargestRelId relationships
long numRelsToCreate = currentLargestNodeId - currentLargestRelId;
for (long i = 0; i < numRelsToCreate; ++i) {
session.queryForObject(Long.class, ""//
+ "MATCH (n1:Dummy{i:0}) "//
+ "MATCH (n2:Dummy{i:1}) "//
+ "MERGE (n1)-[r1:FOOBAR{i:$i}]->(n2) "//
+ "RETURN id(r1)", Collections.singletonMap("i", i + 1L));
}
return currentLargestNodeId + 1L;
} else {
// need to create currentLargestRelId - currentLargestNodeId nodes
long numNodesToCreate = currentLargestRelId - currentLargestNodeId;
for (long i = 0; i < numNodesToCreate; ++i) {
session.queryForObject(Long.class, ""//
+ "MERGE (n1:Dummy{uuid:'A',i:$i}) "//
+ "RETURN id(n1)", Collections.singletonMap("i", i + 2L));
}
return currentLargestRelId + 1L;
}
}

@Test // GH-952
public void shouldCorrectlyMapNodesAndRelsWithSameId() {
// prepare Neo4j by ensuring the next node and rel will get the same IDs
long nextId = bringRelAndNodeIdsToSameLevel();

// create test graph
session.query(""//
+ "MERGE (h1:Human{name:'Jane Doe', uuid:'AAAA0001'}) "//
Expand All @@ -115,12 +76,13 @@ public void shouldCorrectlyMapNodesAndRelsWithSameId() {
Collections.emptyMap());

// verify that we reached the expected setup
BDDAssertions.assertThat(session.queryForObject(Long.class, "MATCH (n{uuid:'AAAA0001'}) RETURN id(n)", Collections.emptyMap())).isEqualTo(nextId);
BDDAssertions.assertThat(session.queryForObject(Long.class, "MATCH (n{uuid:'AAAA0002'}) RETURN id(n)", Collections.emptyMap())).isEqualTo(nextId + 1L);
BDDAssertions.assertThat(session.queryForObject(Long.class, "MATCH (n{uuid:'AAAA0003'}) RETURN id(n)", Collections.emptyMap())).isEqualTo(nextId + 2L);
BDDAssertions.assertThat(session.queryForObject(Long.class, "MATCH ()-[r{uuid:'BBBB0001'}]->() RETURN id(r)", Collections.emptyMap())).isEqualTo(nextId);
BDDAssertions.assertThat(session.queryForObject(Long.class, "MATCH (n{uuid:'AAAA0001'}) RETURN id(n)", Collections.emptyMap())).isEqualTo(0L);
BDDAssertions.assertThat(session.queryForObject(Long.class, "MATCH (n{uuid:'AAAA0002'}) RETURN id(n)", Collections.emptyMap())).isEqualTo(1L);
BDDAssertions.assertThat(session.queryForObject(Long.class, "MATCH (n{uuid:'AAAA0003'}) RETURN id(n)", Collections.emptyMap())).isEqualTo(2L);
BDDAssertions.assertThat(session.queryForObject(Long.class, "MATCH ()-[r{uuid:'BBBB0001'}]->() RETURN id(r)", Collections.emptyMap()))
.isEqualTo(0L);
BDDAssertions.assertThat(session.queryForObject(Long.class, "MATCH ()-[r{uuid:'BBBB0002'}]->() RETURN id(r)", Collections.emptyMap()))
.isEqualTo(nextId + 1L);
.isEqualTo(1L);

// load the relationship entity between Moby-Dick and Jane Doe including the children of Jane
BDDAssertions.assertThat(//
Expand Down

0 comments on commit 0bbaf1a

Please sign in to comment.