Skip to content

Commit df77679

Browse files
refactor(test): Stabilize a couple of tests (especially the ones using _a_ shortest path).
Signed-off-by: Michael Simons <[email protected]>
1 parent 20b2263 commit df77679

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

src/test/java/org/springframework/data/neo4j/integration/movies/imperative/AdvancedMappingIT.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,10 @@ void directionAndTypeLessPathMappingShouldWork(@Autowired Neo4jTemplate template
298298
void mappingOfAPathWithOddNumberOfElementsShouldWorkFromStartToEnd(@Autowired Neo4jTemplate template) {
299299

300300
Map<String, Movie> movies = template
301-
.findAll(
302-
"MATCH p=shortestPath((:Person {name: 'Mary Alice'})-[*]-(:Person {name: 'Emil Eifrem'})) RETURN p",
301+
.findAll("""
302+
MATCH p=shortestPath((:Person {name: 'Mary Alice'})-[*]-(:Person {name: 'Emil Eifrem'}))
303+
WHERE any(t IN [ x in nodes(p) | x.title] WHERE t = 'The Matrix Reloaded')
304+
RETURN p""",
303305
Collections.emptyMap(), Movie.class)
304306
.stream().collect(Collectors.toMap(Movie::getTitle, Function.identity()));
305307
assertThat(movies).hasSize(3);
@@ -317,8 +319,11 @@ void mappingOfAPathWithOddNumberOfElementsShouldWorkFromStartToEnd(@Autowired Ne
317319
void mappingOfAPathWithEventNumberOfElementsShouldWorkFromStartToEnd(@Autowired Neo4jTemplate template) {
318320

319321
Map<String, Movie> movies = template
320-
.findAll(
321-
"MATCH p=shortestPath((:Movie {title: 'The Matrix Revolutions'})-[*]-(:Person {name: 'Emil Eifrem'})) RETURN p",
322+
.findAll("""
323+
MATCH p=shortestPath((:Movie {title: 'The Matrix Revolutions'})-[*]-(:Person {name: 'Emil Eifrem'}))
324+
WHERE any(t IN [ x in nodes(p) | x.title] WHERE t = 'The Matrix Reloaded')
325+
RETURN p
326+
""",
322327
Collections.emptyMap(), Movie.class)
323328
.stream().collect(Collectors.toMap(Movie::getTitle, Function.identity()));
324329
assertThat(movies).hasSize(3);

src/test/java/org/springframework/data/neo4j/integration/movies/reactive/ReactiveAdvancedMappingIT.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ void directionAndTypeLessPathMappingShouldWork(@Autowired ReactiveNeo4jTemplate
258258
void mappingOfAPathWithOddNumberOfElementsShouldWorkFromStartToEnd(@Autowired ReactiveNeo4jTemplate template) {
259259

260260
StepVerifier.create(template
261-
.findAll("MATCH p=shortestPath((:Person {name: 'Mary Alice'})-[*]-(:Person {name: 'Emil Eifrem'})) RETURN p", Collections.emptyMap(), Movie.class))
261+
.findAll("""
262+
MATCH p=shortestPath((:Person {name: 'Mary Alice'})-[*]-(:Person {name: 'Emil Eifrem'}))
263+
WHERE any(t IN [ x in nodes(p) | x.title] WHERE t = 'The Matrix Reloaded')
264+
RETURN p""", Collections.emptyMap(), Movie.class))
262265
.recordWith(ArrayList::new)
263266
.expectNextCount(3)
264267
.consumeRecordedWith(result -> {
@@ -279,7 +282,10 @@ void mappingOfAPathWithOddNumberOfElementsShouldWorkFromStartToEnd(@Autowired Re
279282
void mappingOfAPathWithEventNumberOfElementsShouldWorkFromStartToEnd(@Autowired ReactiveNeo4jTemplate template) {
280283

281284
StepVerifier.create(template
282-
.findAll("MATCH p=shortestPath((:Movie {title: 'The Matrix Revolutions'})-[*]-(:Person {name: 'Emil Eifrem'})) RETURN p", Collections.emptyMap(), Movie.class))
285+
.findAll("""
286+
MATCH p=shortestPath((:Movie {title: 'The Matrix Revolutions'})-[*]-(:Person {name: 'Emil Eifrem'}))
287+
WHERE any(t IN [ x in nodes(p) | x.title] WHERE t = 'The Matrix Reloaded')
288+
RETURN p""", Collections.emptyMap(), Movie.class))
283289
.recordWith(ArrayList::new)
284290
.expectNextCount(3)
285291
.consumeRecordedWith(result -> {

src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveExceptionTranslationTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ class ReactiveExceptionTranslationTest {
7272
ex.getMessage().matches(
7373
"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'") ||
7474
ex.getMessage().matches(
75-
"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'")
75+
"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'") ||
76+
ex.getMessage().matches(
77+
"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'")
7678
);
7779
// @formatter:on
7880

src/test/java/org/springframework/data/neo4j/integration/shared/common/Person.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class Person {
4242
*/
4343
@Node
4444
public static class Address {
45-
@Id
45+
@Id @GeneratedValue
4646
private Long id;
4747
private String zipCode;
4848
private String city;

src/test/java/org/springframework/data/neo4j/test/Neo4jExtension.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,17 @@ public ServerVersion getServerVersion() {
258258
synchronized (this) {
259259
serverVersion = this.cachedServerVersion;
260260
if (serverVersion == null) {
261+
String versionString = "";
261262
try (Session session = this.getDriver().session()) {
262263
Record result = session.run("CALL dbms.components() YIELD versions RETURN 'Neo4j/' + versions[0] as version").single();
263-
this.cachedServerVersion = ServerVersion.version(result.get("version").asString());
264+
versionString = result.get("version").asString();
265+
this.cachedServerVersion = ServerVersion.version(versionString);
264266
} catch (Exception e) {
265-
throw new RuntimeException("Could not determine server version", e);
267+
if (versionString.matches("Neo4j/20\\d{2}.+")) {
268+
this.cachedServerVersion = ServerVersion.vInDev;
269+
} else {
270+
throw new RuntimeException("Could not determine server version", e);
271+
}
266272
}
267273
serverVersion = this.cachedServerVersion;
268274
}

0 commit comments

Comments
 (0)