You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/20 14:39:45 UTC
[sling-org-apache-sling-repoinit-parser] 36/46: SLING-6984 -
'disable service user' reason is required
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-parser.git
commit 16557d142a0f4a96bad2f3400cdec09347c607a5
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Aug 18 10:56:30 2017 +0000
SLING-6984 - 'disable service user' reason is required
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1805399 13f79535-47bb-0310-9956-ffa450edef68
---
.../parser/operations/DisableServiceUser.java | 13 +++++---
src/main/javacc/RepoInitGrammar.jjt | 2 +-
.../parser/test/DisableServiceUserTest.java} | 36 ++++++++++------------
.../repoinit/parser/test/ParsingErrorsTest.java | 3 ++
src/test/resources/testcases/test-61-output.txt | 4 +--
src/test/resources/testcases/test-61.txt | 7 +----
src/test/resources/testcases/test-99-output.txt | 1 -
src/test/resources/testcases/test-99.txt | 3 +-
8 files changed, 32 insertions(+), 37 deletions(-)
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/DisableServiceUser.java b/src/main/java/org/apache/sling/repoinit/parser/operations/DisableServiceUser.java
index 3e646c2..221815d 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/DisableServiceUser.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/DisableServiceUser.java
@@ -18,20 +18,23 @@
package org.apache.sling.repoinit.parser.operations;
public class DisableServiceUser extends ServiceUserOperation {
- private final String message;
+ private final String reason;
- public DisableServiceUser(String username, String message) {
+ public DisableServiceUser(String username, String reason) {
super(username);
- this.message = cleanupQuotedString(message);
+ this.reason = cleanupQuotedString(reason);
+ if(this.reason == null || this.reason.length() == 0) {
+ throw new IllegalArgumentException("A non-empty reason is required");
+ }
}
@Override
protected String getParametersDescription() {
final StringBuilder sb = new StringBuilder();
sb.append(super.getParametersDescription());
- if(message!=null) {
+ if(reason!=null) {
sb.append(" : ");
- sb.append(message);
+ sb.append(reason);
}
return sb.toString();
}
diff --git a/src/main/javacc/RepoInitGrammar.jjt b/src/main/javacc/RepoInitGrammar.jjt
index b05300a..b599e8e 100644
--- a/src/main/javacc/RepoInitGrammar.jjt
+++ b/src/main/javacc/RepoInitGrammar.jjt
@@ -492,7 +492,7 @@ void disableServiceUserStatement(List<Operation> result) :
{
<DISABLE> <SERVICE> <USER>
( user = <STRING> )
- ( <COLON> msg = <QUOTED>) ?
+ ( <COLON> msg = <QUOTED> )
{
result.add(new DisableServiceUser(user.image, msg == null ? null : msg.image));
}
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/DisableServiceUser.java b/src/test/java/org/apache/sling/repoinit/parser/test/DisableServiceUserTest.java
similarity index 54%
copy from src/main/java/org/apache/sling/repoinit/parser/operations/DisableServiceUser.java
copy to src/test/java/org/apache/sling/repoinit/parser/test/DisableServiceUserTest.java
index 3e646c2..be09aa5 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/DisableServiceUser.java
+++ b/src/test/java/org/apache/sling/repoinit/parser/test/DisableServiceUserTest.java
@@ -15,29 +15,27 @@
* limitations under the License.
*/
-package org.apache.sling.repoinit.parser.operations;
+package org.apache.sling.repoinit.parser.test;
-public class DisableServiceUser extends ServiceUserOperation {
- private final String message;
+import org.apache.sling.repoinit.parser.operations.DisableServiceUser;
+import org.junit.Test;
+
+public class DisableServiceUserTest {
+
+ public static final String USERNAME = "foo";
- public DisableServiceUser(String username, String message) {
- super(username);
- this.message = cleanupQuotedString(message);
+ @Test
+ public void nonEmptyReason() {
+ new DisableServiceUser(USERNAME, "some reason");
}
-
- @Override
- protected String getParametersDescription() {
- final StringBuilder sb = new StringBuilder();
- sb.append(super.getParametersDescription());
- if(message!=null) {
- sb.append(" : ");
- sb.append(message);
- }
- return sb.toString();
+
+ @Test(expected = IllegalArgumentException.class)
+ public void emptyReason() {
+ new DisableServiceUser(USERNAME, "");
}
- @Override
- public void accept(OperationVisitor v) {
- v.visitDisableServiceUser(this);
+ @Test(expected = IllegalArgumentException.class)
+ public void nullReason() {
+ new DisableServiceUser(USERNAME, null);
}
}
diff --git a/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java b/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java
index 53f90ab..836c3d6 100644
--- a/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java
+++ b/src/test/java/org/apache/sling/repoinit/parser/test/ParsingErrorsTest.java
@@ -65,6 +65,9 @@ public class ParsingErrorsTest {
add(new Object[] { "CREATE service user bob, alice, tom21", ParseException.class });
add(new Object[] { "create SERVICE user bob, alice, tom21", ParseException.class });
+ // Disable service user with missing reason
+ add(new Object[] { "disable service user foo", ParseException.class });
+
// Quoted strings in disable service user
add(new Object[] { "disable service user foo missing colon and quotes", ParseException.class });
add(new Object[] { "disable service user foo : missing quotes", ParseException.class });
diff --git a/src/test/resources/testcases/test-61-output.txt b/src/test/resources/testcases/test-61-output.txt
index f20b547..912251c 100644
--- a/src/test/resources/testcases/test-61-output.txt
+++ b/src/test/resources/testcases/test-61-output.txt
@@ -1,3 +1 @@
-DisableServiceUser svcA : This message explains why it's disabled. Whitespace is preserved.
-DisableServiceUser svcB
-DisableServiceUser svcC
\ No newline at end of file
+DisableServiceUser svcA : This message explains why it's disabled. Whitespace is preserved.
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-61.txt b/src/test/resources/testcases/test-61.txt
index 31d07a6..669fba9 100644
--- a/src/test/resources/testcases/test-61.txt
+++ b/src/test/resources/testcases/test-61.txt
@@ -1,7 +1,2 @@
# Test "disable service user" statements
-
-disable service user svcA : "This message explains why it's disabled. Whitespace is preserved."
-disable service user svcB : ""
-
-# message is optional
-disable service user svcC
+disable service user svcA : "This message explains why it's disabled. Whitespace is preserved."
\ No newline at end of file
diff --git a/src/test/resources/testcases/test-99-output.txt b/src/test/resources/testcases/test-99-output.txt
index ea139c8..803fe20 100644
--- a/src/test/resources/testcases/test-99-output.txt
+++ b/src/test/resources/testcases/test-99-output.txt
@@ -32,4 +32,3 @@ CreateUser userE (with encoded password), password=afdgwdsdf, passwordEncoding=s
CreateUser one_with-more-chars.ok:/123456 (with encoded password), password=pw-with.ok-:/13456, passwordEncoding=encoding_with.ok-:/12345
CreateServiceUser the-last-one
DisableServiceUser svc1 : This is the message
-DisableServiceUser svc212
diff --git a/src/test/resources/testcases/test-99.txt b/src/test/resources/testcases/test-99.txt
index 52f445c..7fc9c68 100644
--- a/src/test/resources/testcases/test-99.txt
+++ b/src/test/resources/testcases/test-99.txt
@@ -53,5 +53,4 @@ create user userE with password {someEncoding} afdgwdsdf
create user one_with-more-chars.ok:/123456 with password {encoding_with.ok-:/12345} pw-with.ok-:/13456
create service user the-last-one
-disable service user svc1 : "This is the message"
-disable service user svc212
+disable service user svc1 : "This is the message"
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.