directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lucasthei...@apache.org
Subject svn commit: r1654581 - in /directory/shared/trunk/ldap/client/api/src: main/java/org/apache/directory/ldap/client/api/search/ test/java/org/apache/directory/ldap/client/api/search/
Date Sat, 24 Jan 2015 21:39:59 GMT
Author: lucastheisen
Date: Sat Jan 24 21:39:58 2015
New Revision: 1654581

URL: http://svn.apache.org/r1654581
Log:
DIRAPI-165: Add a FilterBuillder


Added:
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AbstractFilter.java
  (with props)
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeFilter.java
  (with props)
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java
  (with props)
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/Filter.java
  (with props)
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterBuilder.java
  (with props)
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilter.java
  (with props)
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/UnaryFilter.java
  (with props)
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/AttributeFilterTest.java
  (with props)
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionTest.java
  (with props)
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/FilterBuilderTest.java
  (with props)
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilterTest.java
  (with props)
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/UnaryFilterTest.java
  (with props)

Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AbstractFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AbstractFilter.java?rev=1654581&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AbstractFilter.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AbstractFilter.java
Sat Jan 24 21:39:58 2015
@@ -0,0 +1,11 @@
+
+package org.apache.directory.ldap.client.api.search;
+
+abstract class AbstractFilter implements Filter
+{
+    @Override
+    public StringBuilder build()
+    {
+        return build( new StringBuilder() );
+    }
+}

Propchange: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AbstractFilter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeFilter.java?rev=1654581&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeFilter.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeFilter.java
Sat Jan 24 21:39:58 2015
@@ -0,0 +1,48 @@
+package org.apache.directory.ldap.client.api.search;
+
+
+class AttributeFilter extends AbstractFilter
+{
+    private String attribute;
+    private Operator operator;
+
+
+    private AttributeFilter( String attribute, Operator operator )
+    {
+        this.attribute = attribute;
+        this.operator = operator;
+    }
+
+
+    public static AttributeFilter present( String attribute )
+    {
+        return new AttributeFilter( attribute, Operator.PRESENT );
+    }
+
+
+    @Override
+    public StringBuilder build( StringBuilder builder )
+    {
+        return builder.append( "(" ).append( attribute )
+            .append( operator.operator() ).append( ")" );
+    }
+
+    public static enum Operator
+    {
+        PRESENT("=*");
+
+        private String operator;
+
+
+        private Operator( String operator )
+        {
+            this.operator = operator;
+        }
+
+
+        public String operator()
+        {
+            return operator;
+        }
+    }
+}
\ No newline at end of file

Propchange: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeFilter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java?rev=1654581&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java
Sat Jan 24 21:39:58 2015
@@ -0,0 +1,72 @@
+
+package org.apache.directory.ldap.client.api.search;
+
+
+class AttributeValueAssertionFilter extends AbstractFilter
+{
+    private String attribute;
+    private String value;
+    private Operator operator;
+    
+    
+    private AttributeValueAssertionFilter( String attribute, String value, Operator operator
)
+    {
+        this.attribute = attribute;
+        this.value = value;
+        this.operator = operator;
+    }
+    
+    
+    public static AttributeValueAssertionFilter approximatelyEqual( String attribute, String
value ) 
+    {
+        return new AttributeValueAssertionFilter( attribute, value, Operator.APPROXIMATELY_EQUAL
);
+    }
+    
+    
+    public static AttributeValueAssertionFilter equal( String attribute, String value ) 
+    {
+        return new AttributeValueAssertionFilter( attribute, value, Operator.EQUAL );
+    }
+    
+    
+    public static AttributeValueAssertionFilter greaterThanOrEqual( String attribute, String
value ) 
+    {
+        return new AttributeValueAssertionFilter( attribute, value, Operator.GREATER_THAN_OR_EQUAL
);
+    }
+    
+    
+    public static AttributeValueAssertionFilter lessThanOrEqual( String attribute, String
value ) 
+    {
+        return new AttributeValueAssertionFilter( attribute, value, Operator.LESS_THAN_OR_EQUAL
);
+    }
+    
+
+    @Override
+    public StringBuilder build( StringBuilder builder )
+    {
+        return builder.append( "(" ).append( attribute )
+                .append( operator.operator() )
+                .append( value ).append( ")" );
+    }
+
+
+    public static enum Operator
+    {
+        APPROXIMATELY_EQUAL("~="),
+        EQUAL("="),
+        GREATER_THAN_OR_EQUAL(">="),
+        LESS_THAN_OR_EQUAL("<=");
+        
+        private String operator;
+        
+        private Operator( String operator ) 
+        {
+            this.operator = operator;
+        }
+        
+        public String operator() 
+        {
+            return operator;
+        }
+    }
+}
\ No newline at end of file

