From c2cbc473bf89c031d245ddcb054e257909634dcc Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Tue, 28 Jan 2025 12:26:06 +0100 Subject: [PATCH] refactor(test): Stabilize a couple of tests (especially the ones using _a_ shortest path). Signed-off-by: Michael Simons --- .../movies/imperative/AdvancedMappingIT.java | 13 +++++++++---- .../movies/reactive/ReactiveAdvancedMappingIT.java | 10 ++++++++-- .../reactive/ReactiveExceptionTranslationTest.java | 4 +++- .../neo4j/integration/shared/common/Person.java | 2 +- .../data/neo4j/test/Neo4jExtension.java | 10 ++++++++-- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/springframework/data/neo4j/integration/movies/imperative/AdvancedMappingIT.java b/src/test/java/org/springframework/data/neo4j/integration/movies/imperative/AdvancedMappingIT.java index c580223c9..4f5e3e9f7 100644 --- a/src/test/java/org/springframework/data/neo4j/integration/movies/imperative/AdvancedMappingIT.java +++ b/src/test/java/org/springframework/data/neo4j/integration/movies/imperative/AdvancedMappingIT.java @@ -298,8 +298,10 @@ class AdvancedMappingIT { void mappingOfAPathWithOddNumberOfElementsShouldWorkFromStartToEnd(@Autowired Neo4jTemplate template) { Map movies = template - .findAll( - "MATCH p=shortestPath((:Person {name: 'Mary Alice'})-[*]-(:Person {name: 'Emil Eifrem'})) RETURN p", + .findAll(""" + MATCH p=shortestPath((:Person {name: 'Mary Alice'})-[*]-(:Person {name: 'Emil Eifrem'})) + WHERE any(t IN [ x in nodes(p) | x.title] WHERE t = 'The Matrix Reloaded') + RETURN p""", Collections.emptyMap(), Movie.class) .stream().collect(Collectors.toMap(Movie::getTitle, Function.identity())); assertThat(movies).hasSize(3); @@ -317,8 +319,11 @@ class AdvancedMappingIT { void mappingOfAPathWithEventNumberOfElementsShouldWorkFromStartToEnd(@Autowired Neo4jTemplate template) { Map movies = template - .findAll( - "MATCH p=shortestPath((:Movie {title: 'The Matrix Revolutions'})-[*]-(:Person {name: 'Emil Eifrem'})) RETURN p", + .findAll(""" + MATCH p=shortestPath((:Movie {title: 'The Matrix Revolutions'})-[*]-(:Person {name: 'Emil Eifrem'})) + WHERE any(t IN [ x in nodes(p) | x.title] WHERE t = 'The Matrix Reloaded') + RETURN p + """, Collections.emptyMap(), Movie.class) .stream().collect(Collectors.toMap(Movie::getTitle, Function.identity())); assertThat(movies).hasSize(3); diff --git a/src/test/java/org/springframework/data/neo4j/integration/movies/reactive/ReactiveAdvancedMappingIT.java b/src/test/java/org/springframework/data/neo4j/integration/movies/reactive/ReactiveAdvancedMappingIT.java index 7164659cd..20e470197 100644 --- a/src/test/java/org/springframework/data/neo4j/integration/movies/reactive/ReactiveAdvancedMappingIT.java +++ b/src/test/java/org/springframework/data/neo4j/integration/movies/reactive/ReactiveAdvancedMappingIT.java @@ -258,7 +258,10 @@ class ReactiveAdvancedMappingIT { void mappingOfAPathWithOddNumberOfElementsShouldWorkFromStartToEnd(@Autowired ReactiveNeo4jTemplate template) { StepVerifier.create(template - .findAll("MATCH p=shortestPath((:Person {name: 'Mary Alice'})-[*]-(:Person {name: 'Emil Eifrem'})) RETURN p", Collections.emptyMap(), Movie.class)) + .findAll(""" + MATCH p=shortestPath((:Person {name: 'Mary Alice'})-[*]-(:Person {name: 'Emil Eifrem'})) + WHERE any(t IN [ x in nodes(p) | x.title] WHERE t = 'The Matrix Reloaded') + RETURN p""", Collections.emptyMap(), Movie.class)) .recordWith(ArrayList::new) .expectNextCount(3) .consumeRecordedWith(result -> { @@ -279,7 +282,10 @@ class ReactiveAdvancedMappingIT { void mappingOfAPathWithEventNumberOfElementsShouldWorkFromStartToEnd(@Autowired ReactiveNeo4jTemplate template) { StepVerifier.create(template - .findAll("MATCH p=shortestPath((:Movie {title: 'The Matrix Revolutions'})-[*]-(:Person {name: 'Emil Eifrem'})) RETURN p", Collections.emptyMap(), Movie.class)) + .findAll(""" + MATCH p=shortestPath((:Movie {title: 'The Matrix Revolutions'})-[*]-(:Person {name: 'Emil Eifrem'})) + WHERE any(t IN [ x in nodes(p) | x.title] WHERE t = 'The Matrix Reloaded') + RETURN p""", Collections.emptyMap(), Movie.class)) .recordWith(ArrayList::new) .expectNextCount(3) .consumeRecordedWith(result -> { diff --git a/src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveExceptionTranslationTest.java b/src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveExceptionTranslationTest.java index 11dfd7905..05f159a4d 100644 --- a/src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveExceptionTranslationTest.java +++ b/src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveExceptionTranslationTest.java @@ -72,7 +72,9 @@ class ReactiveExceptionTranslationTest { ex.getMessage().matches( "New data does not satisfy Constraint\\( id=\\d+, name='simple_person__unique_name', type='UNIQUENESS', schema=\\(:SimplePerson \\{name}\\), ownedIndex=\\d+ \\): Both node \\d+ and node -?\\d+ share the property value \\( String\\(\"Tom\"\\) \\); Error code 'Neo\\.ClientError\\.Schema\\.ConstraintValidationFailed'") || ex.getMessage().matches( - "New data does not satisfy Constraint\\( id=\\d+, name='simple_person__unique_name', type='UNIQUENESS', schema=\\(:SimplePerson \\{name}\\), ownedIndex=\\d+ \\): Node\\(\\d+\\) already exists with label `Label\\[\\d+]` and property `PropertyKey\\[\\d+]` = 'Tom'; Error code 'Neo\\.ClientError\\.Schema\\.ConstraintValidationFailed'") + "New data does not satisfy Constraint\\( id=\\d+, name='simple_person__unique_name', type='UNIQUENESS', schema=\\(:SimplePerson \\{name}\\), ownedIndex=\\d+ \\): Node\\(\\d+\\) already exists with label `Label\\[\\d+]` and property `PropertyKey\\[\\d+]` = 'Tom'; Error code 'Neo\\.ClientError\\.Schema\\.ConstraintValidationFailed'") || + ex.getMessage().matches( + "New data does not satisfy Constraint\\( id=\\d+, name='simple_person__unique_name', type='NODE PROPERTY UNIQUENESS', schema=\\(:SimplePerson \\{name}\\), ownedIndex=\\d+ \\): Node\\(\\d+\\) already exists with label `Label\\[\\d+]` and property `PropertyKey\\[\\d+]` = 'Tom'; Error code 'Neo\\.ClientError\\.Schema\\.ConstraintValidationFailed'") ); // @formatter:on diff --git a/src/test/java/org/springframework/data/neo4j/integration/shared/common/Person.java b/src/test/java/org/springframework/data/neo4j/integration/shared/common/Person.java index d2d619a03..4e22e1a2c 100644 --- a/src/test/java/org/springframework/data/neo4j/integration/shared/common/Person.java +++ b/src/test/java/org/springframework/data/neo4j/integration/shared/common/Person.java @@ -42,7 +42,7 @@ public class Person { */ @Node public static class Address { - @Id + @Id @GeneratedValue private Long id; private String zipCode; private String city; diff --git a/src/test/java/org/springframework/data/neo4j/test/Neo4jExtension.java b/src/test/java/org/springframework/data/neo4j/test/Neo4jExtension.java index 9d5a78752..cb33dfd09 100644 --- a/src/test/java/org/springframework/data/neo4j/test/Neo4jExtension.java +++ b/src/test/java/org/springframework/data/neo4j/test/Neo4jExtension.java @@ -258,11 +258,17 @@ public class Neo4jExtension implements BeforeAllCallback, BeforeEachCallback { synchronized (this) { serverVersion = this.cachedServerVersion; if (serverVersion == null) { + String versionString = ""; try (Session session = this.getDriver().session()) { Record result = session.run("CALL dbms.components() YIELD versions RETURN 'Neo4j/' + versions[0] as version").single(); - this.cachedServerVersion = ServerVersion.version(result.get("version").asString()); + versionString = result.get("version").asString(); + this.cachedServerVersion = ServerVersion.version(versionString); } catch (Exception e) { - throw new RuntimeException("Could not determine server version", e); + if (versionString.matches("Neo4j/20\\d{2}.+")) { + this.cachedServerVersion = ServerVersion.vInDev; + } else { + throw new RuntimeException("Could not determine server version", e); + } } serverVersion = this.cachedServerVersion; }