jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r158896 - in incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java test/org/apache/jackrabbit/test/api/query/TestAll.java test/org/apache/jackrabbit/test/api/query/TextNodeTest.java
Date Thu, 24 Mar 2005 09:23:15 GMT
Author: mreutegg
Date: Thu Mar 24 01:23:14 2005
New Revision: 158896

URL: http://svn.apache.org/viewcvs?view=rev&rev=158896
Log:
- Implement support for text() node test.
- Test cases for text() node test.

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TextNodeTest.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.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/xpath/XPathQueryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java?view=diff&r1=158895&r2=158896
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/xpath/XPathQueryBuilder.java
Thu Mar 24 01:23:14 2005
@@ -88,6 +88,11 @@
     static final QName FN_POSITION_FULL = new QName("", "position()");
 
     /**
+     * QName for jcr:xmltext
+     */
+    static final QName JCR_XMLTEXT = new QName(NamespaceRegistryImpl.NS_JCR_URI, "xmltext");
+
+    /**
      * QName for last function.
      */
     static final QName FN_LAST = new QName("", "last");
@@ -344,6 +349,12 @@
                     if (child.getId() != JJTANYNAME) {
                         createNodeTest(child, queryNode);
                     }
+                }
+                break;
+            case JJTTEXTTEST:
+                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
+                    LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
+                    loc.setNameTest(JCR_XMLTEXT);
                 }
                 break;
             case JJTTYPENAME:

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=158895&r2=158896
==============================================================================
--- 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
Thu Mar 24 01:23:14 2005
@@ -48,6 +48,7 @@
 
         suite.addTestSuite(DerefQueryLevel1Test.class);
         suite.addTestSuite(ElementTest.class);
+        suite.addTestSuite(TextNodeTest.class);
         suite.addTestSuite(GetLanguageTest.class);
         suite.addTestSuite(GetPersistentQueryPathLevel1Test.class);
         suite.addTestSuite(GetPersistentQueryPathTest.class);

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TextNodeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TextNodeTest.java?view=auto&rev=158896
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TextNodeTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TextNodeTest.java
Thu Mar 24 01:23:14 2005
@@ -0,0 +1,123 @@
+/*
+ * 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.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.Repository;
+
+/**
+ * Tests the text() node test in XPath.
+ *
+ * @tck.config testroot path to node that allows child nodes of type
+ * <code>nodetype</code>. The node at <code>testroot</code> must
allow child
+ * nodes with name jcr:xmltext. Assignment of node type for that child node must
+ * be determined by the child node definition. That is, the test will create the
+ * node with {@link javax.jcr.Node#addNode(String)}, without giving an explicit
+ * node type.
+ * @tck.config nodetype name of a node type for nodes under
+ * <code>testroot</code>. This node type must allow child nodes with name
+ * jcr:xmltext. Assignment of node type for that child node must be determined
+ * by the child node definition. That is, the test will create the node with
+ * {@link javax.jcr.Node#addNode(String)}, without giving an explicit node
+ * type.
+ * @tck.config nodename1 name of a child node under <code>testroot</code>.
+ * 
+ * @test
+ * @sources TextNodeTest.java
+ * @executeClass org.apache.jackrabbit.test.api.query.TextNodeTest
+ * @keywords level2
+ */
+public class TextNodeTest extends AbstractQueryTest {
+
+    /** Resolved QName for jcr:xmltext */
+    private String jcrXMLText;
+
+    private String jcrXMLCharacters;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        jcrXMLText = superuser.getNamespacePrefix(NS_JCR_URI) + ":xmltext";
+        jcrXMLCharacters = superuser.getNamespacePrefix(NS_JCR_URI) + ":xmlcharacters";
+    }
+
+    /**
+     * Tests if text() node test is equivalent with jcr:xmltext.
+     */
+    public void testTextNodeTest() throws RepositoryException {
+        Node text1 = testRootNode.addNode(jcrXMLText);
+        testRootNode.save();
+        String xpath = "/" + jcrRoot + testRoot + "/text()";
+        executeXPathQuery(superuser, xpath, new Node[]{text1});
+    }
+
+    /**
+     * Tests if text() node test is equivalent with jcr:xmltext and will select
+     * multiple nodes with name jcr:xmltext.
+     */
+    public void testTextNodeTestMultiNodes() throws RepositoryException {
+        Node text1 = testRootNode.addNode(jcrXMLText);
+        Node text2 = testRootNode.addNode(nodeName1, testNodeType).addNode(jcrXMLText);
+        testRootNode.save();
+        String xpath = "/" + jcrRoot + testRoot + "//text()";
+        executeXPathQuery(superuser, xpath, new Node[]{text1, text2});
+    }
+
+    /**
+     * Tests if text() node test is equivalent with jcr:xmltext and jcrfn:contains
+     * matches content in jcr:xmlcharacters property.
+     */
+    public void testTextNodeTestContains() throws RepositoryException {
+        Node text1 = testRootNode.addNode(jcrXMLText);
+        text1.setProperty(jcrXMLCharacters, "the quick brown fox jumps over the lazy dog.");
+        Node text2 = testRootNode.addNode(nodeName1, testNodeType).addNode(jcrXMLText);
+        text2.setProperty(jcrXMLCharacters, "java content repository");
+        testRootNode.save();
+        String xpath = "/" + jcrRoot + testRoot + "//text()[jcrfn:contains('fox')]";
+        executeXPathQuery(superuser, xpath, new Node[]{text1});
+    }
+
+    /**
+     * Tests text() node test with various position predicates: position(),
+     * first(), last().
+     * @throws NotExecutableException if the repository does not support queries
+     *  with position inidex.
+     */
+    public void testTextNodeTestWithPosition()
+            throws RepositoryException, NotExecutableException {
+        if (superuser.getRepository().getDescriptor(Repository.QUERY_XPATH_POS_INDEX) ==
null) {
+            throw new NotExecutableException("Repository does not support position index");
+        }
+        Node text1 = testRootNode.addNode(jcrXMLText);
+        if (!text1.getDefinition().allowSameNameSibs()) {
+            throw new NotExecutableException("Node at path: " + testRoot + " does not allow
same name siblings with name: " + jcrXMLText);
+        }
+        testRootNode.addNode(nodeName1, testNodeType);
+        Node text2 = testRootNode.addNode(jcrXMLText);
+        testRootNode.save();
+        String xpath = "/" + jcrRoot + testRoot + "/text()[2]";
+        executeXPathQuery(superuser, xpath, new Node[]{text2});
+        xpath = "/" + jcrRoot + testRoot + "/text()[last()]";
+        executeXPathQuery(superuser, xpath, new Node[]{text2});
+        xpath = "/" + jcrRoot + testRoot + "/text()[position() = 2]";
+        executeXPathQuery(superuser, xpath, new Node[]{text2});
+        xpath = "/" + jcrRoot + testRoot + "/text()[first()]";
+        executeXPathQuery(superuser, xpath, new Node[]{text1});
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TextNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message