directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r158987 - in directory/shared/ldap/trunk: apache-provider/src/java/org/apache/ldap/common/berlib/asn1/ apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/ apache-provider/src/test/ common/src/java/org/apache/ldap/common/filter/ common/src/test/org/apache/ldap/common/filter/
Date Fri, 25 Mar 2005 03:24:27 GMT
Author: akarasulu
Date: Thu Mar 24 19:24:24 2005
New Revision: 158987

URL: http://svn.apache.org/viewcvs?view=rev&rev=158987
Log:
change ...

 o fixed the following bug: http://issues.apache.org/jira/browse/DIRLDAP-38
   but did not use submitted patch ... found alt way to do it
 o found a new bug with the BranchNodeNormalizer which was not doing its 
   job correctly
 o formated a bunch of source files
 o added test case to reproduce http://issues.apache.org/jira/browse/DIRLDAP-38


Added:
    directory/shared/ldap/trunk/apache-provider/src/test/RoundTripFilterTest.java
Modified:
    directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/SnickersDecoder.java
    directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/AndRule.java
    directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/EqualityMatchRule.java
    directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/OrRule.java
    directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/filter/BranchNormalizedVisitor.java
    directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/filter/BranchNormalizedVisitorTest.java

Modified: directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/SnickersDecoder.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/SnickersDecoder.java?view=diff&r1=158986&r2=158987
==============================================================================
--- directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/SnickersDecoder.java
(original)
+++ directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/SnickersDecoder.java
Thu Mar 24 19:24:24 2005
@@ -35,8 +35,7 @@
 /**
  * A Snickers based LDAP PDU decoder.
  *
- * @author <a href="mailto:dev@directory.apache.org"> Apache Directory
- *         Project</a> $Rev$
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
$Rev$
  */
 public class SnickersDecoder implements ProviderDecoder
 {

Modified: directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/AndRule.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/AndRule.java?view=diff&r1=158986&r2=158987
==============================================================================
--- directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/AndRule.java
(original)
+++ directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/AndRule.java
Thu Mar 24 19:24:24 2005
@@ -36,8 +36,7 @@
  * 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:dev@directory.apache.org">Apache Directory
- *         Project</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
 public class AndRule extends AbstractRule
@@ -53,9 +52,11 @@
     {
         // check to see we are within limits - have the right number of tags
         int tagCount = getDigester().getTagCount();
+
         if ( tagCount < 3 )
         {
             this.isEnabled = false;
+
             return;
         }
 
@@ -64,10 +65,10 @@
          * 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() )
+        if ( getDigester().getTag( tagCount - 2 ) != LdapTag.SEARCH_REQUEST.getPrimitiveTag()
)
         {
             this.isEnabled = false;
+
             return;
         }
 
@@ -79,15 +80,21 @@
          * specific tags to see if we need to disable this rule.
          */
         if
-        (
-            getDigester().getTag( 2 ) ==
-                LdapTag.CONTEXT_SPECIFIC_TAG_4.getPrimitiveTag()
-        )
+        ( getDigester().getTag( 2 ) == LdapTag.CONTEXT_SPECIFIC_TAG_4.getPrimitiveTag() )
         {
-            this.isEnabled = false ;
-            return ;
+            this.isEnabled = false;
+
+            return;
         }
 
+        /*
+         * At this point we know the AndRule is enabled but we need to push a separator
+         * onto the stack so when the AndRule finishes it knows when to stop popping
+         * subexpressions off of the stack.  We just push the rule itself onto the stack.
+         * and test for it in the finish() method's while loop to terminate.
+         */
+        getDigester().push( this );
+
         super.tag( id, isPrimitive, typeClass );
     }
 
@@ -126,12 +133,30 @@
             super.finish();
 
             BranchNode node;
+
             node = new BranchNode( BranchNode.AND );
 
             while( getDigester().peek() instanceof ExprNode )
             {
                 node.addNode( ( ExprNode ) getDigester().pop() );
             }
