Return-Path: Delivered-To: apmail-incubator-jackrabbit-commits-archive@www.apache.org Received: (qmail 93751 invoked from network); 23 Mar 2005 18:19:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 23 Mar 2005 18:19:55 -0000 Received: (qmail 69188 invoked by uid 500); 23 Mar 2005 18:19:54 -0000 Mailing-List: contact jackrabbit-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jackrabbit-dev@incubator.apache.org Delivered-To: mailing list jackrabbit-commits@incubator.apache.org Received: (qmail 69172 invoked by uid 500); 23 Mar 2005 18:19:54 -0000 Delivered-To: apmail-incubator-jackrabbit-cvs@incubator.apache.org Received: (qmail 69168 invoked by uid 99); 23 Mar 2005 18:19:54 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 23 Mar 2005 10:19:53 -0800 Received: (qmail 33315 invoked by uid 65534); 23 Mar 2005 15:29:51 -0000 Message-ID: <20050323152951.33314.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Wed, 23 Mar 2005 15:29:51 -0000 Subject: svn commit: r158783 - in incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit: core/search/ test/api/query/ To: jackrabbit-cvs@incubator.apache.org From: mreutegg@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: mreutegg Date: Wed Mar 23 07:29:49 2005 New Revision: 158783 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D158783 Log: - Rewrote order by queries tests in core and moved them into api.query pack= age. Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/AbstractOrderByTest.java (with props) incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByDateTest.java (with props) incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByDoubleTest.java (with props) incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByLongTest.java (with props) incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByMultiTypeTest.java (with props) incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByStringTest.java (with props) Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/search/O= rderByTest.java incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/JcrPathTest.java incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/TestAll.java Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/se= arch/OrderByTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/core/search/OrderByTest.java?view=3Ddiff&r1=3D158782&r2= =3D158783 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/search/O= rderByTest.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/search/O= rderByTest.java Wed Mar 23 07:29:49 2005 @@ -17,146 +17,15 @@ package org.apache.jackrabbit.core.search; =20 import javax.jcr.Node; -import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; import javax.jcr.query.Query; import javax.jcr.query.QueryResult; -import java.util.List; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Arrays; -import java.util.Collections; -import java.util.TimeZone; =20 /** * Tests queries with order by. */ public class OrderByTest extends AbstractQueryTest { =20 - public void testStringOrder() throws Exception { - populate(new String[]{"aaaa", "cccc", "bbbb", "dddd"}); - checkOrder(new int[]{1, 3, 2, 4}); - } - - public void testIntegerOrder() throws Exception { - populate(new int[]{0, -1, 1, 5}); - checkOrder(new int[]{2, 1, 3, 4}); - } - - public void testDateOrder() throws Exception { - Calendar c1 =3D Calendar.getInstance(); - c1.set(2000, 4, 20, 14, 35, 14); - Calendar c2 =3D Calendar.getInstance(); - c2.set(2000, 5, 20, 14, 35, 14); - Calendar c3 =3D Calendar.getInstance(); - c3.set(2000, 4, 20, 14, 35, 13); - populate(new Calendar[]{c1, c2, c3}); - checkOrder(new int[]{3, 1, 2}); - } - - public void testDateOrderMillis() throws Exception { - Calendar c1 =3D Calendar.getInstance(); - c1.set(2000, 6, 12, 14, 35, 19); - c1.set(Calendar.MILLISECOND, 10); - Calendar c2 =3D Calendar.getInstance(); - c2.set(2000, 6, 12, 14, 35, 19); - c2.set(Calendar.MILLISECOND, 9); - Calendar c3 =3D Calendar.getInstance(); - c3.set(2000, 6, 12, 14, 35, 19); - c3.set(Calendar.MILLISECOND, 11); - populate(new Calendar[]{c1, c2, c3}); - checkOrder(new int[]{2, 1, 3}); - } - - public void testDateOrderPositiveTimeZone() throws Exception { - Calendar c1 =3D Calendar.getInstance(TimeZone.getTimeZone("GMT+1:0= 0")); - c1.set(2000, 6, 12, 15, 35, 19); - c1.set(Calendar.MILLISECOND, 10); - Calendar c2 =3D Calendar.getInstance(TimeZone.getTimeZone("GMT")); - c2.set(2000, 6, 12, 14, 35, 19); - c2.set(Calendar.MILLISECOND, 9); - Calendar c3 =3D Calendar.getInstance(TimeZone.getTimeZone("GMT")); - c3.set(2000, 6, 12, 14, 35, 19); - c3.set(Calendar.MILLISECOND, 11); - populate(new Calendar[]{c1, c2, c3}); - checkOrder(new int[]{2, 1, 3}); - } - - public void testDateOrderNegativeTimeZone() throws Exception { - Calendar c1 =3D Calendar.getInstance(TimeZone.getTimeZone("GMT-1:0= 0")); - c1.set(2000, 6, 12, 13, 35, 19); - c1.set(Calendar.MILLISECOND, 10); - Calendar c2 =3D Calendar.getInstance(TimeZone.getTimeZone("GMT")); - c2.set(2000, 6, 12, 14, 35, 19); - c2.set(Calendar.MILLISECOND, 9); - Calendar c3 =3D Calendar.getInstance(TimeZone.getTimeZone("GMT")); - c3.set(2000, 6, 12, 14, 35, 19); - c3.set(Calendar.MILLISECOND, 11); - populate(new Calendar[]{c1, c2, c3}); - checkOrder(new int[]{2, 1, 3}); - } - - public void testDoubleOrder1() throws Exception { - populate(new double[]{-2.4, 4.3, 0.0}); - checkOrder(new int[]{1, 3, 2}); - } - - public void testDoubleOrder2() throws Exception { - populate(new double[]{-1.5, -1.4, -1.39}); - checkOrder(new int[]{1, 2, 3}); - } - - public void testMultipleOrder() throws Exception { - Node n1 =3D testRootNode.addNode("node1"); - Node n2 =3D testRootNode.addNode("node2"); - Node n3 =3D testRootNode.addNode("node3"); - - n1.setProperty("text", "aaa"); - n1.setProperty("value", 3); - n2.setProperty("text", "bbb"); - n2.setProperty("value", 2); - n3.setProperty("text", "ccc"); - n3.setProperty("value", 2); - - testRootNode.save(); - - // both ascending - String sql =3D "SELECT value FROM nt:unstructured WHERE " + - "jcr:path LIKE '" + testRoot + "/%' ORDER BY value, text"; - Query q =3D superuser.getWorkspace().getQueryManager().createQuery= (sql, Query.SQL); - QueryResult result =3D q.execute(); - checkResultOrder(result, new String[]{"node2", "node3", "node1"}); - - String xpath =3D "/" + testRoot + "/*[@jcr:primaryType=3D'nt:unstr= uctured'] order by @value, @text"; - q =3D superuser.getWorkspace().getQueryManager().createQuery(xpath= , Query.XPATH); - result =3D q.execute(); - checkResultOrder(result, new String[]{"node2", "node3", "node1"}); - - // both descending - sql =3D "SELECT value FROM nt:unstructured WHERE " + - "jcr:path LIKE '" + testRoot + "/%' ORDER BY value DESC, t= ext DESC"; - q =3D superuser.getWorkspace().getQueryManager().createQuery(sql, = Query.SQL); - result =3D q.execute(); - checkResultOrder(result, new String[]{"node1", "node3", "node2"}); - - xpath =3D "/" + testRoot + "/*[@jcr:primaryType=3D'nt:unstructured= '] order by @value descending, @text descending"; - q =3D superuser.getWorkspace().getQueryManager().createQuery(xpath= , Query.XPATH); - result =3D q.execute(); - checkResultOrder(result, new String[]{"node1", "node3", "node2"}); - - // mixed ascending and descending - sql =3D "SELECT value FROM nt:unstructured WHERE " + - "jcr:path LIKE '" + testRoot + "/%' ORDER BY value DESC, t= ext"; - q =3D superuser.getWorkspace().getQueryManager().createQuery(sql, = Query.SQL); - result =3D q.execute(); - checkResultOrder(result, new String[]{"node1", "node2", "node3"}); - - xpath =3D "/" + testRoot + "/*[@jcr:primaryType=3D'nt:unstructured= '] order by @value descending, @text"; - q =3D superuser.getWorkspace().getQueryManager().createQuery(xpath= , Query.XPATH); - result =3D q.execute(); - checkResultOrder(result, new String[]{"node1", "node2", "node3"}); - } - public void testOrderByScore() throws RepositoryException { Node n1 =3D testRootNode.addNode("node1"); Node n2 =3D testRootNode.addNode("node2"); @@ -182,85 +51,4 @@ result =3D q.execute(); checkResult(result, 3); } - - //------------------< internal >--------------------------------------= ------ - - private void populate(String[] values) throws RepositoryException { - for (int i =3D 0; i < values.length; i++) { - Node node =3D testRootNode.addNode("node" + (i + 1)); - node.setProperty("value", values[i]); - } - testRootNode.save(); - } - - private void populate(Calendar[] values) throws RepositoryException { - for (int i =3D 0; i < values.length; i++) { - Node node =3D testRootNode.addNode("node" + (i + 1)); - node.setProperty("value", values[i]); - } - testRootNode.save(); - } - - private void populate(int[] values) throws RepositoryException { - for (int i =3D 0; i < values.length; i++) { - Node node =3D testRootNode.addNode("node" + (i + 1)); - node.setProperty("value", values[i]); - } - testRootNode.save(); - } - - private void populate(double[] values) throws RepositoryException { - for (int i =3D 0; i < values.length; i++) { - Node node =3D testRootNode.addNode("node" + (i + 1)); - node.setProperty("value", values[i]); - } - testRootNode.save(); - } - - private void checkOrder(int[] order) throws RepositoryException { - String nodeNames[] =3D new String[order.length]; - for (int i =3D 0; i < order.length; i++) { - nodeNames[i] =3D "node" + order[i]; - } - // first check ascending - String sql =3D "SELECT value FROM nt:unstructured WHERE " + - "jcr:path LIKE '" + testRoot + "/%' ORDER BY value"; - Query q =3D superuser.getWorkspace().getQueryManager().createQuery= (sql, Query.SQL); - QueryResult result =3D q.execute(); - checkResultOrder(result, nodeNames); - - String xpath =3D "/" + testRoot + "/*[@jcr:primaryType=3D'nt:unstr= uctured'] order by @value"; - q =3D superuser.getWorkspace().getQueryManager().createQuery(xpath= , Query.XPATH); - result =3D q.execute(); - checkResultOrder(result, nodeNames); - - // then check descending - Collections.reverse(Arrays.asList(nodeNames)); - - sql =3D "SELECT value FROM nt:unstructured WHERE " + - "jcr:path LIKE '" + testRoot + "/%' ORDER BY value DESC"; - q =3D superuser.getWorkspace().getQueryManager().createQuery(sql, = Query.SQL); - result =3D q.execute(); - checkResultOrder(result, nodeNames); - - xpath =3D "/" + testRoot + "/*[@jcr:primaryType=3D'nt:unstructured= '] order by @value descending"; - q =3D superuser.getWorkspace().getQueryManager().createQuery(xpath= , Query.XPATH); - result =3D q.execute(); - checkResultOrder(result, nodeNames); - } - - private void checkResultOrder(QueryResult result, String[] nodeNames) - throws RepositoryException { - List nodes =3D new ArrayList(); - for (NodeIterator it =3D result.getNodes(); it.hasNext();) { - nodes.add(it.nextNode()); - } - assertEquals("Wrong hit count:", nodeNames.length, nodes.size()); - - for (int i =3D 0; i < nodeNames.length; i++) { - String name =3D ((Node) nodes.get(i)).getName(); - assertEquals("Wrong order of nodes:", nodeNames[i], name); - } - } - } Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/q= uery/AbstractOrderByTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/query/AbstractOrderByTest.java?view=3Dauto&rev= =3D158783 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/AbstractOrderByTest.java (added) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/AbstractOrderByTest.java Wed Mar 23 07:29:49 2005 @@ -0,0 +1,164 @@ +/* + * 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.RepositoryException; +import javax.jcr.Node; +import javax.jcr.NodeIterator; +import javax.jcr.Repository; +import javax.jcr.query.Query; +import javax.jcr.query.QueryResult; +import java.util.Calendar; +import java.util.Collections; +import java.util.Arrays; +import java.util.List; +import java.util.ArrayList; + +/** + * Abstract base class for all order by tests. Provides utility methods. + */ +class AbstractOrderByTest extends AbstractQueryTest { + + /** If true this repository supports sql queries */ + protected boolean checkSQL; + + private String[] nodeNames; + + protected void setUp() throws Exception { + super.setUp(); + if (superuser.getRepository().getDescriptor(Repository.OPTION_QUER= Y_SQL_SUPPORTED) =3D=3D null) { + checkSQL =3D false; + } else { + checkSQL =3D true; + } + nodeNames =3D new String[]{nodeName1, nodeName2, nodeName3, nodeNa= me4}; + } + + /** + * Populates the workspace with child nodes under testroot with + * each node has a String value set in property with name + * propertyname1. + * @param values the String values. + */ + protected void populate(String[] values) throws RepositoryException { + for (int i =3D 0; i < values.length; i++) { + Node node =3D testRootNode.addNode(nodeNames[i], testNodeType); + node.setProperty(propertyName1, values[i]); + } + testRootNode.save(); + } + + /** + * Populates the workspace with child nodes under testroot with + * each node has a calendar value set in property with name + * propertyname1. + * @param values the calendar values. + */ + protected void populate(Calendar[] values) throws RepositoryException { + for (int i =3D 0; i < values.length; i++) { + Node node =3D testRootNode.addNode(nodeNames[i], testNodeType); + node.setProperty(propertyName1, values[i]); + } + testRootNode.save(); + } + + /** + * Populates the workspace with child nodes under testroot with + * each node has a long value set in property with name + * propertyname1. + * @param values the long values. + */ + protected void populate(long[] values) throws RepositoryException { + for (int i =3D 0; i < values.length; i++) { + Node node =3D testRootNode.addNode(nodeNames[i], testNodeType); + node.setProperty(propertyName1, values[i]); + } + testRootNode.save(); + } + + /** + * Populates the workspace with child nodes under testroot with + * each node has a double value set in property with name + * propertyname1. + * @param values the double values. + */ + protected void populate(double[] values) throws RepositoryException { + for (int i =3D 0; i < values.length; i++) { + Node node =3D testRootNode.addNode(nodeNames[i], testNodeType); + node.setProperty(propertyName1, values[i]); + } + testRootNode.save(); + } + + /** + * Runs queries on the workspace and checks if the ordering is accordi= ng + * to the nodeNames. + * @param nodeNames the sequence of node names required in the result = set. + */ + protected void checkOrder(String[] nodeNames) throws RepositoryExcepti= on { + // first check ascending + + String sql =3D "SELECT " + propertyName1 + " FROM " + testNodeType= + " WHERE " + + jcrPath + " LIKE '" + testRoot + "/%' ORDER BY " + pro= pertyName1; + String xpath =3D "/" + jcrRoot + testRoot + "/*[@jcr:primaryType= =3D'" + testNodeType + "'] order by @" + propertyName1; + Query q; + QueryResult result; + if (checkSQL) { + q =3D superuser.getWorkspace().getQueryManager().createQuery(s= ql, Query.SQL); + result =3D q.execute(); + checkResultOrder(result, nodeNames); + } + + q =3D superuser.getWorkspace().getQueryManager().createQuery(xpath= , Query.XPATH); + result =3D q.execute(); + checkResultOrder(result, nodeNames); + + // then check descending + Collections.reverse(Arrays.asList(nodeNames)); + + if (checkSQL) { + q =3D superuser.getWorkspace().getQueryManager().createQuery(s= ql + " DESC", Query.SQL); + result =3D q.execute(); + checkResultOrder(result, nodeNames); + } + + q =3D superuser.getWorkspace().getQueryManager().createQuery(xpath= + " descending", Query.XPATH); + result =3D q.execute(); + checkResultOrder(result, nodeNames); + } + + /** + * Checks if the node ordering in result is according to + * nodeNames. + * @param result the query result. + * @param nodeNames the node names. + */ + protected void checkResultOrder(QueryResult result, String[] nodeNames) + throws RepositoryException { + List nodes =3D new ArrayList(); + for (NodeIterator it =3D result.getNodes(); it.hasNext();) { + nodes.add(it.nextNode()); + } + assertEquals("Wrong hit count:", nodeNames.length, nodes.size()); + + for (int i =3D 0; i < nodeNames.length; i++) { + String name =3D ((Node) nodes.get(i)).getName(); + assertEquals("Wrong order of nodes:", nodeNames[i], name); + } + } + +} Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/= api/query/AbstractOrderByTest.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/ap= i/query/JcrPathTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/query/JcrPathTest.java?view=3Ddiff&r1=3D158782&r= 2=3D158783 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/JcrPathTest.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/JcrPathTest.java Wed Mar 23 07:29:49 2005 @@ -31,7 +31,7 @@ * @test * @sources JcrPathTest.java * @executeClass org.apache.jackrabbit.test.api.query.JcrPathTest - * @keywords level1 sql + * @keywords sql */ public class JcrPathTest extends AbstractQueryTest { =20 Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/q= uery/OrderByDateTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/query/OrderByDateTest.java?view=3Dauto&rev=3D158= 783 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByDateTest.java (added) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByDateTest.java Wed Mar 23 07:29:49 2005 @@ -0,0 +1,109 @@ +/* + * 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 java.util.Calendar; +import java.util.TimeZone; + +/** + * Test cases for order by queries on date properties. + * + * @tck.config testroot path to node that accepts child nodes of type + * nodetype + * @tck.config nodetype name of a node type + * @tck.config nodename1 name of a child node of type nodetype + * @tck.config nodename2 name of a child node of type nodetype + * @tck.config nodename3 name of a child node of type nodetype + * @tck.config nodename4 name of a child node of type nodetype + * @tck.config propertyname1 name of a single value calendar property. + * + * @test + * @sources OrderByDateTest.java + * @executeClass org.apache.jackrabbit.test.api.query.OrderByDateTest + * @keywords level2 + */ +public class OrderByDateTest extends AbstractOrderByTest { + + /** + * Tests order by queries with calendar properties. + */ + public void testDateOrder() throws Exception { + Calendar c1 =3D Calendar.getInstance(); + c1.set(2000, 4, 20, 14, 35, 14); + Calendar c2 =3D Calendar.getInstance(); + c2.set(2000, 5, 20, 14, 35, 14); + Calendar c3 =3D Calendar.getInstance(); + c3.set(2000, 4, 20, 14, 35, 13); + populate(new Calendar[]{c1, c2, c3}); + checkOrder(new String[]{nodeName3, nodeName1, nodeName2}); + } + + /** + * Tests order by queries with calendar properties where the calendar + * values only have a millisecond difference. + */ + public void testDateOrderMillis() throws Exception { + Calendar c1 =3D Calendar.getInstance(); + c1.set(2000, 6, 12, 14, 35, 19); + c1.set(Calendar.MILLISECOND, 10); + Calendar c2 =3D Calendar.getInstance(); + c2.set(2000, 6, 12, 14, 35, 19); + c2.set(Calendar.MILLISECOND, 9); + Calendar c3 =3D Calendar.getInstance(); + c3.set(2000, 6, 12, 14, 35, 19); + c3.set(Calendar.MILLISECOND, 11); + populate(new Calendar[]{c1, c2, c3}); + checkOrder(new String[]{nodeName2, nodeName1, nodeName3}); + } + + /** + * Tests order by queries with calendar properties where the calendar + * values have different time zones. + */ + public void testDateOrderPositiveTimeZone() throws Exception { + Calendar c1 =3D Calendar.getInstance(TimeZone.getTimeZone("GMT+1:0= 0")); + c1.set(2000, 6, 12, 15, 35, 19); + c1.set(Calendar.MILLISECOND, 10); + Calendar c2 =3D Calendar.getInstance(TimeZone.getTimeZone("GMT")); + c2.set(2000, 6, 12, 14, 35, 19); + c2.set(Calendar.MILLISECOND, 9); + Calendar c3 =3D Calendar.getInstance(TimeZone.getTimeZone("GMT")); + c3.set(2000, 6, 12, 14, 35, 19); + c3.set(Calendar.MILLISECOND, 11); + populate(new Calendar[]{c1, c2, c3}); + checkOrder(new String[]{nodeName2, nodeName1, nodeName3}); + } + + /** + * Tests order by queries with calendar properties where the calendar + * values have different time zones. + */ + public void testDateOrderNegativeTimeZone() throws Exception { + Calendar c1 =3D Calendar.getInstance(TimeZone.getTimeZone("GMT-1:0= 0")); + c1.set(2000, 6, 12, 13, 35, 19); + c1.set(Calendar.MILLISECOND, 10); + Calendar c2 =3D Calendar.getInstance(TimeZone.getTimeZone("GMT")); + c2.set(2000, 6, 12, 14, 35, 19); + c2.set(Calendar.MILLISECOND, 9); + Calendar c3 =3D Calendar.getInstance(TimeZone.getTimeZone("GMT")); + c3.set(2000, 6, 12, 14, 35, 19); + c3.set(Calendar.MILLISECOND, 11); + populate(new Calendar[]{c1, c2, c3}); + checkOrder(new String[]{nodeName2, nodeName1, nodeName3}); + } + +} Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/= api/query/OrderByDateTest.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/q= uery/OrderByDoubleTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/query/OrderByDoubleTest.java?view=3Dauto&rev=3D1= 58783 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByDoubleTest.java (added) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByDoubleTest.java Wed Mar 23 07:29:49 2005 @@ -0,0 +1,54 @@ +/* + * 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; + +/** + * Test cases for order by queries on double properties. + * + * @tck.config testroot path to node that accepts child nodes of type + * nodetype + * @tck.config nodetype name of a node type + * @tck.config nodename1 name of a child node of type nodetype + * @tck.config nodename2 name of a child node of type nodetype + * @tck.config nodename3 name of a child node of type nodetype + * @tck.config nodename4 name of a child node of type nodetype + * @tck.config propertyname1 name of a single value double property. + * + * @test + * @sources OrderByDoubleTest.java + * @executeClass org.apache.jackrabbit.test.api.query.OrderByDoubleTest + * @keywords level2 + */ +public class OrderByDoubleTest extends AbstractOrderByTest { + + /** + * Tests order by queries with double properties. + */ + public void testDoubleOrder1() throws Exception { + populate(new double[]{-2.4, 4.3, 0.0}); + checkOrder(new String[]{nodeName1, nodeName3, nodeName2}); + } + + /** + * Tests order by queries with double properties. + */ + public void testDoubleOrder2() throws Exception { + populate(new double[]{-1.5, -1.4, -1.39}); + checkOrder(new String[]{nodeName1, nodeName2, nodeName3}); + } + +} Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/= api/query/OrderByDoubleTest.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/q= uery/OrderByLongTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/query/OrderByLongTest.java?view=3Dauto&rev=3D158= 783 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByLongTest.java (added) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByLongTest.java Wed Mar 23 07:29:49 2005 @@ -0,0 +1,45 @@ +/* + * 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; + +/** + * Test cases for order by queries on long properties. + * + * @tck.config testroot path to node that accepts child nodes of type + * nodetype + * @tck.config nodetype name of a node type + * @tck.config nodename1 name of a child node of type nodetype + * @tck.config nodename2 name of a child node of type nodetype + * @tck.config nodename3 name of a child node of type nodetype + * @tck.config nodename4 name of a child node of type nodetype + * @tck.config propertyname1 name of a single value long property. + * + * @test + * @sources OrderByLongTest.java + * @executeClass org.apache.jackrabbit.test.api.query.OrderByLongTest + * @keywords level2 + */ +public class OrderByLongTest extends AbstractOrderByTest { + + /** + * Tests order by queries with long properties. + */ + public void testIntegerOrder() throws Exception { + populate(new long[]{0, -1, 1, 5}); + checkOrder(new String[]{nodeName2, nodeName1, nodeName3, nodeName4= }); + } +} Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/= api/query/OrderByLongTest.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/q= uery/OrderByMultiTypeTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/query/OrderByMultiTypeTest.java?view=3Dauto&rev= =3D158783 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByMultiTypeTest.java (added) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByMultiTypeTest.java Wed Mar 23 07:29:49 2005 @@ -0,0 +1,108 @@ +/* + * 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.Node; +import javax.jcr.query.Query; +import javax.jcr.query.QueryResult; + +/** + * Test cases for order by queries on long properties. + * + * @tck.config testroot path to node that accepts child nodes of type + * nodetype + * @tck.config nodetype name of a node type + * @tck.config nodename1 name of a child node of type nodetype + * @tck.config nodename2 name of a child node of type nodetype + * @tck.config nodename3 name of a child node of type nodetype + * @tck.config nodename4 name of a child node of type nodetype + * @tck.config propertyname1 name of a single value String property. + * @tck.config propertyname2 name of a single value long property. + * @test + * @sources OrderByMultiTypeTest.java + * @executeClass org.apache.jackrabbit.test.api.query.OrderByMultiTypeTest + * @keywords level2 + */ +public class OrderByMultiTypeTest extends AbstractOrderByTest { + + /** + * Tests order by queries with a String property and a long property. + */ + public void testMultipleOrder() throws Exception { + Node n1 =3D testRootNode.addNode(nodeName1); + Node n2 =3D testRootNode.addNode(nodeName2); + Node n3 =3D testRootNode.addNode(nodeName3); + + n1.setProperty(propertyName1, "aaa"); + n1.setProperty(propertyName2, 3); + n2.setProperty(propertyName1, "bbb"); + n2.setProperty(propertyName2, 2); + n3.setProperty(propertyName1, "ccc"); + n3.setProperty(propertyName2, 2); + + testRootNode.save(); + + // both ascending + String sql =3D "SELECT " + propertyName2 + " FROM " + testNodeType= + " WHERE " + + jcrPath + " LIKE '" + testRoot + "/%' ORDER BY " + propert= yName2 + ", " + propertyName1; + Query q; + QueryResult result; + if (checkSQL) { + q =3D superuser.getWorkspace().getQueryManager().createQuery(s= ql, Query.SQL); + result =3D q.execute(); + checkResultOrder(result, new String[]{nodeName2, nodeName3, no= deName1}); + } + + String xpath =3D "/" + testRoot + "/*[@" + jcrPrimaryType + "=3D'"= + testNodeType + + "'] order by @" + propertyName2 + ", @" + propertyName1; + q =3D superuser.getWorkspace().getQueryManager().createQuery(xpath= , Query.XPATH); + result =3D q.execute(); + checkResultOrder(result, new String[]{nodeName2, nodeName3, nodeNa= me1}); + + // both descending + sql =3D "SELECT " + propertyName2 + " FROM " + testNodeType + " WH= ERE " + + jcrPath + " LIKE '" + testRoot + "/%' ORDER BY " + + propertyName2 + " DESC, " + + propertyName1 + " DESC"; + q =3D superuser.getWorkspace().getQueryManager().createQuery(sql, = Query.SQL); + result =3D q.execute(); + checkResultOrder(result, new String[]{nodeName1, nodeName3, nodeNa= me2}); + + xpath =3D "/" + jcrRoot + testRoot + "/*[@" + jcrPrimaryType + "= =3D'" + + testNodeType + "'] order by @" + + propertyName2 + " descending, @" + + propertyName1 + " descending"; + q =3D superuser.getWorkspace().getQueryManager().createQuery(xpath= , Query.XPATH); + result =3D q.execute(); + checkResultOrder(result, new String[]{nodeName1, nodeName3, nodeNa= me2}); + + // mixed ascending and descending + sql =3D "SELECT " + propertyName2 + " FROM " + testNodeType + " WH= ERE " + + jcrPath + " LIKE '" + testRoot + "/%' ORDER BY " + + propertyName2 + " DESC, " + propertyName1; + q =3D superuser.getWorkspace().getQueryManager().createQuery(sql, = Query.SQL); + result =3D q.execute(); + checkResultOrder(result, new String[]{nodeName1, nodeName2, nodeNa= me3}); + + xpath =3D "/" + jcrRoot + testRoot + "/*[@" + jcrPrimaryType + "= =3D'" + + testNodeType + "'] order by @" + propertyName2 + + " descending, @" + propertyName1; + q =3D superuser.getWorkspace().getQueryManager().createQuery(xpath= , Query.XPATH); + result =3D q.execute(); + checkResultOrder(result, new String[]{nodeName1, nodeName2, nodeNa= me3}); + } +} Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/= api/query/OrderByMultiTypeTest.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/q= uery/OrderByStringTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/query/OrderByStringTest.java?view=3Dauto&rev=3D1= 58783 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByStringTest.java (added) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/OrderByStringTest.java Wed Mar 23 07:29:49 2005 @@ -0,0 +1,46 @@ +/* + * 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; + +/** + * Test cases for order by queries on String properties. + * + * @tck.config testroot path to node that accepts child nodes of type + * nodetype + * @tck.config nodetype name of a node type + * @tck.config nodename1 name of a child node of type nodetype + * @tck.config nodename2 name of a child node of type nodetype + * @tck.config nodename3 name of a child node of type nodetype + * @tck.config nodename4 name of a child node of type nodetype + * @tck.config propertyname1 name of a single value String property. + * + * @test + * @sources OrderByStringTest.java + * @executeClass org.apache.jackrabbit.test.api.query.OrderByStringTest + * @keywords level2 + */ +public class OrderByStringTest extends AbstractOrderByTest { + + /** + * Tests order by queries with String properties. + */ + public void testStringOrder() throws Exception { + populate(new String[]{"aaaa", "cccc", "bbbb", "dddd"}); + checkOrder(new String[]{nodeName1, nodeName3, nodeName2, nodeName4= }); + } + +} Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/= api/query/OrderByStringTest.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/ap= i/query/TestAll.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/query/TestAll.java?view=3Ddiff&r1=3D158782&r2=3D= 158783 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/TestAll.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/quer= y/TestAll.java Wed Mar 23 07:29:49 2005 @@ -59,6 +59,12 @@ suite.addTestSuite(PredicatesTest.class); suite.addTestSuite(SimpleSelectionTest.class); =20 + suite.addTestSuite(OrderByDateTest.class); + suite.addTestSuite(OrderByDoubleTest.class); + suite.addTestSuite(OrderByLongTest.class); + suite.addTestSuite(OrderByMultiTypeTest.class); + suite.addTestSuite(OrderByStringTest.class); + return suite; } }