Propchange: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/Filter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/Filter.java?rev=1654581&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/Filter.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/Filter.java
Sat Jan 24 21:39:58 2015
@@ -0,0 +1,10 @@
+package org.apache.directory.ldap.client.api.search;
+
+
+interface Filter
+{
+    public StringBuilder build();
+
+
+    public StringBuilder build( StringBuilder builder );
+}
\ No newline at end of file

Propchange: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/Filter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterBuilder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterBuilder.java?rev=1654581&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterBuilder.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterBuilder.java
Sat Jan 24 21:39:58 2015
@@ -0,0 +1,259 @@
+package org.apache.directory.ldap.client.api.search;
+
+
+/**
+ * A builder for constructing well formed search filters according to
+ * <a href="https://tools.ietf.org/html/rfc1960.html">RFC 1960</a>.  This 
+ * builder is most convenient when you use static imports.  For example:
+ * <pre>
+ * import static org.apache.directory.ldap.client.api.search.FilterBuilder.and;
+ * import static org.apache.directory.ldap.client.api.search.FilterBuilder.equal;
+ * import static org.apache.directory.ldap.client.api.search.FilterBuilder.or;
+ * 
+ * ...
+ * 
+ *         String filter = 
+ *                 or(
+ *                     and( 
+ *                         equal( "givenName", "kermit" ), 
+ *                         equal( "sn", "the frog" ) ),
+ *                     and( 
+ *                         equal( "givenName", "miss" ), 
+ *                         equal( "sn", "piggy" ) ) )
+ *                 .toString()
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class FilterBuilder
+{
+    private Filter filter;
+
+
+    private FilterBuilder( Filter filter )
+    {
+        this.filter = filter;
+    }
+
+
+    /**
+     * Returns a new FilterBuilder that will <code>&</code> together all
of the 
+     * supplied filters.  For example:
+     * 
+     * <pre>
+     * and( equal( "givenName", "kermit" ), equal( "sn", "the frog" ) ).toString()
+     * </pre>
+     * would result in the string:
+     * <pre>
+     * (&(givenName=kermit)(sn=the frog))
+     * </pre>
+     * 
+     * Which would match all entries with a given name of <code>kermit</code>
+     * and a surname <code>the frog</code>.
+     *
+     * @param filters The filters to and together
+     * @return A new FilterBuilder
+     */
+    public static FilterBuilder and( FilterBuilder... filters )
+    {
+        SetOfFiltersFilter filter = SetOfFiltersFilter.and();
+        for ( FilterBuilder builder : filters )
+        {
+            filter.add( builder.filter() );
+        }
+        return new FilterBuilder( filter );
+    }
+
+
+    /**
+     * Returns a new FilterBuilder for testing the approximate equality of an 
+     * attribute. For example:
+     * 
+     * <pre>
+     * approximatelyEqual( "l", "san fransico" ).toString();
+     * </pre>
+     * would result in the string:
+     * <pre>
+     * (l~=san fransico)
+     * </pre>
+     * 
+     * Which <i>MIGHT</i> match results whose locality is 
+     * <code>San Francisco</code>.  The matching rule used to apply this filter
+     * is dependent on the server implementation.
+     *
+     * @param attribute The attribute 
+     * @param value The value
+     * @return A new FilterBuilder
+     */
+    public static FilterBuilder approximatelyEqual( String attribute, String value )
+    {
+        return new FilterBuilder( AttributeValueAssertionFilter.approximatelyEqual( attribute,
value ) );
+    }
+
+
+    /**
+     * Returns a new FilterBuilder for testing equality of an attribute. For 
+     * example:
+     * 
+     * <pre>
+     * equal( "cn", "Kermit The Frog" ).toString();
+     * </pre>
+     * would result in the string:
+     * <pre>
+     * (cn>=Kermit The Frog)
+     * </pre>
+     * 
+     * Which would match entries with the common name 
+     * <code>Kermit The Frog</code>.
+     *
+     * @param attribute The attribute 
+     * @param value The value
+     * @return A new FilterBuilder
+     */
+    public static FilterBuilder equal( String attribute, String value )
+    {
+        return new FilterBuilder( AttributeValueAssertionFilter.equal( attribute, value )
);
+    }
+
+
+    private Filter filter()
+    {
+        return filter;
+    }
+
+
+    /**
+     * Returns a new FilterBuilder for testing lexicographical greater than.  
+     * For example:
+     * 
+     * <pre>
+     * greaterThanOrEqual( "sn", "n" ).toString();
+     * </pre>
+     * would result in the string:
+     * <pre>
+     * (sn>=n)
+     * </pre>
+     * 
+     * which would match results whose surname starts with the second half of
+     * the alphabet.  
+     *
+     * @param attribute The attribute 
+     * @param value The value
+     * @return A new FilterBuilder
+     */
+    public static FilterBuilder greaterThanOrEqual( String attribute, String value )
+    {
+        return new FilterBuilder( AttributeValueAssertionFilter.greaterThanOrEqual( attribute,
value ) );
+    }
+
+
+    /**
+     * Returns a new FilterBuilder for testing lexicographical less than.  For
+     * example:
+     * 
+     * <pre>
+     * lessThanOrEqual( "sn", "mzzzzzz" ).toString();
+     * </pre>
+     * would result in the string:
+     * <pre>
+     * (sn<=mzzzzzz)
+     * </pre>
+     * 
+     * which would match results whose surname starts with the first half of
+     * the alphabet.  <i>Note, this is not perfect, but if you know anybody with
+     * a last name that starts with an <code>m</code> followed by six
+     * <code>z</code>'s...</i>
+     *
+     * @param attribute The attribute 
+     * @param value The value
+     * @return A new FilterBuilder
+     */
+    public static FilterBuilder lessThanOrEqual( String attribute, String value )
+    {
+        return new FilterBuilder( AttributeValueAssertionFilter.lessThanOrEqual( attribute,
value ) );
+    }
+
+
+    /**
+     * Returns a new FilterBuilder for negating another filter.  For example:
+     * 
+     * <pre>
+     * not( present( "givenName" ) ).toString();
+     * </pre>
+     * would result in the string:
+     * <pre>
+     * (!(givenName=*))
+     * </pre>
+     *
+     * @param filter The filter to negate
+     * @return A new FilterBuilder
+     */
+    public static FilterBuilder not( FilterBuilder filter )
+    {
+        return new FilterBuilder( UnaryFilter.not( filter.filter() ) );
+    }
+
+
+    /**
+     * Returns a new FilterBuilder that will <code>|</code> together all of the

+     * supplied filters.  For example:
+     * 
+     * <pre>
+     * or( equal( "givenName", "kermit" ), equal( "givenName", "walter" ) ).toString()
+     * </pre>
+     * would result in the string:
+     * <pre>
+     * (|(givenName=kermit)(givenName=walter))
+     * </pre>
+     * 
+     * Which would match any entry with the <code>givenName</code> of either
+     * <code>kermit</code> or <code>walter</code>.
+     *
+     * @param filters The filters to or together
+     * @return A new FilterBuilder
+     */
+    public static FilterBuilder or( FilterBuilder... filters )
+    {
+        SetOfFiltersFilter filter = SetOfFiltersFilter.or();
+        for ( FilterBuilder builder : filters )
+        {
+            filter.add( builder.filter() );
+        }
+        return new FilterBuilder( filter );
+    }
+
+
+    /**
+     * Returns a new FilterBuilder for testing the presence of an attributes.  
+     * For example:
+     * 
+     * <pre>
+     * present( "givenName" ).toString();
+     * </pre>
+     * would result in the string:
+     * <pre>
+     * (givenName=*)
+     * </pre>
+     * 
+     * Which would match any entry that has a <code>givenName</code> attribute.
+     *
+     * @param attribute The attribute to test the presence of
+     * @return A new FilterBuilder
+     */
+    public static FilterBuilder present( String attribute )
+    {
+        return new FilterBuilder( AttributeFilter.present( attribute ) );
+    }
+
+
+    /**
+     * Returns the string version of the filter represented by this FilterBuilder.
+     * 
+     * @return The string representation of the filter
+     */
+    @Override
+    public String toString()
+    {
+        return filter.build().toString();
+    }
+}

