Author: mreutegg
Date: Wed Mar 16 08:11:54 2005
New Revision: 157764
URL: http://svn.apache.org/viewcvs?view=rev&rev=157764
Log:
More query test cases.
Added:
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPropertyNamesTest.java
(with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/JcrPathTest.java
(with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/PredicatesTest.java
(with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SimpleSelectionTest.java
(with props)
Modified:
incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java
Modified: incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties?view=diff&r1=157763&r2=157764
==============================================================================
--- incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties (original)
+++ incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties Wed Mar 16
08:11:54 2005
@@ -288,6 +288,18 @@
# Test class: DerefQueryLevel1Test
javax.jcr.tck.DerefQueryLevel1Test.testroot=/testdata
+# Test class: GetPropertyNamesTest
+javax.jcr.tck.GetPropertyNamesTest.testroot=/testdata
+
+# Test class: JcrPathTest
+javax.jcr.tck.JcrPathTest.testroot=/testdata
+
+# Test class: PredicatesTest
+javax.jcr.tck.PredicatesTest.testroot=/testdata
+
+# Test class: SimpleSelectionTest
+javax.jcr.tck.SimpleSelectionTest.testroot=/testdata
+
# ==============================================================================
# JAVAX.JCR.VERSIONING CONFIGURATION
# ==============================================================================
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPropertyNamesTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPropertyNamesTest.java?view=auto&rev=157764
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPropertyNamesTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPropertyNamesTest.java
Wed Mar 16 08:11:54 2005
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed 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.test.api.query;
+
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.nodetype.PropertyDef;
+import java.util.Arrays;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Tests if the property names of an XPath query without a jcr:primaryType
+ * predicate matches the ones declared in nt:base.
+ *
+ * @test
+ * @sources GetPropertyNamesTest.java
+ * @executeClass org.apache.jackrabbit.test.api.query.GetPropertyNamesTest
+ * @keywords level1
+ */
+public class GetPropertyNamesTest extends AbstractQueryTest {
+
+ /** A read-only session */
+ private Session session;
+
+ /**
+ * Sets up the test cases
+ */
+ protected void setUp() throws Exception {
+ isReadOnly = true;
+ super.setUp();
+ session = helper.getReadOnlySession();
+ testRootNode = session.getRootNode().getNode(testPath);
+ }
+
+ /**
+ * Releases the session acquired in setUp().
+ */
+ protected void tearDown() throws Exception {
+ if (session != null) {
+ session.logout();
+ }
+ super.tearDown();
+ }
+
+ /**
+ * Check if the property names from the search results match the
+ * non-residual ones from the base node type
+ */
+ public void testGetPropertyNames() throws RepositoryException {
+ String queryStatement = "/" + jcrRoot;
+
+ // build and execute search query
+ Query query = superuser.getWorkspace().getQueryManager().createQuery(queryStatement,
Query.XPATH);
+ QueryResult result = query.execute();
+
+ // Get the node's non-residual properties
+ PropertyDef[] pd = superuser.getWorkspace().getNodeTypeManager().getNodeType(ntBase).getDeclaredPropertyDefs();
+
+ List singleValPropNames = new ArrayList();
+ for (int i = 0; i < pd.length; i++) {
+ // only keep the single-value properties
+ if (!pd[i].isMultiple()) {
+ singleValPropNames.add(pd[i].getName());
+ }
+ }
+
+ String[] foundPropertyNames = result.getPropertyNames();
+ Object[] realPropertyNames = singleValPropNames.toArray();
+
+ // sort the 2 arrays before comparing them
+ Arrays.sort(foundPropertyNames);
+ Arrays.sort(realPropertyNames);
+
+ assertTrue("Property names don't match", Arrays.equals(foundPropertyNames, realPropertyNames));
+ }
+}
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPropertyNamesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/JcrPathTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/JcrPathTest.java?view=auto&rev=157764
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/JcrPathTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/JcrPathTest.java
Wed Mar 16 08:11:54 2005
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed 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.test.api.query;
+
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+
+/**
+ * Tests if the jcr:path property is returned at the correct position in the
+ * query result.
+ *
+ * @test
+ * @sources JcrPathTest.java
+ * @executeClass org.apache.jackrabbit.test.api.query.JcrPathTest
+ * @keywords level1 sql
+ */
+public class JcrPathTest extends AbstractQueryTest {
+
+ /** A read-only session */
+ private Session session;
+
+ /**
+ * Sets up the test cases
+ */
+ protected void setUp() throws Exception {
+ isReadOnly = true;
+ super.setUp();
+ session = helper.getReadOnlySession();
+ testRootNode = session.getRootNode().getNode(testPath);
+ }
+
+ /**
+ * Releases the session acquired in setUp().
+ */
+ protected void tearDown() throws Exception {
+ if (session != null) {
+ session.logout();
+ }
+ super.tearDown();
+ }
+
+ /**
+ * Verify that the jcr:path is the first property from the found property
+ * names, when explicitely declared in the select clause as the 1st
+ * property
+ * @throws NotExecutableException if the repository does not support the
+ * jcr:path property in the query result.
+ */
+ public void testJcrPath() throws RepositoryException, NotExecutableException {
+ String nodeTypeName = session.getRootNode().getPrimaryNodeType().getName();
+ String queryStatement = "select " + jcrPath + " from " + nodeTypeName;
+
+ // verify that jcr:path is supported
+ if (session.getRepository().getDescriptor(Repository.QUERY_JCRPATH) == null) {
+ throw new NotExecutableException(jcrPath + " not supported");
+ }
+
+ // execute the search query
+ Query query = session.getWorkspace().getQueryManager().createQuery(queryStatement,
Query.SQL);
+ QueryResult result = query.execute();
+
+ String[] propNames = result.getPropertyNames();
+ if (propNames.length > 0) {
+ // jcr:path should be the first column
+ assertEquals(jcrPath + " should be the first property", jcrPath, propNames[0]);
+ }
+ }
+}
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/JcrPathTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/PredicatesTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/PredicatesTest.java?view=auto&rev=157764
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/PredicatesTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/PredicatesTest.java
Wed Mar 16 08:11:54 2005
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed 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.test.api.query;
+
+import javax.jcr.query.Query;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.QueryManager;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * Tests if queries with predicates are accepted. Test cases in this class only
+ * perform tests that check if the QueryManager accepts the query, but the tests
+ * will not execute the query and check its results.
+ *
+ * @test
+ * @sources PredicatesTest.java
+ * @executeClass org.apache.jackrabbit.test.api.query.PredicatesTest
+ * @keywords level1
+ */
+public class PredicatesTest extends AbstractQueryTest {
+
+ /**
+ * the node type of the root node
+ */
+ private String nodeTypeName;
+
+ /**
+ * A read-only session
+ */
+ private Session session;
+
+ /**
+ * the query manager of the session
+ */
+ private QueryManager qm;
+
+ /**
+ * Sets up the test cases
+ */
+ protected void setUp() throws Exception {
+ isReadOnly = true;
+ super.setUp();
+ session = helper.getReadOnlySession();
+ testRootNode = session.getRootNode().getNode(testPath);
+
+ nodeTypeName = session.getRootNode().getPrimaryNodeType().getName();
+ qm = session.getWorkspace().getQueryManager();
+ }
+
+ /**
+ * Releases the session acquired in setUp().
+ */
+ protected void tearDown() throws Exception {
+ if (session != null) {
+ session.logout();
+ }
+ super.tearDown();
+ }
+
+ /**
+ * Verifies that the value of a property can be searched
+ *
+ * @throws RepositoryException
+ */
+ public void testEquality() throws RepositoryException {
+ String stmt = "/" + jcrRoot + "/*[@" + jcrPrimaryType + "='" + nodeTypeName + "']";
+
+ try {
+ qm.createQuery(stmt, Query.XPATH);
+ } catch (InvalidQueryException e) {
+ fail("invalid statement syntax for '" + stmt + "'");
+ }
+ }
+
+ /**
+ * Verifies that the or operator is accepted for properties's values
+ *
+ * @throws RepositoryException
+ */
+ public void testCombinedOr() throws RepositoryException {
+ String stmt = "/" + jcrRoot + "/*[@" + jcrPrimaryType + "='" + nodeTypeName + "'
or @" + jcrPrimaryType + "='" + ntBase + "']";
+
+ try {
+ qm.createQuery(stmt, Query.XPATH);
+ } catch (InvalidQueryException e) {
+ fail("invalid statement syntax for '" + stmt + "'");
+ }
+ }
+
+ /**
+ * Verifies that the or operator is accepted for a property name
+ *
+ * @throws RepositoryException
+ */
+ public void testOr() throws RepositoryException {
+ String stmt = "/" + jcrRoot + "/*[@" + jcrPrimaryType + " or @" + jcrMixinTypes +
"]";
+
+ try {
+ qm.createQuery(stmt, Query.XPATH);
+ } catch (InvalidQueryException e) {
+ fail("invalid statement syntax for '" + stmt + "'");
+ }
+ }
+
+ /**
+ * Verifies that the and operator is accepted for a property name
+ *
+ * @throws RepositoryException
+ */
+ public void testAnd() throws RepositoryException {
+ String stmt = "/" + jcrRoot + "/*[@" + jcrPrimaryType + " and @" + jcrMixinTypes
+ "]";
+
+ try {
+ qm.createQuery(stmt, Query.XPATH);
+ } catch (InvalidQueryException e) {
+ fail("invalid statement syntax for '" + stmt + "'");
+ }
+ }
+
+ /**
+ * Verifies that the and operator is accepted for properties's values
+ *
+ * @throws RepositoryException
+ */
+ public void testCombinedAnd() throws RepositoryException {
+ String stmt = "/" + jcrRoot + "/*[@" + jcrPrimaryType + "='" + nodeTypeName + "'
and @" + jcrPrimaryType + "='" + ntBase + "']";
+
+ try {
+ qm.createQuery(stmt, Query.XPATH);
+ } catch (InvalidQueryException e) {
+ fail("invalid statement syntax for '" + stmt + "'");
+ }
+ }
+}
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/PredicatesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SimpleSelectionTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SimpleSelectionTest.java?view=auto&rev=157764
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SimpleSelectionTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SimpleSelectionTest.java
Wed Mar 16 08:11:54 2005
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed 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.test.api.query;
+
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import java.util.Arrays;
+
+/**
+ * <code>SimpleSelectionTest</code>...
+ *
+ * @test
+ * @sources SimpleSelectionTest.java
+ * @executeClass org.apache.jackrabbit.test.api.query.SimpleSelectionTest
+ * @keywords level1
+ */
+public class SimpleSelectionTest extends AbstractQueryTest {
+
+ /**
+ * A read-only session
+ */
+ private Session session;
+
+ /**
+ * Sets up the test cases
+ */
+ protected void setUp() throws Exception {
+ isReadOnly = true;
+ super.setUp();
+ session = helper.getReadOnlySession();
+ testRootNode = session.getRootNode().getNode(testPath);
+ }
+
+ /**
+ * Releases the session acquired in setUp().
+ */
+ protected void tearDown() throws Exception {
+ if (session != null) {
+ session.logout();
+ }
+ super.tearDown();
+ }
+
+ /**
+ * Verifies that searching for a property from a single node returns only
+ * one row and has the searched property
+ *
+ * @throws NotExecutableException if {@link #testRootNode} does not have any
+ * child nodes.
+ */
+ public void testSingleProperty()
+ throws RepositoryException, NotExecutableException {
+
+ if (!testRootNode.hasNodes()) {
+ throw new NotExecutableException("Workspace does not contains enough content.");
+ }
+ // build search query statement
+ String firstChildpath = testRootNode.getNodes().nextNode().getPath();
+ String propQuery = "/" + jcrRoot + firstChildpath + "[@" + jcrPrimaryType + "]";
+
+ // execute search query
+ Query query = session.getWorkspace().getQueryManager().createQuery(propQuery, Query.XPATH);
+ QueryResult result = query.execute();
+
+ assertEquals("Should have only 1 result", 1, result.getRows().getSize());
+ assertTrue("Should contain the searched property",
+ Arrays.asList(result.getPropertyNames()).contains(jcrPrimaryType));
+ }
+}
\ No newline at end of file
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SimpleSelectionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java?view=diff&r1=157763&r2=157764
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java
Wed Mar 16 08:11:54 2005
@@ -52,6 +52,11 @@
suite.addTestSuite(GetStatementTest.class);
suite.addTestSuite(GetSupportedQueryLanguagesTest.class);
+ suite.addTestSuite(JcrPathTest.class);
+ suite.addTestSuite(GetPropertyNamesTest.class);
+ suite.addTestSuite(PredicatesTest.class);
+ suite.addTestSuite(SimpleSelectionTest.class);
+
return suite;
}
}
|