You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2024/06/20 14:09:17 UTC
(jackrabbit-oak) branch 1.22 updated (389f7dbe83 -> b89ad4c972)
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a change to branch 1.22
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
from 389f7dbe83 OAK-10708: error-level log failures to write the journal (#1363)
new bbc679871f OAK-10596: Improve the test coverage of o.a.j.o.namepath.JcrPathParser
new f4ad87fc62 OAK-10596: Improve the test coverage of o.a.j.o.namepath.JcrPathParser
new 81190e4b4c OAK-10596: Improve the test coverage of o.a.j.o.namepath.JcrPathParser
new b89ad4c972 OAK-10596: Improve the test coverage of o.a.j.o.namepath.JcrPathParser
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../jackrabbit/oak/namepath/PathParserTest.java | 376 +++++++++++++++++++++
1 file changed, 376 insertions(+)
create mode 100755 oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
(jackrabbit-oak) 03/04: OAK-10596: Improve the test coverage of o.a.j.o.namepath.JcrPathParser
Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch 1.22
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 81190e4b4c276226fc02fdc0411da5f273821e1d
Author: Manfred Baedke <ma...@gmail.com>
AuthorDate: Fri Jan 19 13:35:49 2024 +0100
OAK-10596: Improve the test coverage of o.a.j.o.namepath.JcrPathParser
Improved test cases
---
.../jackrabbit/oak/namepath/PathParserTest.java | 73 ++++------------------
1 file changed, 11 insertions(+), 62 deletions(-)
diff --git a/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java b/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
index 679b1dfa34..ddafaaf1d5 100755
--- a/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
+++ b/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
@@ -188,10 +188,9 @@ public class PathParserTest {
@Test
@Ignore //OAK-10611
public void testUnexpectedOpeningSquareBracket() throws RepositoryException {
- //TODO check for specific error messages
String path = "[";
TestListener listener = new TestListener(
- CALLBACKRESULT_ERROR_ANY
+ CALLBACKRESULT_ERROR("'[' not allowed in name")
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -200,7 +199,7 @@ public class PathParserTest {
path = "/[";
listener = new TestListener(
CALLBACKRESULT_ROOT,
- CALLBACKRESULT_ERROR_ANY
+ CALLBACKRESULT_ERROR("'[' not allowed in name")
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -209,7 +208,7 @@ public class PathParserTest {
path = "./[";
listener = new TestListener(
CALLBACKRESULT_CURRENT,
- CALLBACKRESULT_ERROR_ANY
+ CALLBACKRESULT_ERROR("'[' not allowed in name")
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -218,7 +217,7 @@ public class PathParserTest {
path = "../[";
listener = new TestListener(
CALLBACKRESULT_PARENT,
- CALLBACKRESULT_ERROR_ANY
+ CALLBACKRESULT_ERROR("'[' not allowed in name")
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -226,7 +225,7 @@ public class PathParserTest {
path = ".[";
listener = new TestListener(
- CALLBACKRESULT_ERROR_ANY
+ CALLBACKRESULT_ERROR("'[' not allowed in name")
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -234,7 +233,7 @@ public class PathParserTest {
path = "..[";
listener = new TestListener(
- CALLBACKRESULT_ERROR_ANY
+ CALLBACKRESULT_ERROR("'[' not allowed in name")
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -242,7 +241,7 @@ public class PathParserTest {
path = "{[";
listener = new TestListener(
- CALLBACKRESULT_ERROR_ANY
+ CALLBACKRESULT_ERROR("'{[' is not a valid path. Missing '}'.")
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -250,7 +249,7 @@ public class PathParserTest {
path = "a[[";
listener = new TestListener(
- CALLBACKRESULT_ERROR_ANY
+ CALLBACKRESULT_ERROR("'[' not allowed in name")
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -260,61 +259,11 @@ public class PathParserTest {
@Test
@Ignore //OAK-10611
public void testMissingClosingSquareBracket() throws RepositoryException {
- //TODO check for specific error messages
- String path = "[";
+ String path = "/a[";
TestListener listener = new TestListener(
- CALLBACKRESULT_ERROR_ANY
- );
- assertFalse(JcrPathParser.validate(path));
- assertFalse(JcrPathParser.parse(path, listener));
- listener.evaluate();
-
- path = "/[";
- listener = new TestListener(
CALLBACKRESULT_ROOT,
- CALLBACKRESULT_ERROR_ANY
- );
- assertFalse(JcrPathParser.validate(path));
- assertFalse(JcrPathParser.parse(path, listener));
- listener.evaluate();
-
- path = "./[";
- listener = new TestListener(
- CALLBACKRESULT_CURRENT,
- CALLBACKRESULT_ERROR_ANY
- );
- assertFalse(JcrPathParser.validate(path));
- assertFalse(JcrPathParser.parse(path, listener));
- listener.evaluate();
-
- path = "../[";
- listener = new TestListener(
- CALLBACKRESULT_PARENT,
- CALLBACKRESULT_ERROR_ANY
- );
- assertFalse(JcrPathParser.validate(path));
- assertFalse(JcrPathParser.parse(path, listener));
- listener.evaluate();
-
- path = ".[";
- listener = new TestListener(
- CALLBACKRESULT_ERROR_ANY
- );
- assertFalse(JcrPathParser.validate(path));
- assertFalse(JcrPathParser.parse(path, listener));
- listener.evaluate();
-
- path = "..[";
- listener = new TestListener(
- CALLBACKRESULT_ERROR_ANY
- );
- assertFalse(JcrPathParser.validate(path));
- assertFalse(JcrPathParser.parse(path, listener));
- listener.evaluate();
-
- path = "{[";
- listener = new TestListener(
- CALLBACKRESULT_ERROR_ANY
+ //the parser actually produces an error, but we should change the error message to something like this
+ CALLBACKRESULT_ERROR("'/a[' is not a valid path. ']' expected after index.")
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
(jackrabbit-oak) 01/04: OAK-10596: Improve the test coverage of o.a.j.o.namepath.JcrPathParser
Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch 1.22
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit bbc679871fe8d22cfded688da588990b4a77d160
Author: Manfred Baedke <ma...@gmail.com>
AuthorDate: Thu Jan 18 12:35:46 2024 +0100
OAK-10596: Improve the test coverage of o.a.j.o.namepath.JcrPathParser
New test class with some initial unit tests.
---
.../jackrabbit/oak/namepath/PathParserTest.java | 307 +++++++++++++++++++++
1 file changed, 307 insertions(+)
diff --git a/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java b/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
new file mode 100755
index 0000000000..da2fc92015
--- /dev/null
+++ b/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
@@ -0,0 +1,307 @@
+package org.apache.jackrabbit.oak.namepath;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import javax.jcr.RepositoryException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class PathParserTest {
+
+ private enum ParserCallbackResultType {
+
+ CALLBACK_ROOT,
+ CALLBACK_CURRENT,
+ CALLBACK_PARENT,
+ CALLBACK_NAME,
+ CALLBACK_ERROR;
+ }
+
+ private static class ParserCallbackResult {
+
+ private final ParserCallbackResultType type;
+ private final String data;
+ private final int index;
+
+ ParserCallbackResult(ParserCallbackResultType type, String data, int index) {
+ this.type = type;
+ this.data = data;
+ this.index = index;
+ }
+
+ ParserCallbackResultType getType() {
+ return type;
+ }
+
+ String getData() {
+ return data;
+ }
+
+ int getIndex() {
+ return index;
+ }
+
+ @Override
+ public int hashCode() {
+ if (type == ParserCallbackResultType.CALLBACK_NAME) {
+ return data == null? 0 : data.hashCode();
+ }
+ if (type == ParserCallbackResultType.CALLBACK_ERROR) {
+ return data == null? 0 : data.hashCode();
+ }
+ return type.ordinal();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof ParserCallbackResult) {
+ ParserCallbackResult result = (ParserCallbackResult) obj;
+ if (result.getType() == getType()) {
+ return result.getData() == null || data == null || (result.getData().equals(data) && result.getIndex() == index);
+ }
+ }
+ return false;
+ }
+ }
+
+ private static final ParserCallbackResult CALLBACKRESULT_ROOT = new ParserCallbackResult(ParserCallbackResultType.CALLBACK_ROOT, null, 0);
+ private static final ParserCallbackResult CALLBACKRESULT_CURRENT = new ParserCallbackResult(ParserCallbackResultType.CALLBACK_CURRENT, null, 0);
+ private static final ParserCallbackResult CALLBACKRESULT_PARENT = new ParserCallbackResult(ParserCallbackResultType.CALLBACK_PARENT, null, 0);
+ private static final ParserCallbackResult CALLBACKRESULT_ERROR_ANY = new ParserCallbackResult(ParserCallbackResultType.CALLBACK_ERROR, null, 0);
+ private static final ParserCallbackResult CALLBACKRESULT_NAME_ANY = new ParserCallbackResult(ParserCallbackResultType.CALLBACK_NAME, null, 0);
+
+ private static ParserCallbackResult CALLBACKRESULT_NAME(String name) {
+ return new ParserCallbackResult(ParserCallbackResultType.CALLBACK_NAME, name, 0);
+ }
+
+ private static ParserCallbackResult CALLBACKRESULT_NAME(String name, int index) {
+ return new ParserCallbackResult(ParserCallbackResultType.CALLBACK_NAME, name, index);
+ }
+
+ private static ParserCallbackResult CALLBACKRESULT_ERROR(String error) {
+ return new ParserCallbackResult(ParserCallbackResultType.CALLBACK_ERROR, error, 0);
+ }
+
+ private static class TestListener implements JcrPathParser.Listener {
+
+ private List<ParserCallbackResult> expectedCallbackResults;
+ private List<ParserCallbackResult> callbackResults = new ArrayList<>();
+
+ TestListener(ParserCallbackResult ... expectedCallbackResult) {
+ this.expectedCallbackResults = Arrays.stream(expectedCallbackResult).collect(Collectors.toList());
+ }
+
+ @Override
+ public boolean name(String name, int index) {
+ callbackResults.add(CALLBACKRESULT_NAME(name, index));
+ return true;
+ }
+
+ @Override
+ public boolean root() {
+ callbackResults.add(CALLBACKRESULT_ROOT);
+ return true;
+ }
+
+ @Override
+ public boolean current() {
+ callbackResults.add(CALLBACKRESULT_CURRENT);
+ return true;
+ }
+
+ @Override
+ public boolean parent() {
+ callbackResults.add(CALLBACKRESULT_PARENT);
+ return true;
+ }
+
+ @Override
+ public void error(String message) {
+ callbackResults.add(CALLBACKRESULT_ERROR(message));
+ }
+
+ public void evaluate() {
+ assertArrayEquals("Parser produced an unexpected sequence of callbacks", expectedCallbackResults.toArray(), callbackResults.toArray());
+ }
+
+ public void reset() {
+ callbackResults.clear();
+ }
+ }
+
+ @Test
+ public void testSampleTestTemplate() {
+ String path = "/a/b/./../c[1]/]";
+ TestListener listener = new TestListener(
+ CALLBACKRESULT_ROOT,
+ CALLBACKRESULT_NAME("a"),
+ CALLBACKRESULT_NAME("b"),
+ CALLBACKRESULT_CURRENT,
+ CALLBACKRESULT_PARENT,
+ CALLBACKRESULT_NAME("c", 1),
+ CALLBACKRESULT_ERROR("'" + path + "' is not a valid path. ']' not a valid name character.")
+ );
+
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+ }
+
+ @Test
+ public void testEmptyPath() {
+ TestListener listener = new TestListener();
+
+ assertTrue(JcrPathParser.validate(null));
+ assertTrue(JcrPathParser.parse(null, listener));
+ listener.evaluate();
+
+ assertTrue(JcrPathParser.validate(""));
+ assertTrue(JcrPathParser.parse("", listener));
+ listener.evaluate();
+ }
+
+ //TODO add more tests to cover all edge cases
+
+ @Test
+ @Ignore //OAK-10611
+ public void testUnexpectedOpeningSquareBracket() throws RepositoryException {
+ //TODO check for specific error messages
+ String path = "[";
+ TestListener listener = new TestListener(
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "/[";
+ listener = new TestListener(
+ CALLBACKRESULT_ROOT,
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "./[";
+ listener = new TestListener(
+ CALLBACKRESULT_CURRENT,
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "../[";
+ listener = new TestListener(
+ CALLBACKRESULT_PARENT,
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = ".[";
+ listener = new TestListener(
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "..[";
+ listener = new TestListener(
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "{[";
+ listener = new TestListener(
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "a[[";
+ listener = new TestListener(
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+ }
+
+ @Test
+ @Ignore //OAK-10611
+ public void testMissingClosingSquareBracket() throws RepositoryException {
+ //TODO check for specific error messages
+ String path = "[";
+ TestListener listener = new TestListener(
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "/[";
+ listener = new TestListener(
+ CALLBACKRESULT_ROOT,
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "./[";
+ listener = new TestListener(
+ CALLBACKRESULT_CURRENT,
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "../[";
+ listener = new TestListener(
+ CALLBACKRESULT_PARENT,
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = ".[";
+ listener = new TestListener(
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "..[";
+ listener = new TestListener(
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "{[";
+ listener = new TestListener(
+ CALLBACKRESULT_ERROR_ANY
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+ }
+}
(jackrabbit-oak) 02/04: OAK-10596: Improve the test coverage of o.a.j.o.namepath.JcrPathParser
Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch 1.22
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit f4ad87fc62fc9ee6b757d65626def02b3f39886a
Author: Manfred Baedke <ma...@gmail.com>
AuthorDate: Thu Jan 18 12:47:16 2024 +0100
OAK-10596: Improve the test coverage of o.a.j.o.namepath.JcrPathParser
Added missing license header
---
.../apache/jackrabbit/oak/namepath/PathParserTest.java | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java b/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
index da2fc92015..679b1dfa34 100755
--- a/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
+++ b/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.jackrabbit.oak.namepath;
import org.junit.Ignore;
(jackrabbit-oak) 04/04: OAK-10596: Improve the test coverage of o.a.j.o.namepath.JcrPathParser
Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch 1.22
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit b89ad4c9727227b411beb3dc7a21770edf37722f
Author: Manfred Baedke <ma...@gmail.com>
AuthorDate: Fri Jan 19 14:22:10 2024 +0100
OAK-10596: Improve the test coverage of o.a.j.o.namepath.JcrPathParser
Added and improved test cases
---
.../jackrabbit/oak/namepath/PathParserTest.java | 124 +++++++++++++++++++--
1 file changed, 114 insertions(+), 10 deletions(-)
diff --git a/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java b/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
index ddafaaf1d5..46fcdaea5e 100755
--- a/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
+++ b/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/namepath/PathParserTest.java
@@ -85,6 +85,11 @@ public class PathParserTest {
}
return false;
}
+
+ @Override
+ public String toString() {
+ return data == null ? "null" : data;
+ }
}
private static final ParserCallbackResult CALLBACKRESULT_ROOT = new ParserCallbackResult(ParserCallbackResultType.CALLBACK_ROOT, null, 0);
@@ -190,7 +195,7 @@ public class PathParserTest {
public void testUnexpectedOpeningSquareBracket() throws RepositoryException {
String path = "[";
TestListener listener = new TestListener(
- CALLBACKRESULT_ERROR("'[' not allowed in name")
+ CALLBACKRESULT_ERROR(errorCharacterNotAllowedInName('['))
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -199,7 +204,7 @@ public class PathParserTest {
path = "/[";
listener = new TestListener(
CALLBACKRESULT_ROOT,
- CALLBACKRESULT_ERROR("'[' not allowed in name")
+ CALLBACKRESULT_ERROR(errorCharacterNotAllowedInName('['))
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -208,7 +213,7 @@ public class PathParserTest {
path = "./[";
listener = new TestListener(
CALLBACKRESULT_CURRENT,
- CALLBACKRESULT_ERROR("'[' not allowed in name")
+ CALLBACKRESULT_ERROR(errorCharacterNotAllowedInName('['))
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -217,7 +222,7 @@ public class PathParserTest {
path = "../[";
listener = new TestListener(
CALLBACKRESULT_PARENT,
- CALLBACKRESULT_ERROR("'[' not allowed in name")
+ CALLBACKRESULT_ERROR(errorCharacterNotAllowedInName('['))
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -225,7 +230,7 @@ public class PathParserTest {
path = ".[";
listener = new TestListener(
- CALLBACKRESULT_ERROR("'[' not allowed in name")
+ CALLBACKRESULT_ERROR(errorCharacterNotAllowedInName('['))
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -233,15 +238,15 @@ public class PathParserTest {
path = "..[";
listener = new TestListener(
- CALLBACKRESULT_ERROR("'[' not allowed in name")
+ CALLBACKRESULT_ERROR(errorCharacterNotAllowedInName('['))
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
listener.evaluate();
- path = "{[";
+ path = "{[}";
listener = new TestListener(
- CALLBACKRESULT_ERROR("'{[' is not a valid path. Missing '}'.")
+ CALLBACKRESULT_ERROR(errorCharacterNotAllowedInName('['))
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -249,7 +254,8 @@ public class PathParserTest {
path = "a[[";
listener = new TestListener(
- CALLBACKRESULT_ERROR("'[' not allowed in name")
+ //the parser actually produces an error, but we should change the error message to something like this
+ CALLBACKRESULT_ERROR(errorClosingQuareBracketExpected(path))
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
@@ -263,10 +269,108 @@ public class PathParserTest {
TestListener listener = new TestListener(
CALLBACKRESULT_ROOT,
//the parser actually produces an error, but we should change the error message to something like this
- CALLBACKRESULT_ERROR("'/a[' is not a valid path. ']' expected after index.")
+ CALLBACKRESULT_ERROR(errorClosingQuareBracketExpected(path))
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+ }
+
+ @Test
+ public void testUnxepectedClosingSquareBracket() throws RepositoryException {
+ String path = "]";
+ TestListener listener = new TestListener(
+ CALLBACKRESULT_ERROR(errorInvalidCharacterInName(path, ']'))
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "/]";
+ listener = new TestListener(
+ CALLBACKRESULT_ROOT,
+ CALLBACKRESULT_ERROR(errorInvalidCharacterInName(path, ']'))
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = ".]";
+ listener = new TestListener(
+ //TODO improve error message?
+ CALLBACKRESULT_ERROR(errorInvalidCharacterInName(path, ']'))
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "..]";
+ listener = new TestListener(
+ //TODO improve error message?
+ CALLBACKRESULT_ERROR(errorInvalidCharacterInName(path, ']'))
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "{]}";
+ listener = new TestListener(
+ CALLBACKRESULT_ERROR(errorInvalidCharacterInName(path, ']'))
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+
+ path = "a[]]";
+ listener = new TestListener(
+ CALLBACKRESULT_ERROR(errorNumberFormatExceptionInIndex(path))
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+ }
+
+ @Test
+ public void testUnxepectedOpeningCurlyBracket() throws RepositoryException {
+ String path = "/{";
+ TestListener listener = new TestListener(
+ CALLBACKRESULT_ROOT,
+ CALLBACKRESULT_ERROR(errorMissingClosingCurlyBracket(path))
);
assertFalse(JcrPathParser.validate(path));
assertFalse(JcrPathParser.parse(path, listener));
listener.evaluate();
}
+ @Test
+
+ public void testMissingClosingCurlyBracket() throws RepositoryException {
+ String path = "{a";
+ TestListener listener = new TestListener(
+ CALLBACKRESULT_ERROR(errorMissingClosingCurlyBracket(path))
+ );
+ assertFalse(JcrPathParser.validate(path));
+ assertFalse(JcrPathParser.parse(path, listener));
+ listener.evaluate();
+ }
+
+ //TODO replace with #errorInvalidCharacterInName() to make error messages consistent?
+ private static String errorCharacterNotAllowedInName(char c) {
+ return "'" + c + "' not allowed in name";
+ }
+
+ private static String errorInvalidCharacterInName(String path, char c) {
+ return "'" + path + "' is not a valid path. ']' not a valid name character.";
+ }
+
+ private static String errorClosingQuareBracketExpected(String path) {
+ return "'" + path + "' is not a valid path. ']' expected after index.";
+ }
+
+ private static String errorNumberFormatExceptionInIndex(String path) {
+ return "'" + path + "' is not a valid path. NumberFormatException in index: ";
+ }
+
+ private static String errorMissingClosingCurlyBracket(String path) {
+ return "'" + path + "' is not a valid path. Missing '}'.";
+ }
}