Propchange: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterBuilder.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilter.java?rev=1654581&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilter.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilter.java
Sat Jan 24 21:39:58 2015
@@ -0,0 +1,92 @@
+package org.apache.directory.ldap.client.api.search;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+class SetOfFiltersFilter extends AbstractFilter
+{
+    private Operator operator;
+    private List<Filter> filters;
+
+
+    private SetOfFiltersFilter( Operator operator )
+    {
+        this.operator = operator;
+        this.filters = new ArrayList<Filter>();
+    }
+
+
+    public SetOfFiltersFilter add( Filter filter )
+    {
+        filters.add( filter );
+        return this;
+    }
+
+
+    public SetOfFiltersFilter addAll( Filter... filters )
+    {
+        for ( Filter filter : filters )
+        {
+            this.filters.add( filter );
+        }
+        return this;
+    }
+
+
+    public SetOfFiltersFilter addAll( List<Filter> filters )
+    {
+        this.filters.addAll( filters );
+        return this;
+    }
+
+
+    public static SetOfFiltersFilter and( Filter... filters )
+    {
+        return new SetOfFiltersFilter( Operator.AND ).addAll( filters );
+    }
+
+
+    public static SetOfFiltersFilter or( Filter... filters )
+    {
+        return new SetOfFiltersFilter( Operator.OR ).addAll( filters );
+    }
+
+
+    @Override
+    public StringBuilder build( StringBuilder builder )
+    {
+        if ( filters.isEmpty() )
+        {
+            throw new IllegalStateException( "at least one filter required" );
+        }
+
+        builder.append( "(" ).append( operator.operator() );
+        for ( Filter filter : filters )
+        {
+            filter.build( builder );
+        }
+        return builder.append( ")" );
+    }
+
+    public static enum Operator
+    {
+        AND("&"),
+        OR("|");
+
+        private String operator;
+
+
+        private Operator( String operator )
+        {
+            this.operator = operator;
+        }
+
+
+        public String operator()
+        {
+            return operator;
+        }
+    }
+}
\ No newline at end of file

