Skip to content
Permalink
Browse files
Modified ZPathImpl's "isParameter()" method to properly check for par…
…ameters strings (values inside of a pair parameter delimiters). This corrects issues with checking for path resolution status in certain cases.

Modified ZPathImpl's "resolved()" method to allow for substituted parameters to have leading path separators ("/"). This is useful in the case where a parameter is used for the first node element in the path, eliminating the need for the user to worry about the leading "/".

Added an additional unit test case for the leading "/" changes, and fixed bugs in the basic test cases that were accepting the wrong resolved state of tested ZPaths.

All unit tests for curator pass.
  • Loading branch information
Ryan0751 authored and randgalt committed Aug 18, 2021
1 parent 9aafdec commit 0128b96f4bc1766dc1fc37c70b0d98e72e50405f
Showing 3 changed files with 20 additions and 7 deletions.
@@ -31,6 +31,9 @@
*/
public interface ZPath extends Resolvable
{
String PARAMETER_OPENING_DELIMITER = "{";
String PARAMETER_CLOSING_DELIMITER = "}";

/**
* The root path: "/"
*/
@@ -52,7 +55,7 @@ static String parameter()
*/
static String parameter(String name)
{
return PATH_SEPARATOR + "{" + name + "}";
return PATH_SEPARATOR + PARAMETER_OPENING_DELIMITER + name + PARAMETER_CLOSING_DELIMITER;
}

/**
@@ -241,7 +244,7 @@ default ZPath resolved(Object... parameters)
boolean isRoot();

/**
* Return true if this path is fully resolved (i.e. has no unresoled parameters)
* Return true if this path is fully resolved (i.e. has no unresolved parameters)
*
* @return true/false
*/
@@ -210,7 +210,9 @@ public ZPath resolved(List<Object> parameters)
.map(name -> {
if ( isParameter(name) && iterator.hasNext() )
{
return NodeName.nameFrom(iterator.next());
// Eliminate any leading path separator from substituted parameters, as ZPathImpl() will
// add in all required path separators as part of it's build operation.
return NodeName.nameFrom(iterator.next()).replaceAll(String.format("^%s+", PATH_SEPARATOR), "");
}
return name;
})
@@ -226,7 +228,8 @@ public boolean isResolved()

private static boolean isParameter(String name)
{
return (name.length() > 1) && name.startsWith(PATH_SEPARATOR);
return name.matches(String.format(".*\\%s.*\\%s", PARAMETER_OPENING_DELIMITER,
PARAMETER_CLOSING_DELIMITER));
}

private ZPathImpl(List<String> nodes, String child)
@@ -57,11 +57,11 @@ public void testBasic()
assertFalse(path.startsWith(ZPath.root.child("two")));

ZPath checkIdLike = ZPath.parse("/one/{two}/three");
assertTrue(checkIdLike.isResolved());
assertFalse(checkIdLike.isResolved());
checkIdLike = ZPath.parse("/one/" + ZPath.parameter() + "/three");
assertTrue(checkIdLike.isResolved());
assertFalse(checkIdLike.isResolved());
checkIdLike = ZPath.parse("/one/" + ZPath.parameter("others") + "/three");
assertTrue(checkIdLike.isResolved());
assertFalse(checkIdLike.isResolved());
}

@Test
@@ -71,6 +71,13 @@ public void testParsing()
assertEquals(ZPath.parse("/one/two/three"), ZPath.root.child("one").child("two").child("three"));
assertEquals(ZPath.parse("/one/two/three"), ZPath.from("one", "two", "three"));
assertEquals(ZPath.parseWithIds("/one/{id}/two/{id}"), ZPath.from("one", parameter(), "two", parameter()));

final ZPath rootPath = ZPath.parse("/root");
ZPath path = ZPath.parseWithIds("{root}/one/{id}/two/{id}");
assertFalse(path.isResolved());
path = path.resolved(rootPath.toString(), "foo", "bar");
assertEquals(ZPath.from("root", "one", "foo", "two", "bar").toString(), path.toString());
assertTrue(path.isResolved());
}

@Test

0 comments on commit 0128b96

Please sign in to comment.