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/23 16:29:51 UTC
svn commit: r158783 - in
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit: core/search/
test/api/query/
Author: mreutegg
Date: Wed Mar 23 07:29:49 2005
New Revision: 158783
URL: http://svn.apache.org/viewcvs?view=rev&rev=158783
Log:
- Rewrote order by queries tests in core and moved them into api.query package.
Added:
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractOrderByTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByDateTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByDoubleTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByLongTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByMultiTypeTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByStringTest.java (with props)
Modified:
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/search/OrderByTest.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/JcrPathTest.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/TestAll.java
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/search/OrderByTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/search/OrderByTest.java?view=diff&r1=158782&r2=158783
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/search/OrderByTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/search/OrderByTest.java Wed Mar 23 07:29:49 2005
@@ -17,146 +17,15 @@
package org.apache.jackrabbit.core.search;
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;
/**
* Tests queries with order by.
*/
public class OrderByTest extends AbstractQueryTest {
- 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 = Calendar.getInstance();
- c1.set(2000, 4, 20, 14, 35, 14);
- Calendar c2 = Calendar.getInstance();
- c2.set(2000, 5, 20, 14, 35, 14);
- Calendar c3 = 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 = Calendar.getInstance();
- c1.set(2000, 6, 12, 14, 35, 19);
- c1.set(Calendar.MILLISECOND, 10);
- Calendar c2 = Calendar.getInstance();
- c2.set(2000, 6, 12, 14, 35, 19);
- c2.set(Calendar.MILLISECOND, 9);
- Calendar c3 = 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 = Calendar.getInstance(TimeZone.getTimeZone("GMT+1:00"));
- c1.set(2000, 6, 12, 15, 35, 19);
- c1.set(Calendar.MILLISECOND, 10);
- Calendar c2 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
- c2.set(2000, 6, 12, 14, 35, 19);
- c2.set(Calendar.MILLISECOND, 9);
- Calendar c3 = 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 = Calendar.getInstance(TimeZone.getTimeZone("GMT-1:00"));
- c1.set(2000, 6, 12, 13, 35, 19);
- c1.set(Calendar.MILLISECOND, 10);
- Calendar c2 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
- c2.set(2000, 6, 12, 14, 35, 19);
- c2.set(Calendar.MILLISECOND, 9);
- Calendar c3 = 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 = testRootNode.addNode("node1");
- Node n2 = testRootNode.addNode("node2");
- Node n3 = 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 = "SELECT value FROM nt:unstructured WHERE " +
- "jcr:path LIKE '" + testRoot + "/%' ORDER BY value, text";
- Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
- QueryResult result = q.execute();
- checkResultOrder(result, new String[]{"node2", "node3", "node1"});
-
- String xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured'] order by @value, @text";
- q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
- result = q.execute();
- checkResultOrder(result, new String[]{"node2", "node3", "node1"});
-
- // both descending
- sql = "SELECT value FROM nt:unstructured WHERE " +
- "jcr:path LIKE '" + testRoot + "/%' ORDER BY value DESC, text DESC";
- q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
- result = q.execute();
- checkResultOrder(result, new String[]{"node1", "node3", "node2"});
-
- xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured'] order by @value descending, @text descending";
- q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
- result = q.execute();
- checkResultOrder(result, new String[]{"node1", "node3", "node2"});
-
- // mixed ascending and descending
- sql = "SELECT value FROM nt:unstructured WHERE " +
- "jcr:path LIKE '" + testRoot + "/%' ORDER BY value DESC, text";
- q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
- result = q.execute();
- checkResultOrder(result, new String[]{"node1", "node2", "node3"});
-
- xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured'] order by @value descending, @text";
- q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
- result = q.execute();
- checkResultOrder(result, new String[]{"node1", "node2", "node3"});
- }
-
public void testOrderByScore() throws RepositoryException {
Node n1 = testRootNode.addNode("node1");
Node n2 = testRootNode.addNode("node2");
@@ -182,85 +51,4 @@
result = q.execute();
checkResult(result, 3);
}
-
- //------------------< internal >--------------------------------------------
-
- private void populate(String[] values) throws RepositoryException {
- for (int i = 0; i < values.length; i++) {
- Node node = testRootNode.addNode("node" + (i + 1));
- node.setProperty("value", values[i]);
- }
- testRootNode.save();
- }
-
- private void populate(Calendar[] values) throws RepositoryException {
- for (int i = 0; i < values.length; i++) {
- Node node = testRootNode.addNode("node" + (i + 1));
- node.setProperty("value", values[i]);
- }
- testRootNode.save();
- }
-
- private void populate(int[] values) throws RepositoryException {
- for (int i = 0; i < values.length; i++) {
- Node node = testRootNode.addNode("node" + (i + 1));
- node.setProperty("value", values[i]);
- }
- testRootNode.save();
- }
-
- private void populate(double[] values) throws RepositoryException {
- for (int i = 0; i < values.length; i++) {
- Node node = testRootNode.addNode("node" + (i + 1));
- node.setProperty("value", values[i]);
- }
- testRootNode.save();
- }
-
- private void checkOrder(int[] order) throws RepositoryException {
- String nodeNames[] = new String[order.length];
- for (int i = 0; i < order.length; i++) {
- nodeNames[i] = "node" + order[i];
- }
- // first check ascending
- String sql = "SELECT value FROM nt:unstructured WHERE " +
- "jcr:path LIKE '" + testRoot + "/%' ORDER BY value";
- Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
- QueryResult result = q.execute();
- checkResultOrder(result, nodeNames);
-
- String xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured'] order by @value";
- q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
- result = q.execute();
- checkResultOrder(result, nodeNames);
-
- // then check descending
- Collections.reverse(Arrays.asList(nodeNames));
-
- sql = "SELECT value FROM nt:unstructured WHERE " +
- "jcr:path LIKE '" + testRoot + "/%' ORDER BY value DESC";
- q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
- result = q.execute();
- checkResultOrder(result, nodeNames);
-
- xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured'] order by @value descending";
- q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
- result = q.execute();
- checkResultOrder(result, nodeNames);
- }
-
- private void checkResultOrder(QueryResult result, String[] nodeNames)
- throws RepositoryException {
- List nodes = new ArrayList();
- for (NodeIterator it = result.getNodes(); it.hasNext();) {
- nodes.add(it.nextNode());
- }
- assertEquals("Wrong hit count:", nodeNames.length, nodes.size());
-
- for (int i = 0; i < nodeNames.length; i++) {
- String name = ((Node) nodes.get(i)).getName();
- assertEquals("Wrong order of nodes:", nodeNames[i], name);
- }
- }
-
}
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractOrderByTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractOrderByTest.java?view=auto&rev=158783
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/AbstractOrderByTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/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 <code>true</code> this repository supports sql queries */
+ protected boolean checkSQL;
+
+ private String[] nodeNames;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ if (superuser.getRepository().getDescriptor(Repository.OPTION_QUERY_SQL_SUPPORTED) == null) {
+ checkSQL = false;
+ } else {
+ checkSQL = true;
+ }
+ nodeNames = new String[]{nodeName1, nodeName2, nodeName3, nodeName4};
+ }
+
+ /**
+ * Populates the workspace with child nodes under <code>testroot</code> with
+ * each node has a String value set in property with name
+ * <code>propertyname1</code>.
+ * @param values the String values.
+ */
+ protected void populate(String[] values) throws RepositoryException {
+ for (int i = 0; i < values.length; i++) {
+ Node node = testRootNode.addNode(nodeNames[i], testNodeType);
+ node.setProperty(propertyName1, values[i]);
+ }
+ testRootNode.save();
+ }
+
+ /**
+ * Populates the workspace with child nodes under <code>testroot</code> with
+ * each node has a calendar value set in property with name
+ * <code>propertyname1</code>.
+ * @param values the calendar values.
+ */
+ protected void populate(Calendar[] values) throws RepositoryException {
+ for (int i = 0; i < values.length; i++) {
+ Node node = testRootNode.addNode(nodeNames[i], testNodeType);
+ node.setProperty(propertyName1, values[i]);
+ }
+ testRootNode.save();
+ }
+
+ /**
+ * Populates the workspace with child nodes under <code>testroot</code> with
+ * each node has a long value set in property with name
+ * <code>propertyname1</code>.
+ * @param values the long values.
+ */
+ protected void populate(long[] values) throws RepositoryException {
+ for (int i = 0; i < values.length; i++) {
+ Node node = testRootNode.addNode(nodeNames[i], testNodeType);
+ node.setProperty(propertyName1, values[i]);
+ }
+ testRootNode.save();
+ }
+
+ /**
+ * Populates the workspace with child nodes under <code>testroot</code> with
+ * each node has a double value set in property with name
+ * <code>propertyname1</code>.
+ * @param values the double values.
+ */
+ protected void populate(double[] values) throws RepositoryException {
+ for (int i = 0; i < values.length; i++) {
+ Node node = testRootNode.addNode(nodeNames[i], testNodeType);
+ node.setProperty(propertyName1, values[i]);
+ }
+ testRootNode.save();
+ }
+
+ /**
+ * Runs queries on the workspace and checks if the ordering is according
+ * to the <code>nodeNames</code>.
+ * @param nodeNames the sequence of node names required in the result set.
+ */
+ protected void checkOrder(String[] nodeNames) throws RepositoryException {
+ // first check ascending
+
+ String sql = "SELECT " + propertyName1 + " FROM " + testNodeType + " WHERE " +
+ jcrPath + " LIKE '" + testRoot + "/%' ORDER BY " + propertyName1;
+ String xpath = "/" + jcrRoot + testRoot + "/*[@jcr:primaryType='" + testNodeType + "'] order by @" + propertyName1;
+ Query q;
+ QueryResult result;
+ if (checkSQL) {
+ q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
+ result = q.execute();
+ checkResultOrder(result, nodeNames);
+ }
+
+ q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
+ result = q.execute();
+ checkResultOrder(result, nodeNames);
+
+ // then check descending
+ Collections.reverse(Arrays.asList(nodeNames));
+
+ if (checkSQL) {
+ q = superuser.getWorkspace().getQueryManager().createQuery(sql + " DESC", Query.SQL);
+ result = q.execute();
+ checkResultOrder(result, nodeNames);
+ }
+
+ q = superuser.getWorkspace().getQueryManager().createQuery(xpath + " descending", Query.XPATH);
+ result = q.execute();
+ checkResultOrder(result, nodeNames);
+ }
+
+ /**
+ * Checks if the node ordering in <code>result</code> is according to
+ * <code>nodeNames</code>.
+ * @param result the query result.
+ * @param nodeNames the node names.
+ */
+ protected void checkResultOrder(QueryResult result, String[] nodeNames)
+ throws RepositoryException {
+ List nodes = new ArrayList();
+ for (NodeIterator it = result.getNodes(); it.hasNext();) {
+ nodes.add(it.nextNode());
+ }
+ assertEquals("Wrong hit count:", nodeNames.length, nodes.size());
+
+ for (int i = 0; i < nodeNames.length; i++) {
+ String name = ((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 = native
Modified: 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=diff&r1=158782&r2=158783
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/JcrPathTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/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 {
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByDateTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByDateTest.java?view=auto&rev=158783
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByDateTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/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
+ * <code>nodetype</code>
+ * @tck.config nodetype name of a node type
+ * @tck.config nodename1 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename2 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename3 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename4 name of a child node of type <code>nodetype</code>
+ * @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 = Calendar.getInstance();
+ c1.set(2000, 4, 20, 14, 35, 14);
+ Calendar c2 = Calendar.getInstance();
+ c2.set(2000, 5, 20, 14, 35, 14);
+ Calendar c3 = 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 = Calendar.getInstance();
+ c1.set(2000, 6, 12, 14, 35, 19);
+ c1.set(Calendar.MILLISECOND, 10);
+ Calendar c2 = Calendar.getInstance();
+ c2.set(2000, 6, 12, 14, 35, 19);
+ c2.set(Calendar.MILLISECOND, 9);
+ Calendar c3 = 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 = Calendar.getInstance(TimeZone.getTimeZone("GMT+1:00"));
+ c1.set(2000, 6, 12, 15, 35, 19);
+ c1.set(Calendar.MILLISECOND, 10);
+ Calendar c2 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ c2.set(2000, 6, 12, 14, 35, 19);
+ c2.set(Calendar.MILLISECOND, 9);
+ Calendar c3 = 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 = Calendar.getInstance(TimeZone.getTimeZone("GMT-1:00"));
+ c1.set(2000, 6, 12, 13, 35, 19);
+ c1.set(Calendar.MILLISECOND, 10);
+ Calendar c2 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ c2.set(2000, 6, 12, 14, 35, 19);
+ c2.set(Calendar.MILLISECOND, 9);
+ Calendar c3 = 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 = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByDoubleTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByDoubleTest.java?view=auto&rev=158783
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByDoubleTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/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
+ * <code>nodetype</code>
+ * @tck.config nodetype name of a node type
+ * @tck.config nodename1 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename2 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename3 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename4 name of a child node of type <code>nodetype</code>
+ * @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 = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByLongTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByLongTest.java?view=auto&rev=158783
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByLongTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/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
+ * <code>nodetype</code>
+ * @tck.config nodetype name of a node type
+ * @tck.config nodename1 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename2 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename3 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename4 name of a child node of type <code>nodetype</code>
+ * @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 = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByMultiTypeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByMultiTypeTest.java?view=auto&rev=158783
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByMultiTypeTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/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
+ * <code>nodetype</code>
+ * @tck.config nodetype name of a node type
+ * @tck.config nodename1 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename2 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename3 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename4 name of a child node of type <code>nodetype</code>
+ * @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 = testRootNode.addNode(nodeName1);
+ Node n2 = testRootNode.addNode(nodeName2);
+ Node n3 = 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 = "SELECT " + propertyName2 + " FROM " + testNodeType + " WHERE " +
+ jcrPath + " LIKE '" + testRoot + "/%' ORDER BY " + propertyName2 + ", " + propertyName1;
+ Query q;
+ QueryResult result;
+ if (checkSQL) {
+ q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
+ result = q.execute();
+ checkResultOrder(result, new String[]{nodeName2, nodeName3, nodeName1});
+ }
+
+ String xpath = "/" + testRoot + "/*[@" + jcrPrimaryType + "='" + testNodeType +
+ "'] order by @" + propertyName2 + ", @" + propertyName1;
+ q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
+ result = q.execute();
+ checkResultOrder(result, new String[]{nodeName2, nodeName3, nodeName1});
+
+ // both descending
+ sql = "SELECT " + propertyName2 + " FROM " + testNodeType + " WHERE " +
+ jcrPath + " LIKE '" + testRoot + "/%' ORDER BY " +
+ propertyName2 + " DESC, " +
+ propertyName1 + " DESC";
+ q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
+ result = q.execute();
+ checkResultOrder(result, new String[]{nodeName1, nodeName3, nodeName2});
+
+ xpath = "/" + jcrRoot + testRoot + "/*[@" + jcrPrimaryType + "='" +
+ testNodeType + "'] order by @" +
+ propertyName2 + " descending, @" +
+ propertyName1 + " descending";
+ q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
+ result = q.execute();
+ checkResultOrder(result, new String[]{nodeName1, nodeName3, nodeName2});
+
+ // mixed ascending and descending
+ sql = "SELECT " + propertyName2 + " FROM " + testNodeType + " WHERE " +
+ jcrPath + " LIKE '" + testRoot + "/%' ORDER BY " +
+ propertyName2 + " DESC, " + propertyName1;
+ q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
+ result = q.execute();
+ checkResultOrder(result, new String[]{nodeName1, nodeName2, nodeName3});
+
+ xpath = "/" + jcrRoot + testRoot + "/*[@" + jcrPrimaryType + "='" +
+ testNodeType + "'] order by @" + propertyName2 +
+ " descending, @" + propertyName1;
+ q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
+ result = q.execute();
+ checkResultOrder(result, new String[]{nodeName1, nodeName2, nodeName3});
+ }
+}
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByMultiTypeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByStringTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByStringTest.java?view=auto&rev=158783
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/OrderByStringTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/query/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
+ * <code>nodetype</code>
+ * @tck.config nodetype name of a node type
+ * @tck.config nodename1 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename2 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename3 name of a child node of type <code>nodetype</code>
+ * @tck.config nodename4 name of a child node of type <code>nodetype</code>
+ * @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 = 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=158782&r2=158783
==============================================================================
--- 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 23 07:29:49 2005
@@ -59,6 +59,12 @@
suite.addTestSuite(PredicatesTest.class);
suite.addTestSuite(SimpleSelectionTest.class);
+ suite.addTestSuite(OrderByDateTest.class);
+ suite.addTestSuite(OrderByDoubleTest.class);
+ suite.addTestSuite(OrderByLongTest.class);
+ suite.addTestSuite(OrderByMultiTypeTest.class);
+ suite.addTestSuite(OrderByStringTest.class);
+
return suite;
}
}