[exo-jcr-commits] exo-jcr SVN: r295 - in jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr: impl/core/query and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Oct 19 08:50:03 EDT 2009


Author: sergiykarpenko
Date: 2009-10-19 08:50:03 -0400 (Mon, 19 Oct 2009)
New Revision: 295

Removed:
   jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/IndexFormatVersionTest.java
Modified:
   jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/IndexingRuleTest.java
   jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestQueryUsecases.java
Log:
EXOJCR-180: TestQueryUsecases updated

Deleted: jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/IndexFormatVersionTest.java
===================================================================
--- jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/IndexFormatVersionTest.java	2009-10-19 12:40:20 UTC (rev 294)
+++ jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/IndexFormatVersionTest.java	2009-10-19 12:50:03 UTC (rev 295)
@@ -1,67 +0,0 @@
-/*
- * 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.exoplatform.services.jcr.api.core.query;
-
-import org.apache.jackrabbit.test.AbstractJCRTest;
-import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
-import org.exoplatform.services.jcr.impl.core.query.QueryManagerImpl;
-import org.exoplatform.services.jcr.impl.core.query.lucene.IndexFormatVersion;
-import org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex;
-
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.query.QueryManager;
-
-/**
- * <code>IndexFormatVersionTest</code> checks if the various index format
- * versions are correctly read from the index.
- */
-public class IndexFormatVersionTest extends AbstractJCRTest {
-
-   
-   public void testname() throws Exception
-   {
-      
-   }
-//    public void testVersionOne() throws RepositoryException {
-//        checkIndexFormatVersion("index-format-v1", IndexFormatVersion.V1);
-//    }
-//
-//    public void testVersionTwo() throws RepositoryException {
-//        checkIndexFormatVersion("index-format-v2", IndexFormatVersion.V2);
-//    }
-//
-//    public void testVersionThree() throws RepositoryException {
-//        checkIndexFormatVersion("index-format-v3", IndexFormatVersion.V3);
-//    }
-//
-//    private void checkIndexFormatVersion(String wspName,
-//                                         IndexFormatVersion version)
-//            throws RepositoryException {
-//        Session session = helper.getSuperuserSession(wspName);
-//        try {
-//            QueryManager qm = session.getWorkspace().getQueryManager();
-//            QueryHandler handler = ((QueryManagerImpl) qm).getQueryHandler();
-//            SearchIndex index = (SearchIndex) handler;
-//            assertEquals("Wrong index format", version.getVersion(),
-//                    index.getIndexFormatVersion().getVersion());
-//        } finally {
-//            session.logout();
-//        }
-//    }
-}

Modified: jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/IndexingRuleTest.java
===================================================================
--- jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/IndexingRuleTest.java	2009-10-19 12:40:20 UTC (rev 294)
+++ jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/IndexingRuleTest.java	2009-10-19 12:50:03 UTC (rev 295)
@@ -83,9 +83,12 @@
       Node node2 = testRootNode.addNode(nodeName2, NT_UNSTRUCTURED);
       node2.setProperty("rule", "nsiFalse");
       node2.setProperty("text", TEXT);
+      Node node3 = testRootNode.addNode(nodeName3, NT_UNSTRUCTURED);
+      node3.setProperty("text", TEXT);
+
       testRootNode.save();
       String stmt = "/jcr:root" + testRootNode.getPath() + "/*[jcr:contains(., 'quick')]";
-      checkResult(executeQuery(stmt), new Node[]{node1});
+      checkResult(executeQuery(stmt), new Node[]{node1, node3});
    }
 
    public void testNodeType() throws RepositoryException
