refactor(test): Stabilize a couple of tests (especially the ones using _a_ shortest path).

Signed-off-by: Michael Simons <michael@simons.ac>
This commit is contained in:
Michael Simons
2025-01-28 12:26:06 +01:00
parent ee01516474
commit c2cbc473bf
5 changed files with 29 additions and 10 deletions

View File

@@ -298,8 +298,10 @@ class AdvancedMappingIT {
void mappingOfAPathWithOddNumberOfElementsShouldWorkFromStartToEnd(@Autowired Neo4jTemplate template) {
Map<String, Movie> 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<String, Movie> 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);

View File

@@ -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 -> {

View File

@@ -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

View File

@@ -42,7 +42,7 @@ public class Person {
*/
@Node
public static class Address {
@Id
@Id @GeneratedValue
private Long id;
private String zipCode;
private String city;

View File

@@ -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;
}