jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1512281 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryBuilder.java oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserQueryTest.java
Date Fri, 09 Aug 2013 12:29:00 GMT
Author: angela
Date: Fri Aug  9 12:29:00 2013
New Revision: 1512281

URL: http://svn.apache.org/r1512281
Log:
OAK-50: user mgt

- ensure backward compatible behavior of querybuilder#setLimit which used to allow -1 to indicate
that the max number of result should not be limited.
- tests asserting the same results with maxCount being set to Long.MAX_VALUE and -1 both with
and without limiting the scope of the result to a given group (-> different test executing
in the code).

- use constants

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryBuilder.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserQueryTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryBuilder.java?rev=1512281&r1=1512280&r2=1512281&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryBuilder.java
Fri Aug  9 12:29:00 2013
@@ -77,7 +77,7 @@ class XPathQueryBuilder implements Query
         // reset the offset before setting bound value/maxCount
         offset = 0;
         this.bound = bound;
-        this.maxCount = maxCount;
+        setMaxCount(maxCount);
     }
 
     @Override
@@ -85,7 +85,7 @@ class XPathQueryBuilder implements Query
         // reset the bound value before setting offset/maxCount
         bound = null;
         this.offset = offset;
-        this.maxCount = maxCount;
+        setMaxCount(maxCount);
     }
 
     @Override
@@ -203,4 +203,12 @@ class XPathQueryBuilder implements Query
     long getMaxCount() {
         return maxCount;
     }
+
+    private void setMaxCount(long maxCount) {
+        if (maxCount == -1) {
+            this.maxCount = Long.MAX_VALUE;
+        } else {
+            this.maxCount = maxCount;
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserQueryTest.java?rev=1512281&r1=1512280&r2=1512281&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserQueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserQueryTest.java
Fri Aug  9 12:29:00 2013
@@ -753,6 +753,54 @@ public class UserQueryTest extends Abstr
         assertFalse(result.hasNext());
     }
 
+    @Test
+    public void testMaxCount() throws Exception {
+        final long count = Long.MAX_VALUE;
+        final long countjr2 = -1; // in jackrabbit -1 could be used to set no limit
+
+        Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {
+            public <T> void build(QueryBuilder<T> builder) {
+                builder.setSortOrder("profile/@weight", QueryBuilder.Direction.ASCENDING);
+                builder.setLimit(0, countjr2);
+            }
+        });
+
+        Iterator<Authorizable> expected = userMgr.findAuthorizables(new Query() {
+            public <T> void build(QueryBuilder<T> builder) {
+                builder.setSortOrder("profile/@weight", QueryBuilder.Direction.ASCENDING);
+                builder.setLimit(0, count);
+            }
+        });
+
+        assertSame(expected, result, count);
+        assertFalse(result.hasNext());
+    }
+
+    @Test
+    public void testMaxCountWithScope() throws Exception {
+        final long count = Long.MAX_VALUE;
+        final long countjr2 = -1; // in jackrabbit -1 could be used to set no limit
+
+        Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {
+            public <T> void build(QueryBuilder<T> builder) {
+                builder.setSortOrder("profile/@weight", QueryBuilder.Direction.ASCENDING);
+                builder.setScope("vertebrates", false);
+                builder.setLimit(0, countjr2);
+            }
+        });
+
+        Iterator<Authorizable> expected = userMgr.findAuthorizables(new Query() {
+            public <T> void build(QueryBuilder<T> builder) {
+                builder.setSortOrder("profile/@weight", QueryBuilder.Direction.ASCENDING);
+                builder.setScope("vertebrates", false);
+                builder.setLimit(0, count);
+            }
+        });
+
+        assertSame(expected, result, count);
+        assertFalse(result.hasNext());
+    }
+
     //------------------------------------------------------------< private >---
 
     private static void addMembers(Group group, Authorizable... authorizables) throws RepositoryException
{



Mime
View raw message