From 91584356b34284a7cbacccc44a14153f59719d7b Mon Sep 17 00:00:00 2001 From: Gemma Lamont Date: Thu, 5 Dec 2024 09:00:29 +0100 Subject: [PATCH] Error on typos for uniqueness --- core/src/main/java/apoc/path/PathExplorer.java | 8 +++++++- .../src/test/java/apoc/path/ExpandPathTest.java | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/apoc/path/PathExplorer.java b/core/src/main/java/apoc/path/PathExplorer.java index c44ebca9c..b01a76ba7 100644 --- a/core/src/main/java/apoc/path/PathExplorer.java +++ b/core/src/main/java/apoc/path/PathExplorer.java @@ -282,7 +282,13 @@ private Uniqueness getUniqueness(String uniqueness) { for (Uniqueness u : Uniqueness.values()) { if (u.name().equalsIgnoreCase(uniqueness)) return u; } - return UNIQUENESS; + throw new RuntimeException("Invalid uniqueness: '" + uniqueness + "'. Must be one of: " + + String.join( + ", ", + java.util.Arrays.stream(Uniqueness.values()) + .map(Enum::name) + .toArray(String[]::new)) + + "."); } private Stream expandConfigPrivate(@Name("start") Object start, @Name("config") Map config) { diff --git a/core/src/test/java/apoc/path/ExpandPathTest.java b/core/src/test/java/apoc/path/ExpandPathTest.java index c1b4602b0..9c8b635ae 100644 --- a/core/src/test/java/apoc/path/ExpandPathTest.java +++ b/core/src/test/java/apoc/path/ExpandPathTest.java @@ -21,6 +21,7 @@ import static apoc.util.Util.labelStrings; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import apoc.util.MapUtil; @@ -696,6 +697,22 @@ public void testLabelWithTwoDots() { }); } + @Test + public void testShouldFailOnInvalidUniqueness() { + String statement = + """ + MATCH (k:Person {name:'Keanu Reeves'}) + CALL apoc.path.expandConfig(k, {uniqueness: 'NODE_GLOBALS'}) + YIELD path + RETURN path + """; + + RuntimeException e = assertThrows(RuntimeException.class, () -> TestUtil.testCall(db, statement, (res) -> {})); + String expectedMessage = + "Failed to invoke procedure `apoc.path.expandConfig`: Caused by: java.lang.RuntimeException: Invalid uniqueness: 'NODE_GLOBALS'. Must be one of: NODE_GLOBAL, NODE_PATH, NODE_RECENT, NODE_LEVEL, RELATIONSHIP_GLOBAL, RELATIONSHIP_PATH, RELATIONSHIP_RECENT, RELATIONSHIP_LEVEL, NONE."; + assertEquals(expectedMessage, e.getMessage()); + } + private void specialCharAssertions(Result result) { Map row = result.next(); assertSinglePath(row);