Propchange: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/UnaryFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/UnaryFilter.java?rev=1654581&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/UnaryFilter.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/UnaryFilter.java
Sat Jan 24 21:39:58 2015
@@ -0,0 +1,66 @@
+package org.apache.directory.ldap.client.api.search;
+
+
+class UnaryFilter extends AbstractFilter
+{
+    private Operator operator;
+    private Filter filter;
+
+
+    private UnaryFilter( Operator operator )
+    {
+        this.operator = operator;
+    }
+
+
+    public UnaryFilter setFilter( Filter filter )
+    {
+        this.filter = filter;
+        return this;
+    }
+
+
+    public static UnaryFilter not()
+    {
+        return new UnaryFilter( Operator.NOT );
+    }
+
+
+    public static UnaryFilter not( Filter filter )
+    {
+        return not().setFilter( filter );
+    }
+
+
+    @Override
+    public StringBuilder build( StringBuilder builder )
+    {
+        if ( filter == null )
+        {
+            throw new IllegalStateException( "filter not set" );
+        }
+
+        builder.append( "(" ).append( operator.operator() );
+        filter.build( builder );
+        return builder.append( ")" );
+    }
+
+    public static enum Operator
+    {
+        NOT("!");
+
+        private String operator;
+
+
+        private Operator( String operator )
+        {
+            this.operator = operator;
+        }
+
+
+        public String operator()
+        {
+            return operator;
+        }
+    }
+}
\ No newline at end of file