+
+            if ( getDigester().peek() == this )
+            {
+                getDigester().pop();
+            }
+            else
+            {
+                String msg = "Expected to see an AndRule object on stack but got ";
+
+                msg += getDigester().peek().getClass() + " instead";
+
+                throw new IllegalStateException( msg );
+            }
+
+            StringBuffer strbuf = new StringBuffer( );
+
+            node.printToBuffer( strbuf );
 
             getDigester().push( node );
         }

Modified: directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/EqualityMatchRule.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/EqualityMatchRule.java?view=diff&r1=158986&r2=158987
==============================================================================
--- directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/EqualityMatchRule.java
(original)
+++ directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/EqualityMatchRule.java
Thu Mar 24 19:24:24 2005
@@ -37,18 +37,22 @@
  */
 public class EqualityMatchRule extends PrimitiveOctetStringRule
 {
-    private boolean isEnabled = true ;
-    private String name = null ;
-    private String value = null ;
+    private boolean isEnabled = true;
+
+    private String name = null;
+
+    private String value = null;
 
 
     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 < 4 )
         {
             this.isEnabled = false;
+
             return;
         }
 
@@ -57,22 +61,24 @@
          * 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() )
+        if ( getDigester().getTag( tagCount - 2 ) != LdapTag.SEARCH_REQUEST.getPrimitiveTag()
)
         {
             this.isEnabled = false;
+
             return;
         }
 
         super.tag( id, isPrimitive, typeClass );
 
         int ii = getDigester().getCount() - 2;
+
         SearchRequestProcessing processing;
+
         processing = ( SearchRequestProcessing ) getDigester().peek(ii);
 
         if ( processing.getState() != processing.FILTER_STATE )
         {
-            isEnabled = false ;
+            isEnabled = false;
         }
     }
 
@@ -109,6 +115,7 @@
         if ( ! isEnabled )
         {
             isEnabled = true ;
+
             return ;
         }
 
@@ -119,15 +126,19 @@
         ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
 
         byte[] octets = null ;
+
         if ( buf.limit() == buf.capacity() && buf.hasArray() )
         {
             // use the backing store
+
             octets = buf.array() ;
         }
         else
         {
             // copy because we don't have accessible array or data < array
+
             octets = new byte[buf.remaining()];
+
             buf.get( octets );
         }
 
@@ -139,18 +150,23 @@
         {
             value = new String( octets ) ;
 
-
             SimpleNode node;
+
             node = new SimpleNode( name, value, SimpleNode.EQUALITY );
+
+            StringBuffer strbuf = new StringBuffer( );
+
+            node.printToBuffer( strbuf );
+
             getDigester().push( node ) ;
 
             name = null ;
+
             value = null ;
         }
         else
         {
-            throw new IllegalStateException( "name = " + name
-                    + " and value = " + value );
+            throw new IllegalStateException( "name = " + name + " and value = " + value );
         }
     }
 }

Modified: directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/OrRule.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/OrRule.java?view=diff&r1=158986&r2=158987
==============================================================================
--- directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/OrRule.java
(original)
+++ directory/shared/ldap/trunk/apache-provider/src/java/org/apache/ldap/common/berlib/asn1/decoder/search/OrRule.java
Thu Mar 24 19:24:24 2005
@@ -53,9 +53,11 @@
     {
         // check to see we are within limits - have the right number of tags
         int tagCount = getDigester().getTagCount();
+
         if ( tagCount < 3 )
         {
             this.isEnabled = false;
+
             return;
         }
 
@@ -64,10 +66,10 @@
          * 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() )
+        if ( getDigester().getTag( tagCount - 2 ) != LdapTag.SEARCH_REQUEST.getPrimitiveTag()
)
         {
             this.isEnabled = false;
+
             return;
         }
 
@@ -79,17 +81,22 @@
          * 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()
-        )
+        ( getDigester().getTag( 2 ) == LdapTag.CONTEXT_SPECIFIC_TAG_4.getPrimitiveTag() ||
+          getDigester().getTag( 1 ) == LdapTag.CONTEXT_SPECIFIC_TAG_9.getPrimitiveTag() )
         {
             this.isEnabled = false ;
+
             return ;
         }
 
