directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 21193 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap java/org/apache/snickers/ldap/search test/org/apache/snickers/ldap/search
Date Mon, 14 Jun 2004 07:38:21 GMT
Author: akarasulu
Date: Mon Jun 14 00:38:21 2004
New Revision: 21193

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/AndRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/OrRule.java
  (contents, props changed)
Modified:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/search/SearchRequestTest.java
Log:
oops

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
Mon Jun 14 00:38:21 2004
@@ -234,9 +234,16 @@
         // End Extensible match filter rules
         //
 
-        // NOT filter expresion rules
+        //
+        // Branch filter expresion rules
+        //
+
         pattern = new int[2];
         pattern[0] = TagTree.WILDCARD;
+        pattern[1] = LdapTag.CONTEXT_SPECIFIC_TAG_0.getPrimitiveTag();
+        digester.addRule( pattern, new AndRule() );
+        pattern[1] = LdapTag.CONTEXT_SPECIFIC_TAG_1.getPrimitiveTag();
+        digester.addRule( pattern, new OrRule() );
         pattern[1] = LdapTag.CONTEXT_SPECIFIC_TAG_2.getPrimitiveTag();
         digester.addRule( pattern, new NotRule() );
     }

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/AndRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/AndRule.java
Mon Jun 14 00:38:21 2004
@@ -0,0 +1,141 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   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.snickers.ldap.search;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.snickers.ber.digester.AbstractRule;
+import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ldap.LdapTag;
+import org.apache.ldap.common.filter.BranchNode;
+import org.apache.ldap.common.filter.ExprNode;
+
+
+/**
+ * A rule used to build filter expressions that are AND'ed using the '&'
+ * operator.  This rule pops the stack for its arguments which it
+ * checks to see is a filter expression tree node of the type ExprNode.  This
+ * rule will consume all expression nodes on the stack until it reaches an
+ * object stack element that is not of the ExprNode class.  It uses these
+ * expression nodes to construct a anded expression with it, and pushes
+ * the newly created AND'ed node onto the stack.  This rule also makes sure
+ * that it is enabled only under a search request.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class AndRule extends AbstractRule
+{
+    private boolean isEnabled = true;
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        // check to see we are within limits - have the right number of tags
+        int tagCount = getDigester().getTagCount();
+        if ( tagCount < 3 )
+        {
+            this.isEnabled = false;
+            return;
+        }
+
+        /*
+         * check to see that we're dealing within a search request - this is
+         * done by making sure the tag right above the bottom tag is equal
+         * to the SEARCH_REQUEST tag. If not we must disable this rule.
+         */
+        if ( getDigester().getTag( tagCount - 2 ) !=
+                LdapTag.SEARCH_REQUEST.getPrimitiveTag() )
+        {
+            this.isEnabled = false;
+            return;
+        }
+
+        /*
+         * This rule is registered using [*, 0x80000000] which matches all
+         * context sensitive 0 tags in the search request.  This makes it
+         * cross react with substring match expression components.  We need to
+         * check if the next tags in stack are equal to substring match context
+         * specific tags to see if we need to disable this rule.
+         */
+        if
+        (
+            getDigester().getTag( 2 ) ==
+                LdapTag.CONTEXT_SPECIFIC_TAG_4.getPrimitiveTag()
+        )
+        {
+            this.isEnabled = false ;
+            return ;
+        }
+
+        super.tag( id, isPrimitive, typeClass );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( isEnabled )
+        {
+            super.length( length );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        if ( isEnabled )
+        {
+            super.value( buf );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        if ( isEnabled )
+        {
+            super.finish();
+
+            BranchNode node;
+            node = new BranchNode( BranchNode.AND );
+
+            while( getDigester().peek() instanceof ExprNode )
+            {
+                node.addNode( ( ExprNode ) getDigester().pop() );
+            }
+
+            getDigester().push( node );
+        }
+
+        this.isEnabled = true;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/OrRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/search/OrRule.java
Mon Jun 14 00:38:21 2004
@@ -0,0 +1,143 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   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.snickers.ldap.search;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.snickers.ber.digester.AbstractRule;
+import org.apache.snickers.ber.TypeClass;
+import org.apache.snickers.ldap.LdapTag;
+import org.apache.ldap.common.filter.BranchNode;
+import org.apache.ldap.common.filter.ExprNode;
+
+
+/**
+ * A rule used to build filter expressions that are OR'ed using the '|'
+ * operator.  This rule pops the stack for its arguments which it
+ * checks to see is a filter expression tree node of the type ExprNode.  This
+ * rule will consume all expression nodes on the stack until it reaches an
+ * object stack element that is not of the ExprNode class.  It uses these
+ * expression nodes to construct a anded expression with it, and pushes
+ * the newly created OR'ed node onto the stack.  This rule also makes sure
+ * that it is enabled only under a search request.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class OrRule extends AbstractRule
+{
+    private boolean isEnabled = true;
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        // check to see we are within limits - have the right number of tags
+        int tagCount = getDigester().getTagCount();
+        if ( tagCount < 3 )
+        {
+            this.isEnabled = false;
+            return;
+        }
+
+        /*
+         * check to see that we're dealing within a search request - this is
+         * done by making sure the tag right above the bottom tag is equal
+         * to the SEARCH_REQUEST tag. If not we must disable this rule.
+         */
+        if ( getDigester().getTag( tagCount - 2 ) !=
+                LdapTag.SEARCH_REQUEST.getPrimitiveTag() )
+        {
+            this.isEnabled = false;
+            return;
+        }
+
+        /*
+         * This rule is registered using [*, 0x81000000] which matches all
+         * context sensitive 0 tags in the search request.  This makes it
+         * cross react with substring match expression components.  We need to
+         * check if the next tags in stack are equal to substring match context
+         * specific tags to see if we need to disable this rule.
+         */
+        if
+        (
+            getDigester().getTag( 2 ) ==
+                LdapTag.CONTEXT_SPECIFIC_TAG_4.getPrimitiveTag() ||
+            getDigester().getTag( 1 ) ==
+                LdapTag.CONTEXT_SPECIFIC_TAG_9.getPrimitiveTag()
+        )
+        {
+            this.isEnabled = false ;
+            return ;
+        }
+
+        super.tag( id, isPrimitive, typeClass );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( isEnabled )
+        {
+            super.length( length );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        if ( isEnabled )
+        {
+            super.value( buf );
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        if ( isEnabled )
+        {
+            super.finish();
+
+            BranchNode node;
+            node = new BranchNode( BranchNode.OR );
+
+            while( getDigester().peek() instanceof ExprNode )
+            {
+                node.addNode( ( ExprNode ) getDigester().pop() );
+            }
+
+            getDigester().push( node );
+        }
+
+        this.isEnabled = true;
+    }
+}

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/search/SearchRequestTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/search/SearchRequestTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/search/SearchRequestTest.java
Mon Jun 14 00:38:21 2004
@@ -20,6 +20,7 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.ArrayList;
+import java.util.Collections;
 
 import org.apache.ldap.common.message.*;
 import org.apache.ldap.common.filter.*;
@@ -37,6 +38,23 @@
  */
 public class SearchRequestTest extends RuleTestCase
 {
+    BranchNormalizedVisitor normalizer = null;
+
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        normalizer = new BranchNormalizedVisitor();
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        normalizer = null;
+    }
+
+
     /**
      * Tests an search request decode with a simple equality match filter.
      */
@@ -576,6 +594,461 @@
         node.printToBuffer( buf0 );
         System.out.println( buf0.toString() );
         node = decoded.getFilter();
+        StringBuffer buf1 = new StringBuffer();
+        node.printToBuffer( buf1 );
+        System.out.println( buf1.toString() );
+        assertEquals(buf0.toString(), buf1.toString()) ;
+    }
+
+
+    /**
+     * Tests an search request decode with a simple equality match filter.
+     */
+    public void testAndFilter0() throws Exception
+    {
+        SearchRequestImpl req = new SearchRequestImpl( 33 );
+        req.setBase( "dc=example,dc=com" );
+        req.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        req.setScope( ScopeEnum.BASEOBJECT );
+        req.setSizeLimit( 2 );
+        req.setTimeLimit( 3 );
+        req.setTypesOnly( true );
+
+        req.addAttribute( "attr0" );
+        req.addAttribute( "attr1" );
+        req.addAttribute( "attr2" );
+
+
+        FilterParserImpl parser = new FilterParserImpl();
+        BranchNode node = null ;
+        node = ( BranchNode ) parser.parse(
+                "( & ( ou = Human Resources ) ( l=Santa Clara ) )" ) ;
+
+        req.setFilter( node );
+
+        System.out.println( "Generated SearchRequest for test:" );
+        System.out.println( TestUtils.printTupleTree( req ) );
+
+        SearchRequest decoded = ( SearchRequest )
+                snickersDecode( snaccEncode( req ) );
+        assertNotNull( decoded );
+
+        // test that we have all the properties set
+        assertEquals( req.getBase(), decoded.getBase() );
+        assertEquals( req.getScope(), decoded.getScope() );
+        assertEquals( req.getTypesOnly(), decoded.getTypesOnly() );
+        assertEquals( req.getTimeLimit(), decoded.getTimeLimit() );
+        assertEquals( req.getSizeLimit(), decoded.getSizeLimit() );
+        assertEquals( req.getDerefAliases(), decoded.getDerefAliases() );
+
+        // test that we have all the attributes
+        Iterator list = req.getAttributes().iterator();
+        Collection attributes = decoded.getAttributes();
+        while( list.hasNext() )
+        {
+            assertTrue( attributes.contains( list.next() ) );
+        }
+
+        // control test should not exist
+        assertFalse( attributes.contains( "(*&#$&#$*@#" ) );
+
+        // filter tests
+        StringBuffer buf0 = new StringBuffer();
+        node.printToBuffer( buf0 );
+        System.out.println( buf0.toString() );
+        node = ( BranchNode ) decoded.getFilter();
+        StringBuffer buf1 = new StringBuffer();
+        node.printToBuffer( buf1 );
+        System.out.println( buf1.toString() );
+        assertEquals(buf0.toString(), buf1.toString()) ;
+    }
+
+
+    /**
+     * Tests an search request decode with a simple equality match filter.
+     */
+    public void testAndFilter1() throws Exception
+    {
+        SearchRequestImpl req = new SearchRequestImpl( 33 );
+        req.setBase( "dc=example,dc=com" );
+        req.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        req.setScope( ScopeEnum.BASEOBJECT );
+        req.setSizeLimit( 2 );
+        req.setTimeLimit( 3 );
+        req.setTypesOnly( true );
+
+        req.addAttribute( "attr0" );
+        req.addAttribute( "attr1" );
+        req.addAttribute( "attr2" );
+
+        FilterParserImpl parser = new FilterParserImpl();
+        ExprNode node = null ;
+        node = parser.parse(
+                "( & ( ou = Human Resources ) ( l=Santa Clara ) " +
+                "( uid=akarasulu ) )" ) ;
+        normalizer.visit( node );
+        req.setFilter( node );
+
+        System.out.println( "Generated SearchRequest for test:" );
+        System.out.println( TestUtils.printTupleTree( req ) );
+
+        SearchRequest decoded = ( SearchRequest )
+                snickersDecode( snaccEncode( req ) );
+        assertNotNull( decoded );
+
+        // test that we have all the properties set
+        assertEquals( req.getBase(), decoded.getBase() );
+        assertEquals( req.getScope(), decoded.getScope() );
+        assertEquals( req.getTypesOnly(), decoded.getTypesOnly() );
+        assertEquals( req.getTimeLimit(), decoded.getTimeLimit() );
+        assertEquals( req.getSizeLimit(), decoded.getSizeLimit() );
+        assertEquals( req.getDerefAliases(), decoded.getDerefAliases() );
+
+        // test that we have all the attributes
+        Iterator list = req.getAttributes().iterator();
+        Collection attributes = decoded.getAttributes();
+        while( list.hasNext() )
+        {
+            assertTrue( attributes.contains( list.next() ) );
+        }
+
+        // control test should not exist
+        assertFalse( attributes.contains( "(*&#$&#$*@#" ) );
+
+        // filter tests
+        node = req.getFilter();
+        StringBuffer buf0 = new StringBuffer();
+        node.printToBuffer( buf0 );
+        System.out.println( buf0.toString() );
+        node = decoded.getFilter();
+        normalizer.visit( node );
+        StringBuffer buf1 = new StringBuffer();
+        node.printToBuffer( buf1 );
+        System.out.println( buf1.toString() );
+        assertEquals(buf0.toString(), buf1.toString()) ;
+    }
+
+
+    /**
+     * Tests an search request decode with a simple equality match filter.
+     */
+    public void testAndFilter2() throws Exception
+    {
+        SearchRequestImpl req = new SearchRequestImpl( 33 );
+        req.setBase( "dc=example,dc=com" );
+        req.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        req.setScope( ScopeEnum.BASEOBJECT );
+        req.setSizeLimit( 2 );
+        req.setTimeLimit( 3 );
+        req.setTypesOnly( true );
+
+        req.addAttribute( "attr0" );
+        req.addAttribute( "attr1" );
+        req.addAttribute( "attr2" );
+
+
+        FilterParserImpl parser = new FilterParserImpl();
+        ExprNode node = null ;
+        node = parser.parse(
+                "( & ( ou = Human Resources ) ( l=Santa Clara ) " +
+                "( uid=akarasulu ) ( cn=aok ) )" ) ;
+        normalizer.visit( node );
+        req.setFilter( node );
+
+        System.out.println( "Generated SearchRequest for test:" );
+        System.out.println( TestUtils.printTupleTree( req ) );
+
+        SearchRequest decoded = ( SearchRequest )
+                snickersDecode( snaccEncode( req ) );
+        assertNotNull( decoded );
+
+        // test that we have all the properties set
+        assertEquals( req.getBase(), decoded.getBase() );
+        assertEquals( req.getScope(), decoded.getScope() );
+        assertEquals( req.getTypesOnly(), decoded.getTypesOnly() );
+        assertEquals( req.getTimeLimit(), decoded.getTimeLimit() );
+        assertEquals( req.getSizeLimit(), decoded.getSizeLimit() );
+        assertEquals( req.getDerefAliases(), decoded.getDerefAliases() );
+
+        // test that we have all the attributes
+        Iterator list = req.getAttributes().iterator();
+        Collection attributes = decoded.getAttributes();
+        while( list.hasNext() )
+        {
+            assertTrue( attributes.contains( list.next() ) );
+        }
+
+        // control test should not exist
+        assertFalse( attributes.contains( "(*&#$&#$*@#" ) );
+
+        // filter tests
+        node = req.getFilter();
+        StringBuffer buf0 = new StringBuffer();
+        node.printToBuffer( buf0 );
+        System.out.println( buf0.toString() );
+        node = decoded.getFilter();
+        normalizer.visit( node );
+        StringBuffer buf1 = new StringBuffer();
+        node.printToBuffer( buf1 );
+        System.out.println( buf1.toString() );
+        assertEquals(buf0.toString(), buf1.toString()) ;
+    }
+
+
+    /**
+     * Tests an search request decode with a simple equality match filter.
+     */
+    public void testAndFilter3() throws Exception
+    {
+        SearchRequestImpl req = new SearchRequestImpl( 33 );
+        req.setBase( "dc=example,dc=com" );
+        req.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        req.setScope( ScopeEnum.BASEOBJECT );
+        req.setSizeLimit( 2 );
+        req.setTimeLimit( 3 );
+        req.setTypesOnly( true );
+
+        req.addAttribute( "attr0" );
+        req.addAttribute( "attr1" );
+        req.addAttribute( "attr2" );
+
+        FilterParserImpl parser = new FilterParserImpl();
+        ExprNode node = null ;
+        node = parser.parse(
+                "( & ( ou = Human Resources ) ( l=Santa Clara ) " +
+                "( uid=akarasulu ) ( cn=aok ) ( cn=aok ) ( cn = abok) )" ) ;
+        normalizer.visit( node );
+        req.setFilter( node );
+
+        System.out.println( "Generated SearchRequest for test:" );
+        System.out.println( TestUtils.printTupleTree( req ) );
+
+        SearchRequest decoded = ( SearchRequest )
+                snickersDecode( snaccEncode( req ) );
+        assertNotNull( decoded );
+
+        // test that we have all the properties set
+        assertEquals( req.getBase(), decoded.getBase() );
+        assertEquals( req.getScope(), decoded.getScope() );
+        assertEquals( req.getTypesOnly(), decoded.getTypesOnly() );
+        assertEquals( req.getTimeLimit(), decoded.getTimeLimit() );
+        assertEquals( req.getSizeLimit(), decoded.getSizeLimit() );
+        assertEquals( req.getDerefAliases(), decoded.getDerefAliases() );
+
+        // test that we have all the attributes
+        Iterator list = req.getAttributes().iterator();
+        Collection attributes = decoded.getAttributes();
+        while( list.hasNext() )
+        {
+            assertTrue( attributes.contains( list.next() ) );
+        }
+
+        // control test should not exist
+        assertFalse( attributes.contains( "(*&#$&#$*@#" ) );
+
+        // filter tests
+        node = req.getFilter();
+        StringBuffer buf0 = new StringBuffer();
+        node.printToBuffer( buf0 );
+        System.out.println( buf0.toString() );
+        node = decoded.getFilter();
+        normalizer.visit( node );
+        StringBuffer buf1 = new StringBuffer();
+        node.printToBuffer( buf1 );
+        System.out.println( buf1.toString() );
+        assertEquals(buf0.toString(), buf1.toString()) ;
+    }
+
+
+    /**
+     * Tests an search request decode with a simple equality match filter.
+     */
+    public void testOrFilter1() throws Exception
+    {
+        SearchRequestImpl req = new SearchRequestImpl( 33 );
+        req.setBase( "dc=example,dc=com" );
+        req.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        req.setScope( ScopeEnum.BASEOBJECT );
+        req.setSizeLimit( 2 );
+        req.setTimeLimit( 3 );
+        req.setTypesOnly( true );
+
+        req.addAttribute( "attr0" );
+        req.addAttribute( "attr1" );
+        req.addAttribute( "attr2" );
+
+        FilterParserImpl parser = new FilterParserImpl();
+        ExprNode node = null ;
+        node = parser.parse(
+                "( | ( ou = Human Resources ) ( l=Santa Clara ) " +
+                "( uid=akarasulu ) )" ) ;
+        normalizer.visit( node );
+        req.setFilter( node );
+
+        System.out.println( "Generated SearchRequest for test:" );
+        System.out.println( TestUtils.printTupleTree( req ) );
+
+        SearchRequest decoded = ( SearchRequest )
+                snickersDecode( snaccEncode( req ) );
+        assertNotNull( decoded );
+
+        // test that we have all the properties set
+        assertEquals( req.getBase(), decoded.getBase() );
+        assertEquals( req.getScope(), decoded.getScope() );
+        assertEquals( req.getTypesOnly(), decoded.getTypesOnly() );
+        assertEquals( req.getTimeLimit(), decoded.getTimeLimit() );
+        assertEquals( req.getSizeLimit(), decoded.getSizeLimit() );
+        assertEquals( req.getDerefAliases(), decoded.getDerefAliases() );
+
+        // test that we have all the attributes
+        Iterator list = req.getAttributes().iterator();
+        Collection attributes = decoded.getAttributes();
+        while( list.hasNext() )
+        {
+            assertTrue( attributes.contains( list.next() ) );
+        }
+
+        // control test should not exist
+        assertFalse( attributes.contains( "(*&#$&#$*@#" ) );
+
+        // filter tests
+        node = req.getFilter();
+        StringBuffer buf0 = new StringBuffer();
+        node.printToBuffer( buf0 );
+        System.out.println( buf0.toString() );
+        node = decoded.getFilter();
+        normalizer.visit( node );
+        StringBuffer buf1 = new StringBuffer();
+        node.printToBuffer( buf1 );
+        System.out.println( buf1.toString() );
+        assertEquals(buf0.toString(), buf1.toString()) ;
+    }
+
+
+    /**
+     * Tests an search request decode with a simple equality match filter.
+     */
+    public void testOrFilter2() throws Exception
+    {
+        SearchRequestImpl req = new SearchRequestImpl( 33 );
+        req.setBase( "dc=example,dc=com" );
+        req.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        req.setScope( ScopeEnum.BASEOBJECT );
+        req.setSizeLimit( 2 );
+        req.setTimeLimit( 3 );
+        req.setTypesOnly( true );
+
+        req.addAttribute( "attr0" );
+        req.addAttribute( "attr1" );
+        req.addAttribute( "attr2" );
+
+
+        FilterParserImpl parser = new FilterParserImpl();
+        ExprNode node = null ;
+        node = parser.parse(
+                "( | ( ou = Human Resources ) ( l=Santa Clara ) " +
+                "( uid=akarasulu ) ( cn=aok ) )" ) ;
+        normalizer.visit( node );
+        req.setFilter( node );
+
+        System.out.println( "Generated SearchRequest for test:" );
+        System.out.println( TestUtils.printTupleTree( req ) );
+
+        SearchRequest decoded = ( SearchRequest )
+                snickersDecode( snaccEncode( req ) );
+        assertNotNull( decoded );
+
+        // test that we have all the properties set
+        assertEquals( req.getBase(), decoded.getBase() );
+        assertEquals( req.getScope(), decoded.getScope() );
+        assertEquals( req.getTypesOnly(), decoded.getTypesOnly() );
+        assertEquals( req.getTimeLimit(), decoded.getTimeLimit() );
+        assertEquals( req.getSizeLimit(), decoded.getSizeLimit() );
+        assertEquals( req.getDerefAliases(), decoded.getDerefAliases() );
+
+        // test that we have all the attributes
+        Iterator list = req.getAttributes().iterator();
+        Collection attributes = decoded.getAttributes();
+        while( list.hasNext() )
+        {
+            assertTrue( attributes.contains( list.next() ) );
+        }
+
+        // control test should not exist
+        assertFalse( attributes.contains( "(*&#$&#$*@#" ) );
+
+        // filter tests
+        node = req.getFilter();
+        StringBuffer buf0 = new StringBuffer();
+        node.printToBuffer( buf0 );
+        System.out.println( buf0.toString() );
+        node = decoded.getFilter();
+        normalizer.visit( node );
+        StringBuffer buf1 = new StringBuffer();
+        node.printToBuffer( buf1 );
+        System.out.println( buf1.toString() );
+        assertEquals(buf0.toString(), buf1.toString()) ;
+    }
+
+
+    /**
+     * Tests an search request decode with a simple equality match filter.
+     */
+    public void testOrFilter3() throws Exception
+    {
+        SearchRequestImpl req = new SearchRequestImpl( 33 );
+        req.setBase( "dc=example,dc=com" );
+        req.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        req.setScope( ScopeEnum.BASEOBJECT );
+        req.setSizeLimit( 2 );
+        req.setTimeLimit( 3 );
+        req.setTypesOnly( true );
+
+        req.addAttribute( "attr0" );
+        req.addAttribute( "attr1" );
+        req.addAttribute( "attr2" );
+
+        FilterParserImpl parser = new FilterParserImpl();
+        ExprNode node = null ;
+        node = parser.parse(
+                "( | ( ou = Human Resources ) ( l=Santa Clara ) " +
+                "( uid=akarasulu ) ( cn=aok ) ( cn=aok ) ( cn = abok) )" ) ;
+        normalizer.visit( node );
+        req.setFilter( node );
+
+        System.out.println( "Generated SearchRequest for test:" );
+        System.out.println( TestUtils.printTupleTree( req ) );
+
+        SearchRequest decoded = ( SearchRequest )
+                snickersDecode( snaccEncode( req ) );
+        assertNotNull( decoded );
+
+        // test that we have all the properties set
+        assertEquals( req.getBase(), decoded.getBase() );
+        assertEquals( req.getScope(), decoded.getScope() );
+        assertEquals( req.getTypesOnly(), decoded.getTypesOnly() );
+        assertEquals( req.getTimeLimit(), decoded.getTimeLimit() );
+        assertEquals( req.getSizeLimit(), decoded.getSizeLimit() );
+        assertEquals( req.getDerefAliases(), decoded.getDerefAliases() );
+
+        // test that we have all the attributes
+        Iterator list = req.getAttributes().iterator();
+        Collection attributes = decoded.getAttributes();
+        while( list.hasNext() )
+        {
+            assertTrue( attributes.contains( list.next() ) );
+        }
+
+        // control test should not exist
+        assertFalse( attributes.contains( "(*&#$&#$*@#" ) );
+
+        // filter tests
+        node = req.getFilter();
+        StringBuffer buf0 = new StringBuffer();
+        node.printToBuffer( buf0 );
+        System.out.println( buf0.toString() );
+        node = decoded.getFilter();
+        normalizer.visit( node );
         StringBuffer buf1 = new StringBuffer();
         node.printToBuffer( buf1 );
         System.out.println( buf1.toString() );

Mime
View raw message