Propchange: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/UnaryFilter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/AttributeFilterTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/AttributeFilterTest.java?rev=1654581&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/AttributeFilterTest.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/AttributeFilterTest.java
Sat Jan 24 21:39:58 2015
@@ -0,0 +1,17 @@
+
+package org.apache.directory.ldap.client.api.search;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class AttributeFilterTest
+{
+    @Test
+    public void testPresent() {
+        assertEquals( "(objectClass=*)", AttributeFilter.present( "objectClass" ).build().toString()
);
+        assertEquals( "(uid=*)", AttributeFilter.present( "uid" ).build().toString() );
+        assertEquals( "(userPassword=*)", AttributeFilter.present( "userPassword" ).build().toString()
);
+        assertEquals( "(cn=*)", AttributeFilter.present( "cn" ).build().toString() );
+    }
+}

Propchange: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/AttributeFilterTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionTest.java?rev=1654581&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionTest.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionTest.java
Sat Jan 24 21:39:58 2015
@@ -0,0 +1,60 @@
+package org.apache.directory.ldap.client.api.search;
+
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+
+public class AttributeValueAssertionTest
+{
+    @Test
+    public void testApproximatelyEqual()
+    {
+        assertEquals( "(objectClass~=person)",
+            AttributeValueAssertionFilter.approximatelyEqual( "objectClass", "person" )
+                .build().toString() );
+        assertEquals( "(uid~=admin)",
+            AttributeValueAssertionFilter.approximatelyEqual( "uid", "admin" )
+                .build().toString() );
+    }
+    
+    
+    @Test
+    public void testEqual()
+    {
+        assertEquals( "(objectClass=person)",
+            AttributeValueAssertionFilter.equal( "objectClass", "person" )
+                .build().toString() );
+        assertEquals( "(uid=admin)",
+            AttributeValueAssertionFilter.equal( "uid", "admin" )
+                .build().toString() );
+        assertEquals( "(cn=lu*)",
+            AttributeValueAssertionFilter.equal( "cn", "lu*" )
+                .build().toString() );
+    }
+    
+    
+    @Test
+    public void testGreaterThanOrEqual()
+    {
+        assertEquals( "(objectClass>=person)",
+            AttributeValueAssertionFilter.greaterThanOrEqual( "objectClass", "person" )
+                .build().toString() );
+        assertEquals( "(uid>=admin)",
+            AttributeValueAssertionFilter.greaterThanOrEqual( "uid", "admin" )
+                .build().toString() );
+    }
+    
+    
+    @Test
+    public void testLessThanOrEqual()
+    {
+        assertEquals( "(objectClass<=person)",
+            AttributeValueAssertionFilter.lessThanOrEqual( "objectClass", "person" )
+                .build().toString() );
+        assertEquals( "(uid<=admin)",
+            AttributeValueAssertionFilter.lessThanOrEqual( "uid", "admin" )
+                .build().toString() );
+    }
+}

Propchange: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/FilterBuilderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/FilterBuilderTest.java?rev=1654581&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/FilterBuilderTest.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/FilterBuilderTest.java
Sat Jan 24 21:39:58 2015
@@ -0,0 +1,26 @@
+package org.apache.directory.ldap.client.api.search;
+
+
+import static org.apache.directory.ldap.client.api.search.FilterBuilder.and;
+import static org.apache.directory.ldap.client.api.search.FilterBuilder.equal;
+import static org.apache.directory.ldap.client.api.search.FilterBuilder.not;
+import static org.apache.directory.ldap.client.api.search.FilterBuilder.or;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+
+public class FilterBuilderTest
+{
+    @Test
+    public void testFilterBuilder()
+    {
+        assertEquals( "(cn=Babs Jensen)", equal( "cn", "Babs Jensen" ).toString() );
+        assertEquals( "(!(cn=Tim Howes))", not( equal( "cn", "Tim Howes" ) ).toString() );
+        assertEquals( "(&(objectClass=Person)(|(sn=Jensen)(cn=Babs J*)))",
+            and( equal( "objectClass", "Person" ),
+                or( equal( "sn", "Jensen" ),
+                    equal( "cn", "Babs J*" ) ) ).toString() );
+        assertEquals( "(o=univ*of*mich*)", equal( "o", "univ*of*mich*" ).toString() );
+    }
+}