@@ -104,23 +107,22 @@
    {
       Node node = testRootNode.addNode(nodeName1, NT_UNSTRUCTURED);
       node.setProperty("rule", "excerpt");
-      node.setProperty("title", "Apache Jackrabbit");
-      node.setProperty("text", "Jackrabbit is a JCR implementation");
+      node.setProperty("title", "eXo Platform");
+      node.setProperty("text", "eXo is a JCR implementation");
       testRootNode.save();
-      String stmt =
-         "/jcr:root" + testRootNode.getPath() + "/*[jcr:contains(., 'jackrabbit implementation')]/rep:excerpt(.)";
+      String stmt = "/jcr:root" + testRootNode.getPath() + "/*[jcr:contains(., 'eXo implementation')]/rep:excerpt(.)";
       RowIterator rows = executeQuery(stmt).getRows();
       assertTrue("No results returned", rows.hasNext());
       Value excerpt = rows.nextRow().getValue("rep:excerpt(.)");
       assertNotNull("No excerpt created", excerpt);
-      assertTrue("Title must not be present in excerpt", excerpt.getString().indexOf("Apache") == -1);
+      assertTrue("Title must not be present in excerpt", excerpt.getString().indexOf("Platform") == -1);
       assertTrue("Missing highlight", excerpt.getString().indexOf("<strong>implementation</strong>") != -1);
 
-      stmt = "/jcr:root" + testRootNode.getPath() + "/*[jcr:contains(., 'apache')]/rep:excerpt(.)";
+      stmt = "/jcr:root" + testRootNode.getPath() + "/*[jcr:contains(., 'eXo implementation')]/rep:excerpt(.)";
       rows = executeQuery(stmt).getRows();
       assertTrue("No results returned", rows.hasNext());
       excerpt = rows.nextRow().getValue("rep:excerpt(.)");
       assertNotNull("No excerpt created", excerpt);
-      assertTrue("Title must not be present in excerpt", excerpt.getString().indexOf("Apache") == -1);
+      assertTrue("Title must not be present in excerpt", excerpt.getString().indexOf("Platform") == -1);
    }
 }

Modified: jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestQueryUsecases.java
===================================================================
--- jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestQueryUsecases.java	2009-10-19 12:40:20 UTC (rev 294)
+++ jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestQueryUsecases.java	2009-10-19 12:50:03 UTC (rev 295)
@@ -21,9 +21,11 @@
 import org.exoplatform.services.log.Log;
 
 import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 import javax.jcr.Node;
@@ -422,7 +424,101 @@
       checkResult(xres, new Node[]{doc2, doc3});
    }
 