+        /*
+         * At this point we know the OrRule is enabled but we need to push a separator
+         * onto the stack so when the OrRule finishes it knows when to stop popping
+         * subexpressions off of the stack.  We just push the rule itself onto the stack.
+         * and test for it in the finish() method's while loop to terminate.
+         */
+        getDigester().push( this );
+
         super.tag( id, isPrimitive, typeClass );
     }
 
@@ -128,12 +135,30 @@
             super.finish();
 
             BranchNode node;
+
             node = new BranchNode( BranchNode.OR );
 
             while( getDigester().peek() instanceof ExprNode )
             {
                 node.addNode( ( ExprNode ) getDigester().pop() );
             }
+
+            if ( getDigester().peek() == this )
+            {
+                getDigester().pop();
+            }
+            else
+            {
+                String msg = "Expected to see an OrRule object on stack but got ";
+
+                msg += getDigester().peek().getClass() + " instead";
+
+                throw new IllegalStateException( msg );
+            }
+
+            StringBuffer strbuf = new StringBuffer( );
+
+            node.printToBuffer( strbuf );
 
             getDigester().push( node );
         }

Added: directory/shared/ldap/trunk/apache-provider/src/test/RoundTripFilterTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache-provider/src/test/RoundTripFilterTest.java?view=auto&rev=158987
==============================================================================
--- directory/shared/ldap/trunk/apache-provider/src/test/RoundTripFilterTest.java (added)
+++ directory/shared/ldap/trunk/apache-provider/src/test/RoundTripFilterTest.java Thu Mar
24 19:24:24 2005
@@ -0,0 +1,92 @@
+/*
+ *   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.
+ *
+ */
+
+
+import junit.framework.TestCase;
+import org.apache.ldap.common.message.*;
+import org.apache.ldap.common.filter.FilterParserImpl;
+import org.apache.ldap.common.filter.ExprNode;
+import org.apache.ldap.common.filter.BranchNormalizedVisitor;
+import org.apache.asn1.codec.stateful.CallbackHistory;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.nio.ByteBuffer;
+
+
+/**
+ * Tests for a bug where the filter expression is being rearranged by the decoder.
+ *
+ * @see <a href="http://issues.apache.org/jira/browse/DIRLDAP-38">DIRLDAP-38</a>
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class RoundTripFilterTest extends TestCase
+{
+    /**
+     * According to the JIRA issue the following expression is being rearranged:
+     *
+     * <pre>
+     *  (& (a=A) (| (b=B) (c=C) ) )
+     *
+     *  The resulting expression object after the BER parser is finished is:
+     *
+     *  (& (| (c=C) (b=B) (a=A) ) )
+     * </pre>
+     *
+     */
+    public void testRearrangingExpression() throws IOException, ParseException
+    {
+        SearchRequestImpl req = new SearchRequestImpl( 1 );
+
+        req.setBase( "ou=system" );
+
+        FilterParserImpl parser = new FilterParserImpl();
+
+        String originalFilter = "(& (a=A) (| (b=B) (c=C) ) )";
+
+        ExprNode node = parser.parse( originalFilter );
+
+        req.setFilter( node );
+
+        req.setScope( ScopeEnum.SINGLELEVEL );
+
+        req.setDerefAliases( DerefAliasesEnum.DEREFALWAYS );
+
+        MessageEncoder encoder = new MessageEncoder();
+
+        ByteBuffer buf = encoder.encodeBlocking( req );
+
+        CallbackHistory history = new CallbackHistory();
+
+        MessageDecoder decoder = new MessageDecoder();
+
+        decoder.setCallback( history );
+
+        decoder.decode( buf );
+
+        SearchRequest decodedReq = ( SearchRequest ) history.getMostRecent();
+
+        assertNotNull( decodedReq );
+
+        String decodedNormalized = BranchNormalizedVisitor.getNormalizedFilter( decodedReq.getFilter()
);
+
+        String originalNormalized = BranchNormalizedVisitor.getNormalizedFilter( originalFilter
);
+
+        assertEquals( originalNormalized, decodedNormalized );
+    }
+}

