You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2005/03/16 12:38:56 UTC
svn commit: r157736 - in incubator/jackrabbit/trunk/src:
java/org/apache/jackrabbit/core/search/
test/org/apache/jackrabbit/test/api/query/
Author: mreutegg
Date: Wed Mar 16 03:38:51 2005
New Revision: 157736
URL: http://svn.apache.org/viewcvs?view=rev&rev=157736
Log:
Added more test cases for Query and QueryManager interfaces.
Added:
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetLanguageTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPersistentQueryPathLevel1Test.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPersistentQueryPathTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetStatementTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetSupportedQueryLanguagesTest.java (with props)
Modified:
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryImpl.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SaveTest.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryImpl.java?view=diff&r1=157735&r2=157736
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/QueryImpl.java Wed Mar 16 03:38:51 2005
@@ -187,6 +187,7 @@
queryNode.setProperty(QueryConstants.JCR_STATEMENT.toJCRName(resolver), statement);
// todo this should be changed in the spec some time!
queryNode.getParent().save();
+ node = queryNode;
} catch (MalformedPathException e) {
throw new RepositoryException(e.getMessage(), e);
} catch (NoPrefixDeclaredException e) {
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetLanguageTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetLanguageTest.java?view=auto&rev=157736
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetLanguageTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetLanguageTest.java Wed Mar 16 03:38:51 2005
@@ -0,0 +1,65 @@
+/*
+ * 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.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * Test the method {@link Query#getLanguage()}.
+ *
+ * @test
+ * @sources GetLanguageTest.java
+ * @executeClass org.apache.jackrabbit.test.api.query.GetLanguageTest
+ * @keywords level1
+ */
+public class GetLanguageTest 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();
+ }
+
+ /**
+ * Tests if a XPath query returns {@link Query#XPATH} when calling
+ * {@link Query#getLanguage()}.
+ */
+ public void testGetLanguage() throws RepositoryException {
+ String statement = "/" + jcrRoot;
+ Query q = session.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
+ assertEquals("Query returns wrong language.", Query.XPATH, q.getLanguage());
+ }
+}
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetLanguageTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPersistentQueryPathLevel1Test.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPersistentQueryPathLevel1Test.java?view=auto&rev=157736
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPersistentQueryPathLevel1Test.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPersistentQueryPathLevel1Test.java Wed Mar 16 03:38:51 2005
@@ -0,0 +1,71 @@
+/*
+ * 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.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.ItemNotFoundException;
+
+/**
+ * Test the method {@link Query#getPersistentQueryPath()}.
+ *
+ * @test
+ * @sources GetPersistentQueryPathLevel1Test.java
+ * @executeClass org.apache.jackrabbit.test.api.query.GetPersistentQueryPathLevel1Test
+ * @keywords level1
+ */
+public class GetPersistentQueryPathLevel1Test 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();
+ }
+
+ /**
+ * Tests if a non-persistent query throws an {@link ItemNotFoundException}
+ * when {@link Query#getPersistentQueryPath()} is called.
+ */
+ public void testGetPersistentQueryPath() throws RepositoryException {
+ String statement = "/" + jcrRoot;
+ Query q = session.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
+ try {
+ q.getPersistentQueryPath();
+ fail("Query.getPersistentQueryPath() on a transient query must throw an ItemNotFoundException.");
+ } catch (ItemNotFoundException e) {
+ // success
+ }
+ }
+}
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPersistentQueryPathLevel1Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPersistentQueryPathTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPersistentQueryPathTest.java?view=auto&rev=157736
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPersistentQueryPathTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPersistentQueryPathTest.java Wed Mar 16 03:38:51 2005
@@ -0,0 +1,49 @@
+/*
+ * 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.RepositoryException;
+
+/**
+ * Test the method {@link Query#getPersistentQueryPath()}.
+ *
+ * @tck.config testroot node that allows to create a child node of type nt:query.
+ * @tck.config nodename1 name of an nt:query node that can becreated below the
+ * testroot.
+ *
+ * @test
+ * @sources GetPersistentQueryPathTest.java
+ * @executeClass org.apache.jackrabbit.test.api.query.GetPersistentQueryPathTest
+ * @keywords level2
+ */
+public class GetPersistentQueryPathTest extends AbstractQueryTest {
+
+ /**
+ * Tests if {@link Query#getPersistentQueryPath()} returns the correct
+ * path where the query had been saved.
+ */
+ public void testGetPersistentQueryPath() throws RepositoryException {
+ String statement = "/" + jcrRoot;
+ Query q = superuser.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
+ String path = testRoot + "/" + nodeName1;
+ q.save(path);
+ assertEquals("Query.getPersistentQueryPath() does not return the correct path.",
+ path,
+ q.getPersistentQueryPath());
+ }
+}
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetPersistentQueryPathTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetStatementTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetStatementTest.java?view=auto&rev=157736
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetStatementTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetStatementTest.java Wed Mar 16 03:38:51 2005
@@ -0,0 +1,67 @@
+/*
+ * 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.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * Tests the method {@link Query#getStatement()}.
+ *
+ * @test
+ * @sources GetStatementTest.java
+ * @executeClass org.apache.jackrabbit.test.api.query.GetStatementTest
+ * @keywords level1
+ */
+public class GetStatementTest 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();
+ }
+
+ /**
+ * Tests it the statement returned by {@link Query#getStatement()} is equal
+ * to the one passed in createQuery().
+ */
+ public void testGetStatement() throws RepositoryException {
+ String statement = "/" + jcrRoot + "/foo";
+ Query q = session.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
+ assertEquals("Statement returned by Query.getStatement() is not equal to the initial statement.",
+ statement,
+ q.getStatement());
+ }
+}
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetStatementTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetSupportedQueryLanguagesTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetSupportedQueryLanguagesTest.java?view=auto&rev=157736
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetSupportedQueryLanguagesTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetSupportedQueryLanguagesTest.java Wed Mar 16 03:38:51 2005
@@ -0,0 +1,78 @@
+/*
+ * 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.QueryManager;
+import javax.jcr.query.Query;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Repository;
+import java.util.List;
+import java.util.Arrays;
+
+/**
+ * Test the method {@link QueryManager#getSupportedQueryLanguages()}.
+ *
+ * @test
+ * @sources GetSupportedQueryLanguagesTest.java
+ * @executeClass org.apache.jackrabbit.test.api.query.GetSupportedQueryLanguagesTest
+ * @keywords level1
+ */
+public class GetSupportedQueryLanguagesTest 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();
+ }
+
+ /**
+ * Tests if all implementations return {@link Query#XPATH} with
+ * {@link QueryManager#getSupportedQueryLanguages()}. Tests if repositores
+ * that have the SQL descriptor set in the repository return {@link Query#SQL}.
+ */
+ public void testGetSupportedQueryLanguages() throws RepositoryException {
+ List langs = Arrays.asList(session.getWorkspace().getQueryManager().getSupportedQueryLanguages());
+ // all repositories must support XPath
+ assertTrue("XPath not retured with QueryManager.getSupportedQueryLanguages()",
+ langs.contains(Query.XPATH));
+
+ // if repository descriptor for sql is present also sql must be returned
+ if (session.getRepository().getDescriptor(Repository.OPTION_QUERY_SQL_SUPPORTED) != null) {
+ assertTrue("SQL not returned with QueryManager.getSupportedQueryLanguages()",
+ langs.contains(Query.SQL));
+ }
+
+ }
+}
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/GetSupportedQueryLanguagesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SaveTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SaveTest.java?view=diff&r1=157735&r2=157736
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SaveTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/SaveTest.java Wed Mar 16 03:38:51 2005
@@ -59,6 +59,9 @@
Node queryNode = testRootNode.getNode(nodeName1);
assertEquals("Query node is not of type nt:query", ntQuery, queryNode.getPrimaryNodeType().getName());
+
+ Query query2 = superuser.getWorkspace().getQueryManager().getQuery(queryNode);
+ assertEquals("Persisted query does not match initial query.", query.getStatement(), query2.getStatement());
}
/**
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=157735&r2=157736
==============================================================================
--- 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 03:38:51 2005
@@ -46,6 +46,11 @@
suite.addTestSuite(XPathQueryLevel2Test.class);
suite.addTestSuite(DerefQueryLevel1Test.class);
+ suite.addTestSuite(GetLanguageTest.class);
+ suite.addTestSuite(GetPersistentQueryPathLevel1Test.class);
+ suite.addTestSuite(GetPersistentQueryPathTest.class);
+ suite.addTestSuite(GetStatementTest.class);
+ suite.addTestSuite(GetSupportedQueryLanguagesTest.class);
return suite;
}