+   public void testUPPERConstraint() throws Exception
+   {
+      root.addNode("simplenode", "nt:unstructured");
+
+      Node doc1 = root.addNode("document1", "nt:unstructured");
+      doc1.addMixin("mix:title");
+      doc1.setProperty("jcr:title", "CaseSensitive");
+
+      Node doc2 = root.addNode("document2", "nt:unstructured");
+      doc2.addMixin("mix:title");
+      doc2.setProperty("jcr:title", "casesensitive");
+
+      Node doc3 = root.addNode("document3", "nt:unstructured");
+      doc3.addMixin("mix:title");
+      doc3.setProperty("jcr:title", "caseSENSITIVE");
+      session.save();
+
+      // make SQL query
+      QueryManager qman = this.workspace.getQueryManager();
+
+      Query q = qman.createQuery("SELECT * FROM mix:title WHERE UPPER(jcr:title) = 'CASESENSITIVE'", Query.SQL);
+      QueryResult res = q.execute();
+      long sqlsize = res.getNodes().getSize();
+      assertEquals(3, sqlsize);
+      checkResult(res, new Node[]{doc1, doc2, doc3});
+
+      q = qman.createQuery("SELECT * FROM mix:title WHERE LOWER(jcr:title) = 'casesensitive'", Query.SQL);
+      res = q.execute();
+      sqlsize = res.getNodes().getSize();
+      assertEquals(3, sqlsize);
+      checkResult(res, new Node[]{doc1, doc2, doc3});
+
+      //make XPath query
+      Query xq = qman.createQuery("//element(*,mix:title)[fn:upper-case(@jcr:title)='CASESENSITIVE']", Query.XPATH);
+      QueryResult xres = xq.execute();
+      long xpathsize = xres.getNodes().getSize();
+      assertEquals(3, xpathsize);
+      checkResult(xres, new Node[]{doc1, doc2, doc3});
+
+      xq = qman.createQuery("//element(*,mix:title)[fn:lower-case(@jcr:title)='casesensitive']", Query.XPATH);
+      xres = xq.execute();
+      xpathsize = xres.getNodes().getSize();
+      assertEquals(3, xpathsize);
+      checkResult(xres, new Node[]{doc1, doc2, doc3});
+   }
+
    /**
+    * Find all mix:title nodes which title begins from 'P' symbol.
+    * 
+    * @throws Exception
+    */
+   public void testLikeWithEscapeSymbol() throws Exception
+   {
+      root.addNode("simplenode", "nt:unstructured");
+
+      Node doc1 = root.addNode("document1", "nt:unstructured");
+      doc1.addMixin("mix:title");
+      doc1.setProperty("jcr:title", "Porison break");//setProperty("jcr:title", "Star wars");
+      doc1.setProperty("jcr:description", "Dart rules!!");
+
+      Node doc2 = root.addNode("document2", "nt:file");
+      doc2.addMixin("mix:title");
+      doc2.setProperty("jcr:title", "P%rison break");
+      doc2.setProperty("jcr:description", "Run, Forest, run ))");
+
+      NodeImpl cont = (NodeImpl)doc2.addNode("jcr:content", "nt:resource");
+      cont.setProperty("jcr:mimeType", "text/plain");
+      cont.setProperty("jcr:lastModified", Calendar.getInstance());
+      cont.setProperty("jcr:data", "text");
+
+      Node doc3 = root.addNode("document3", "nt:unstructured");
+      doc3.addMixin("mix:title");
+      doc3.setProperty("jcr:title", "Panopticum");
+      doc3.setProperty("jcr:description", "It's imagine film )");
+
+      session.save();
+
+      // make SQL query
+      QueryManager qman = this.workspace.getQueryManager();
+
+      Query q = qman.createQuery("SELECT * FROM mix:title WHERE jcr:title LIKE 'P#%ri%' ESCAPE '#'", Query.SQL);
+      QueryResult res = q.execute();
+      long sqlsize = res.getNodes().getSize();
+      assertEquals(1, sqlsize);
+      checkResult(res, new Node[]{doc2});
+
+      //make XPath query
+      Query xq = qman.createQuery("//element(*,mix:title)[jcr:like(@jcr:title, 'P\\%ri%')]", Query.XPATH);
+      QueryResult xres = xq.execute();
+      long xpathsize = xres.getNodes().getSize();
+      assertEquals(1, xpathsize);
+      checkResult(xres, new Node[]{doc2});
+   }
+
+   /**
     * Find all mix:title nodes which title not begins from 'P' symbol.
     * 
     * @throws Exception
@@ -911,8 +1007,8 @@
       QueryManager qman = this.workspace.getQueryManager();
 
       Query q =
-         qman.createQuery(
-            "SELECT * FROM mix:title WHERE CONTAINS(*, 'brown OR fox OR jumps') ORDER BY jcr:score() DESC", Query.SQL);
+         qman.createQuery("SELECT * FROM mix:title WHERE CONTAINS(*, 'brown OR fox OR jumps') ORDER BY SCORE ASC",
+            Query.SQL);
       QueryResult res = q.execute();
       long sqlsize = res.getNodes().getSize();
       assertEquals(3, sqlsize);
@@ -921,7 +1017,7 @@
       //make XPath query
       Query xq =
          qman.createQuery(
-            "//element(*,mix:title)[jcr:contains(., 'brown OR fox OR jumps')] order by jcr:score() descending",
+            "//element(*,mix:title)[jcr:contains(., 'brown OR fox OR jumps')] order by jcr:score() ascending",
             Query.XPATH);
       QueryResult xres = xq.execute();
       long xpathsize = xres.getNodes().getSize();
@@ -1006,6 +1102,77 @@
       checkOrder(res, new Node[]{doc3, doc1, doc2});
    }
 
+   public void testSearchByName() throws Exception
+   {
+      Node doc1 = root.addNode("document1", "nt:file");
+      NodeImpl cont1 = (NodeImpl)doc1.addNode("jcr:content", "nt:resource");
+      cont1.setProperty("jcr:mimeType", "text/plain");
+      cont1.setProperty("jcr:lastModified", Calendar.getInstance());
+      cont1.setProperty("jcr:data", "The quick brown fox jump over the lazy dog");
+      session.save();
+
+      Node doc2 = root.addNode("document2", "nt:file");
+      NodeImpl cont2 = (NodeImpl)doc2.addNode("jcr:content", "nt:resource");
+      cont2.setProperty("jcr:mimeType", "text/plain");
+      cont2.setProperty("jcr:lastModified", Calendar.getInstance());
+      cont2.setProperty("jcr:data", "Dogs do not like cats.");
+
+      Node doc3 = root.addNode("document1", "nt:file");
+      NodeImpl cont3 = (NodeImpl)doc3.addNode("jcr:content", "nt:resource");
+      cont3.setProperty("jcr:mimeType", "text/plain");
+      cont3.setProperty("jcr:lastModified", Calendar.getInstance());
+      cont3.setProperty("jcr:data", "Cats jumping high.");
+      session.save();
+
+      // make SQL query
+      QueryManager qman = this.workspace.getQueryManager();
+
+      Query q = qman.createQuery("SELECT * FROM nt:file WHERE fn:name() = 'document1'", Query.SQL);
+      QueryResult res = q.execute();
+      long sqlsize = res.getNodes().getSize();
+      assertEquals(2, sqlsize);
+      checkResult(res, new Node[]{doc1, doc3});
+
+      //make XPath query
+      Query xq = qman.createQuery("//element(*,nt:file)[fn:name() = 'document1']", Query.XPATH);
+      QueryResult xres = xq.execute();
+      long xpathsize = xres.getNodes().getSize();
+      assertEquals(2, xpathsize);
+      checkResult(xres, new Node[]{doc1, doc3});
+   }
+
+   public void testMultivalueProperty() throws Exception
+   {
+      Node doc1 = root.addNode("node1", "nt:unstructured");
+      doc1.setProperty("multiprop", new String[]{"one", "two"});
+
+      Node doc2 = root.addNode("node2", "nt:unstructured");
+      doc2.setProperty("multiprop", new String[]{"one", "two", "three"});
+
+      Node doc3 = root.addNode("node3", "nt:unstructured");
+      doc3.setProperty("multiprop", new String[]{"one", "five"});
+      session.save();
+
+      // make SQL query
+      QueryManager qman = this.workspace.getQueryManager();
+
+      Query q =
+         qman.createQuery("SELECT * FROM nt:unstructured WHERE multiprop = 'one' AND multiprop = 'two'", Query.SQL);
+      QueryResult res = q.execute();
+      long sqlsize = res.getNodes().getSize();
+      assertEquals(2, sqlsize);
+      checkResult(res, new Node[]{doc1, doc2});
+
+      //make XPath query
+      Query xq =
+         qman.createQuery("//element(*,nt:unstructured)[@multiprop = 'one' and @multiprop = 'two']", Query.XPATH);
+      QueryResult xres = xq.execute();
+      long xpathsize = xres.getNodes().getSize();
+      assertEquals(2, xpathsize);
+      checkResult(xres, new Node[]{doc1, doc2});
+
+   }
+
    /**
     * Checks if the result set contains exactly the <code>nodes</code>.
     * 
@@ -1050,6 +1217,14 @@
    {
       NodeIterator ni = res.getNodes();
 
+      List<String> list = new ArrayList<String>();
+
+      while (ni.hasNext())
+      {
+         list.add(ni.nextNode().getPath());
+      }
+
+      ni = res.getNodes();
       for (int i = 0; i < expectedNodes.length; i++)
       {
          Node expNode = expectedNodes[i];



More information about the exo-jcr-commits mailing list