Propchange: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/FilterBuilderTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilterTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilterTest.java?rev=1654581&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilterTest.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilterTest.java
Sat Jan 24 21:39:58 2015
@@ -0,0 +1,83 @@
+package org.apache.directory.ldap.client.api.search;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+
+import org.junit.Test;
+
+
+public class SetOfFiltersFilterTest
+{
+    private String expected( SetOfFiltersFilter.Operator operator, Filter... filters )
+    {
+        StringBuilder builder = new StringBuilder( "(" )
+            .append( operator.operator() );
+        for ( Filter filter : filters )
+        {
+            filter.build( builder );
+        }
+        return builder.append( ")" ).toString();
+    }
+
+
+    @Test
+    public void testAnd()
+    {
+        AttributeFilter attributeFilter = AttributeFilter.present( "objectClass" );
+        AttributeValueAssertionFilter attributeValueAssertionFilter =
+            AttributeValueAssertionFilter.equal( "objectClass", "person" );
+        String expected = expected( SetOfFiltersFilter.Operator.AND, attributeFilter, attributeValueAssertionFilter
);
+
+        assertEquals( expected,
+            SetOfFiltersFilter.and( attributeFilter, attributeValueAssertionFilter )
+                .build().toString() );
+
+        assertEquals( expected,
+            SetOfFiltersFilter.and()
+                .add( attributeFilter )
+                .add( attributeValueAssertionFilter )
+                .build().toString() );
+
+        assertEquals( expected,
+            SetOfFiltersFilter.and()
+                .addAll( attributeFilter, attributeValueAssertionFilter )
+                .build().toString() );
+
+        assertEquals( expected,
+            SetOfFiltersFilter.and()
+                .addAll( Arrays.asList( ( Filter ) attributeFilter, ( Filter ) attributeValueAssertionFilter
) )
+                .build().toString() );
+    }
+
+
+    @Test
+    public void testOr()
+    {
+        AttributeFilter attributeFilter = AttributeFilter.present( "objectClass" );
+        AttributeValueAssertionFilter attributeValueAssertionFilter =
+            AttributeValueAssertionFilter.equal( "objectClass", "person" );
+        String expected = expected( SetOfFiltersFilter.Operator.OR, attributeFilter, attributeValueAssertionFilter
);
+
+        assertEquals( expected,
+            SetOfFiltersFilter.or( attributeFilter, attributeValueAssertionFilter )
+                .build().toString() );
+
+        assertEquals( expected,
+            SetOfFiltersFilter.or()
+                .add( attributeFilter )
+                .add( attributeValueAssertionFilter )
+                .build().toString() );
+
+        assertEquals( expected,
+            SetOfFiltersFilter.or()
+                .addAll( attributeFilter, attributeValueAssertionFilter )
+                .build().toString() );
+
+        assertEquals( expected,
+            SetOfFiltersFilter.or()
+                .addAll( Arrays.asList( ( Filter ) attributeFilter, ( Filter ) attributeValueAssertionFilter
) )
+                .build().toString() );
+    }
+}

Propchange: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilterTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/UnaryFilterTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/UnaryFilterTest.java?rev=1654581&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/UnaryFilterTest.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/UnaryFilterTest.java
Sat Jan 24 21:39:58 2015
@@ -0,0 +1,27 @@
+package org.apache.directory.ldap.client.api.search;
+
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+
+public class UnaryFilterTest
+{
+    @Test
+    public void testNot()
+    {
+        AttributeFilter attributeFilter = AttributeFilter.present( "objectClass" );
+        assertEquals( "(!" + attributeFilter.build().toString() + ")",
+            UnaryFilter.not( attributeFilter ).build().toString() );
+        assertEquals( "(!" + attributeFilter.build().toString() + ")",
+            UnaryFilter.not().setFilter( attributeFilter ).build().toString() );
+
+        AttributeValueAssertionFilter attributeValueAssertionFilter =
+            AttributeValueAssertionFilter.equal( "objectClass", "person" );
+        assertEquals( "(!" + attributeValueAssertionFilter.build().toString() + ")",
+            UnaryFilter.not( attributeValueAssertionFilter ).build().toString() );
+        assertEquals( "(!" + attributeValueAssertionFilter.build().toString() + ")",
+            UnaryFilter.not().setFilter( attributeValueAssertionFilter ).build().toString()
);
+    }
+}

Propchange: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/UnaryFilterTest.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message