Modified: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/filter/BranchNormalizedVisitor.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/filter/BranchNormalizedVisitor.java?view=diff&r1=158986&r2=158987
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/filter/BranchNormalizedVisitor.java
(original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/filter/BranchNormalizedVisitor.java
Thu Mar 24 19:24:24 2005
@@ -20,6 +20,8 @@
 import java.util.TreeSet;
 import java.util.ArrayList;
 import java.util.Comparator;
+import java.io.IOException;
+import java.text.ParseException;
 
 
 /**
@@ -54,38 +56,26 @@
             return;
         }
 
+        Comparator nodeComparator = new NodeComparator();
 
-        Comparator strComp = new Comparator()
-        {
-            StringBuffer buf = new StringBuffer() ;
+        TreeSet set = new TreeSet( nodeComparator ) ;
 
-            public int compare( Object o1, Object o2 )
-            {
-                ExprNode n1 = ( ExprNode ) o1;
-                ExprNode n2 = ( ExprNode ) o2;
+        ArrayList children = branch.getChildren();
 
-                buf.setLength( 0 );
-                String s1 = null;
-                n1.printToBuffer( buf );
-                s1 = buf.toString();
-
-                buf.setLength( 0 );
-                String s2 = null;
-                n2.printToBuffer( buf );
-                s2 = buf.toString();
+        for( int ii = 0; ii < children.size(); ii++ )
+        {
+            ExprNode child = ( ExprNode ) children.get( ii );
 
-                return s1.compareTo( s2 );
+            if ( ! child.isLeaf() )
+            {
+                visit( child );
             }
-        };
 
-        TreeSet set = new TreeSet( strComp ) ;
-        ArrayList children = branch.getChildren();
-        for( int ii = 0; ii < children.size(); ii++ )
-        {
-            set.add( children.get( ii ) ) ;
+            set.add( child ) ;
         }
 
         children.clear();
+
         children.addAll( set ) ;
     }
 
@@ -110,5 +100,76 @@
     public ArrayList getOrder( BranchNode node, ArrayList children )
     {
         return children;
+    }
+
+
+    /**
+     * Normalizes a filter expression to a canonical representation while
+     * retaining logical meaning of the expression.
+     *
+     * @param filter the filter to normalize
+     * @return the normalized version of the filter
+     * @throws java.io.IOException if filter parser cannot be created
+     * @throws java.text.ParseException if the filter is malformed
+     */
+    public static String getNormalizedFilter( String filter ) throws IOException, ParseException
+    {
+        FilterParserImpl parser = new FilterParserImpl();
+
+        ExprNode originalNode = parser.parse( filter );
+
+        return getNormalizedFilter( originalNode );
+    }
+
+
+    /**
+     * Normalizes a filter expression to a canonical representation while
+     * retaining logical meaning of the expression.
+     *
+     * @param filter the filter to normalize
+     * @return the normalized String version of the filter
+     */
+    public static String getNormalizedFilter( ExprNode filter )
+    {
+        BranchNormalizedVisitor visitor = new BranchNormalizedVisitor();
+
+        visitor.visit( filter );
+
+        StringBuffer normalized = new StringBuffer();
+
+        filter.printToBuffer( normalized );
+
+        return normalized.toString().trim();
+    }
+
+
+    class NodeComparator implements Comparator
+    {
+        public int compare( Object o1, Object o2 )
+        {
+            StringBuffer buf = new StringBuffer();
+
+            ExprNode n1 = ( ExprNode ) o1;
+
+            ExprNode n2 = ( ExprNode ) o2;
+
+            buf.setLength( 0 );
+
+            String s1 = null;
+
+            n1.printToBuffer( buf );
+
+            s1 = buf.toString();
+
+            buf.setLength( 0 );
+
+            String s2 = null;
+
+            n2.printToBuffer( buf );
+
+            s2 = buf.toString();
+
+            return s1.compareTo( s2 );
+        }
     }
 }

