You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2015/12/16 11:46:01 UTC
svn commit: r1720318 -
/sling/trunk/contrib/extensions/acldef-parser/src/test/java/org/apache/sling/acldef/parser/test/ParsingErrorsTest.java
Author: bdelacretaz
Date: Wed Dec 16 10:46:01 2015
New Revision: 1720318
URL: http://svn.apache.org/viewvc?rev=1720318&view=rev
Log:
SLING-5355 - test parsing errors
Added:
sling/trunk/contrib/extensions/acldef-parser/src/test/java/org/apache/sling/acldef/parser/test/ParsingErrorsTest.java
Added: sling/trunk/contrib/extensions/acldef-parser/src/test/java/org/apache/sling/acldef/parser/test/ParsingErrorsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/acldef-parser/src/test/java/org/apache/sling/acldef/parser/test/ParsingErrorsTest.java?rev=1720318&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/acldef-parser/src/test/java/org/apache/sling/acldef/parser/test/ParsingErrorsTest.java (added)
+++ sling/trunk/contrib/extensions/acldef-parser/src/test/java/org/apache/sling/acldef/parser/test/ParsingErrorsTest.java Wed Dec 16 10:46:01 2015
@@ -0,0 +1,89 @@
+/*
+ * 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.sling.acldef.parser.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.sling.acldef.parser.ACLDefinitions;
+import org.apache.sling.acldef.parser.ParseException;
+import org.apache.sling.acldef.parser.TokenMgrError;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/** Test various parsing errors */
+@RunWith(Parameterized.class)
+public class ParsingErrorsTest {
+
+ private String input;
+ private Class<? extends Throwable> expected;
+
+ @Parameters
+ public static Collection<Object[]> data() {
+ @SuppressWarnings("serial")
+ final List<Object []> result = new ArrayList<Object []>() {{
+ add(new Object[] { "foo", ParseException.class });
+ add(new Object[] { "12", ParseException.class });
+
+ add(new Object[] { "set ACL on /apps \n remove * for u \n end", null });
+ add(new Object[] { "set ACL on /apps \n badkeyword * for u \n end", ParseException.class });
+ add(new Object[] { "set ACL on appsWithoutSlash \n remove * for u \n end", ParseException.class });
+ add(new Object[] { "set ACL", ParseException.class });
+ add(new Object[] { "set ACL \n end", ParseException.class });
+
+ add(new Object[] { "create service user bob, alice, tom21", null });
+ add(new Object[] { "create service user bob-221_BOB", null });
+ add(new Object[] { "create service user bob/221", ParseException.class });
+ add(new Object[] { "create service user bob,/alice, tom21", ParseException.class });
+ add(new Object[] { "create service user bob,alice,tom21 # comment not allowed here", TokenMgrError.class });
+ add(new Object[] { "CREATE service user bob, alice, tom21", ParseException.class });
+ add(new Object[] { "create SERVICE user bob, alice, tom21", ParseException.class });
+ }};
+ return result;
+ }
+
+ public ParsingErrorsTest(String input, Class<? extends Throwable> expected) {
+ this.input = input;
+ this.expected = expected;
+ }
+
+ @Test
+ public void checkResult() throws ParseException, IOException {
+ final StringReader r = new StringReader(input);
+ try {
+ new ACLDefinitions(r).parse();
+ if(expected != null) {
+ fail("Expected a " + expected.getSimpleName() + " for [" + input + "]");
+ }
+ } catch(Exception e) {
+ assertEquals(expected, e.getClass());
+ } catch(Error err) {
+ assertEquals(expected, err.getClass());
+ } finally {
+ r.close();
+ }
+ }
+}
\ No newline at end of file