You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2015/09/01 17:26:49 UTC

svn commit: r1700591 - in /chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/query: InvalidQueryTest.java QueryTestGroup.java

Author: fmui
Date: Tue Sep  1 15:26:49 2015
New Revision: 1700591

URL: http://svn.apache.org/r1700591
Log:
TCK: test invalid queries

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/query/InvalidQueryTest.java
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/query/QueryTestGroup.java

Added: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/query/InvalidQueryTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/query/InvalidQueryTest.java?rev=1700591&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/query/InvalidQueryTest.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/query/InvalidQueryTest.java Tue Sep  1 15:26:49 2015
@@ -0,0 +1,80 @@
+/*
+ * 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.chemistry.opencmis.tck.tests.query;
+
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.WARNING;
+
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.client.api.QueryResult;
+import org.apache.chemistry.opencmis.client.api.Session;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
+
+public class InvalidQueryTest extends AbstractQueryTest {
+
+    @Override
+    public void init(Map<String, String> parameters) {
+        super.init(parameters);
+        setName("Invalid Query Test");
+        setDescription("Tests invalid queries.");
+    }
+
+    @Override
+    public void run(Session session) {
+        if (supportsQuery(session)) {
+            doInvalidQuery(session, "");
+            doInvalidQuery(session, "SELECT");
+            doInvalidQuery(session, "SELECT *");
+            doInvalidQuery(session, "THIS_IS_NOT_A_SELECT");
+            doInvalidQuery(session, "SELECT FROM cmis:document");
+            doInvalidQuery(session, "SELECT ,cmis:name FROM cmis:document");
+        } else {
+            try {
+                doQuery(session, "SELECT * FROM cmis:document");
+                addResult(createResult(WARNING, "Query capability is set to 'none' but calling query() works."));
+            } catch (CmisNotSupportedException e) {
+                // excepted
+            } catch (Exception ex) {
+                addResult(createResult(FAILURE,
+                        "Query capability is set to 'none' but calling query() throws an exception, which is not a notSupported exception("
+                                + ex.toString() + ").", ex, false));
+            }
+        }
+    }
+
+    private void doQuery(Session session, String stmt) {
+        for (QueryResult qr : session.query(stmt, false)) {
+            qr.getPropertyByQueryName("cmis:name");
+        }
+    }
+
+    private void doInvalidQuery(Session session, String stmt) {
+        try {
+            doQuery(session, stmt);
+            addResult(createResult(FAILURE, "This query is invalid but has been accepted: " + stmt));
+        } catch (CmisInvalidArgumentException e) {
+            // excepted
+        } catch (Exception ex) {
+            addResult(createResult(FAILURE, "This query is invalid and an unexcepted exception (" + ex.toString()
+                    + ") has been thrown: " + stmt, ex, false));
+        }
+    }
+}

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/query/QueryTestGroup.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/query/QueryTestGroup.java?rev=1700591&r1=1700590&r2=1700591&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/query/QueryTestGroup.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/query/QueryTestGroup.java Tue Sep  1 15:26:49 2015
@@ -38,6 +38,7 @@ public class QueryTestGroup extends Abst
         addTest(new QueryForObject());
         addTest(new QueryLikeTest());
         addTest(new QueryInFolderTest());
+        addTest(new InvalidQueryTest());
         addTest(new ContentChangesSmokeTest());
     }
 }