Modified: directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/filter/BranchNormalizedVisitorTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/filter/BranchNormalizedVisitorTest.java?view=diff&r1=158986&r2=158987
==============================================================================
--- directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/filter/BranchNormalizedVisitorTest.java
(original)
+++ directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/filter/BranchNormalizedVisitorTest.java
Thu Mar 24 19:24:24 2005
@@ -23,8 +23,7 @@
 /**
  * Tests the BranchNormalizedVisitor.
  * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory
- *         Project</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
 public class BranchNormalizedVisitorTest extends TestCase
@@ -32,15 +31,23 @@
     public void testBranchNormalizedVisitor0() throws Exception
     {
         FilterParserImpl parser = new FilterParserImpl();
+
         String filter = "( ou = Human Resources )" ;
+
         ExprNode ori = parser.parse( filter );
+
         ExprNode altered = parser.parse( filter );
+
         BranchNormalizedVisitor visitor = new BranchNormalizedVisitor();
+
         visitor.visit( altered );
 
         StringBuffer oriBuf = new StringBuffer();
+
         ori.printToBuffer( oriBuf );
+
         StringBuffer alteredBuf = new StringBuffer();
+
         altered.printToBuffer( alteredBuf );
 
         assertEquals( oriBuf.toString(), alteredBuf.toString() );
@@ -50,15 +57,23 @@
     public void testBranchNormalizedVisitor1() throws Exception
     {
         FilterParserImpl parser = new FilterParserImpl();
+
         String filter = "( & ( ou = Human Resources ) ( uid = akarasulu ) )" ;
+
         ExprNode ori = parser.parse( filter );
+
         ExprNode altered = parser.parse( filter );
+
         BranchNormalizedVisitor visitor = new BranchNormalizedVisitor();
+
         visitor.visit( altered );
 
         StringBuffer oriBuf = new StringBuffer();
+
         ori.printToBuffer( oriBuf );
+
         StringBuffer alteredBuf = new StringBuffer();
+
         altered.printToBuffer( alteredBuf );
 
         assertEquals( oriBuf.toString(), alteredBuf.toString() );
@@ -68,17 +83,27 @@
     public void testBranchNormalizedVisitor2() throws Exception
     {
         FilterParserImpl parser = new FilterParserImpl();
+
         String filter = "( & ( uid = akarasulu ) ( ou = Human Resources ) " ;
+
         filter += "(| ( uid = akarasulu ) ( ou = Human Resources ) ) ) " ;
+
         ExprNode ori = parser.parse( filter );
+
         ExprNode altered = parser.parse( filter );
+
         BranchNormalizedVisitor visitor = new BranchNormalizedVisitor();
+
         visitor.visit( altered );
 
         StringBuffer oriBuf = new StringBuffer();
+
         ori.printToBuffer( oriBuf );
+
         StringBuffer alteredBuf = new StringBuffer();
+
         altered.printToBuffer( alteredBuf );
+
         assertFalse( oriBuf.toString().equals( alteredBuf.toString() ) );
     }
 
@@ -86,17 +111,41 @@
     public void testBranchNormalizedVisitor3() throws Exception
     {
         FilterParserImpl parser = new FilterParserImpl();
+
         String filter = "( & ( ou = Human Resources ) ( uid = akarasulu ) " ;
+
         filter += "(| ( ou = Human Resources ) ( uid = akarasulu ) ) ) " ;
+
         ExprNode ori = parser.parse( filter );
+
         ExprNode altered = parser.parse( filter );
+
         BranchNormalizedVisitor visitor = new BranchNormalizedVisitor();
+
         visitor.visit( altered );
 
         StringBuffer oriBuf = new StringBuffer();
+
         ori.printToBuffer( oriBuf );
+
         StringBuffer alteredBuf = new StringBuffer();
+
         altered.printToBuffer( alteredBuf );
+
         assertTrue( oriBuf.toString().equals( alteredBuf.toString() ) );
+    }
+
+
+    public void testBranchNormalizedComplex() throws Exception
+    {
+        String filter1 = "( & ( a = A ) ( | ( b = B ) ( c = C ) ) )" ;
+
+        String filter2 = "( & ( a = A ) ( | ( c = C ) ( b = B ) ) )" ;
+
+        String normalizedFilter1 = BranchNormalizedVisitor.getNormalizedFilter( filter1 );
+
+        String normalizedFilter2 = BranchNormalizedVisitor.getNormalizedFilter( filter2 );
+
+        assertEquals( normalizedFilter1, normalizedFilter2 );
     }
 }



Mime
View raw message