directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: r153670 - in incubator/directory/ldap/trunk/apache-provider: project.xml src/test/org/apache/ldap/common/berlib/asn1/decoder/search/SearchRequestTest.java src/test/org/apache/ldap/common/berlib/asn1/decoder/testutils/RuleTestCase.java src/test/org/apache/ldap/common/berlib/asn1/decoder/testutils/TestUtils.java
Date Sun, 13 Feb 2005 21:14:36 GMT
Author: vtence
Date: Sun Feb 13 13:14:35 2005
New Revision: 153670

URL: http://svn.apache.org/viewcvs?view=rev&rev=153670
Log:
Dependency on Snacc is gone. All tests use pre-computed PDUs.

Modified:
    incubator/directory/ldap/trunk/apache-provider/project.xml
    incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/search/SearchRequestTest.java
    incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/testutils/RuleTestCase.java
    incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/testutils/TestUtils.java

Modified: incubator/directory/ldap/trunk/apache-provider/project.xml
URL: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/apache-provider/project.xml?view=diff&r1=153669&r2=153670
==============================================================================
--- incubator/directory/ldap/trunk/apache-provider/project.xml (original)
+++ incubator/directory/ldap/trunk/apache-provider/project.xml Sun Feb 13 13:14:35 2005
@@ -70,23 +70,6 @@
     </dependency>
 
     <dependency>
-      <groupId>incubator-directory</groupId>
-      <artifactId>ldap-snacc-provider</artifactId>
-      <version>0.9-SNAPSHOT</version>
-      <url>
-        http://incubator.apache.org/directory/subprojects/ldap/snacc-provider
-      </url>
-    </dependency>
-
-    <!-- used only to test Apache's ASN.1 Libarary -->
-    <dependency>
-      <groupId>snacc4j</groupId>
-      <artifactId>snacc</artifactId>
-      <version>2.3</version>
-      <url>http://alphaworks.ibm.com/tech/snaccforjava</url>
-    </dependency>
-    
-    <dependency>
       <groupId>regexp</groupId>
       <artifactId>regexp</artifactId>
       <version>1.2</version>

Modified: incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/search/SearchRequestTest.java
URL: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/search/SearchRequestTest.java?view=diff&r1=153669&r2=153670
==============================================================================
--- incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/search/SearchRequestTest.java
(original)
+++ incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/search/SearchRequestTest.java
Sun Feb 13 13:14:35 2005
@@ -78,9 +78,8 @@
 
     public void testFailingRequest0() throws Exception
     {
-        ByteBuffer buf = ByteBuffer.wrap( failingRequest0 );
+        SearchRequest req = ( SearchRequest ) decode( failingRequest0 );
 
-        SearchRequest req = ( SearchRequest ) super.snickersDecode( buf );
         assertEquals( 3, req.getMessageId() );
         assertEquals( MessageTypeEnum.SEARCHREQUEST, req.getType() );
         assertEquals( 0, req.getSizeLimit() );
@@ -98,9 +97,7 @@
 
     public void testFailingRequest0Twice() throws Exception
     {
-        ByteBuffer buf = ByteBuffer.wrap( failingRequest0 );
-
-        SearchRequest req = ( SearchRequest ) super.snickersDecode( buf );
+        SearchRequest req = ( SearchRequest ) decode( failingRequest0 );
         assertEquals( 3, req.getMessageId() );
         assertEquals( MessageTypeEnum.SEARCHREQUEST, req.getType() );
         assertEquals( 0, req.getSizeLimit() );
@@ -114,8 +111,7 @@
         assertTrue( req.getAttributes().isEmpty() );
         assertEquals( "(objectClass=*)", req.getFilter().toString().trim() );
 
-        buf.rewind();
-        req = ( SearchRequest ) super.snickersDecode( buf );
+        req = ( SearchRequest ) decode( failingRequest0 );
         assertEquals( 3, req.getMessageId() );
         assertEquals( MessageTypeEnum.SEARCHREQUEST, req.getType() );
         assertEquals( 0, req.getSizeLimit() );
@@ -395,86 +391,22 @@
         assertEquals( expected, decoded );
     }
 
-    /**
-     * 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()) ;
-//    }
-
     public void testAndFilter1() throws Exception
     {
         byte[] pdu = new byte[] {0x30, 0x7B, 0x02, 0x01, 0x21, 0x63, 0x76, 0x04, 0x11, 0x64,
0x63, 0x3D, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2C, 0x64, 0x63, 0x3D, 0x63, 0x6F,
0x6D, 0x0A, 0x01, 0x00, 0x0A, 0x01, 0x02, 0x02, 0x01, 0x02, 0x02, 0x01, 0x03, 0x01, 0x01,
0xFFFFFFFF, 0xFFFFFFA0, 0x3B, 0xFFFFFFA3, 0x15, 0x04, 0x02, 0x6F, 0x75, 0x04, 0x0F, 0x48,
0x75, 0x6D, 0x61, 0x6E, 0x20, 0x52, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73, 0xFFFFFFA3,
0x10, 0x04, 0x03, 0x75, 0x69, 0x64, 0x04, 0x09, 0x61, 0x6B, 0x61, 0x72, 0x61, 0x73, 0x75,
0x6C, 0x75, 0xFFFFFFA3, 0x10, 0x04, 0x01, 0x6C, 0x04, 0x0B, 0x53, 0x61, 0x6E, 0x74, 0x61,
0x20, 0x43, 0x6C, 0x61, 0x72, 0x61, 0x30, 0x15, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x30,
0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x31, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x32};
+        SearchRequest decoded = ( SearchRequest ) decode( pdu );
+
+        SearchRequestImpl expected = new SearchRequestImpl( 33 );
+        expected.setBase( "dc=example,dc=com" );
+        expected.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        expected.setScope( ScopeEnum.BASEOBJECT );
+        expected.setSizeLimit( 2 );
+        expected.setTimeLimit( 3 );
+        expected.setTypesOnly( true );
 
-        //TODO: here
-        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" );
+        expected.addAttribute( "attr0" );
+        expected.addAttribute( "attr1" );
+        expected.addAttribute( "attr2" );
 
         FilterParserImpl parser = new FilterParserImpl();
         ExprNode node = null ;
@@ -482,45 +414,9 @@
                 "( & ( 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 ) );
+        expected.setFilter( node );
 
-        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()) ;
+        assertEquals( expected, decoded );
     }
 
     /**
@@ -528,18 +424,20 @@
      */
     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" );
+        byte[] pdu = {0x30, 0xFFFFFF81, 0xFFFFFF87, 0x02, 0x01, 0x21, 0x63, 0xFFFFFF81, 0xFFFFFF81,
0x04, 0x11, 0x64, 0x63, 0x3D, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2C, 0x64, 0x63,
0x3D, 0x63, 0x6F, 0x6D, 0x0A, 0x01, 0x00, 0x0A, 0x01, 0x02, 0x02, 0x01, 0x02, 0x02, 0x01,
0x03, 0x01, 0x01, 0xFFFFFFFF, 0xFFFFFFA0, 0x46, 0xFFFFFFA3, 0x10, 0x04, 0x01, 0x6C, 0x04,
0x0B, 0x53, 0x61, 0x6E, 0x74, 0x61, 0x20, 0x43, 0x6C, 0x61, 0x72, 0x61, 0xFFFFFFA3, 0x10,
0x04, 0x03, 0x75, 0x69, 0x64, 0x04, 0x09, 0x61, 0x6B, 0x61, 0x72, 0x61, 0x73, 0x75, 0x6C,
0x75, 0xFFFFFFA3, 0x15, 0x04, 0x02, 0x6F, 0x75, 0x04, 0x0F, 0x48, 0x75, 0x6D, 0x61, 0x6E,
0x20, 0x52, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73, 0xFFFFFFA3, 0x09, 0x04, 0x02,
0x63, 0x6E, 0x04, 0x03, 0x61, 0x6F, 0x6B, 0x30, 0x15, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72,
0x30, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x31, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x32};
+        SearchRequest decoded = ( SearchRequest ) decode( pdu );
 
+        SearchRequestImpl expected = new SearchRequestImpl( 33 );
+        expected.setBase( "dc=example,dc=com" );
+        expected.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        expected.setScope( ScopeEnum.BASEOBJECT );
+        expected.setSizeLimit( 2 );
+        expected.setTimeLimit( 3 );
+        expected.setTypesOnly( true );
+
+        expected.addAttribute( "attr0" );
+        expected.addAttribute( "attr1" );
+        expected.addAttribute( "attr2" );
 
         FilterParserImpl parser = new FilterParserImpl();
         ExprNode node = null ;
@@ -547,64 +445,30 @@
                 "( & ( 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 ) );
+        expected.setFilter( node );
 
-        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()) ;
+        assertEquals( expected, decoded );
     }
 
-
     /**
      * 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" );
+        byte[] pdu = new byte[] {0x30, 0xFFFFFF81, 0xFFFFFF93, 0x02, 0x01, 0x21, 0x63, 0xFFFFFF81,
0xFFFFFF8D, 0x04, 0x11, 0x64, 0x63, 0x3D, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2C,
0x64, 0x63, 0x3D, 0x63, 0x6F, 0x6D, 0x0A, 0x01, 0x00, 0x0A, 0x01, 0x02, 0x02, 0x01, 0x02,
0x02, 0x01, 0x03, 0x01, 0x01, 0xFFFFFFFF, 0xFFFFFFA0, 0x52, 0xFFFFFFA3, 0x10, 0x04, 0x03,
0x75, 0x69, 0x64, 0x04, 0x09, 0x61, 0x6B, 0x61, 0x72, 0x61, 0x73, 0x75, 0x6C, 0x75, 0xFFFFFFA3,
0x09, 0x04, 0x02, 0x63, 0x6E, 0x04, 0x03, 0x61, 0x6F, 0x6B, 0xFFFFFFA3, 0x15, 0x04, 0x02,
0x6F, 0x75, 0x04, 0x0F, 0x48, 0x75, 0x6D, 0x61, 0x6E, 0x20, 0x52, 0x65, 0x73, 0x6F, 0x75,
0x72, 0x63, 0x65, 0x73, 0xFFFFFFA3, 0x10, 0x04, 0x01, 0x6C, 0x04, 0x0B, 0x53, 0x61, 0x6E,
0x74, 0x61, 0x20, 0x43, 0x6C, 0x61, 0x72, 0x61, 0xFFFFFFA3, 0x0A, 0x04, 0x02, 0x63, 0x6E,
0x04, 0x04, 0x61, 0x62, 0x6F, 0x6B, 0x30, 0x15, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x30,
0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x31, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x32};
+        SearchRequest decoded = ( SearchRequest ) decode( pdu  );
+
+        SearchRequestImpl expected = new SearchRequestImpl( 33 );
+        expected.setBase( "dc=example,dc=com" );
+        expected.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        expected.setScope( ScopeEnum.BASEOBJECT );
+        expected.setSizeLimit( 2 );
+        expected.setTimeLimit( 3 );
+        expected.setTypesOnly( true );
+
+        expected.addAttribute( "attr0" );
+        expected.addAttribute( "attr1" );
+        expected.addAttribute( "attr2" );
 
         FilterParserImpl parser = new FilterParserImpl();
         ExprNode node = null ;
@@ -612,64 +476,27 @@
                 "( & ( 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 ) );
+        expected.setFilter( node );
 
-        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()) ;
+        assertEquals( expected, decoded );
     }
 
-
-    /**
-     * 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" );
+        byte[] pdu = new byte[] {0x30, 0x7B, 0x02, 0x01, 0x21, 0x63, 0x76, 0x04, 0x11, 0x64,
0x63, 0x3D, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2C, 0x64, 0x63, 0x3D, 0x63, 0x6F,
0x6D, 0x0A, 0x01, 0x00, 0x0A, 0x01, 0x02, 0x02, 0x01, 0x02, 0x02, 0x01, 0x03, 0x01, 0x01,
0xFFFFFFFF, 0xFFFFFFA1, 0x3B, 0xFFFFFFA3, 0x15, 0x04, 0x02, 0x6F, 0x75, 0x04, 0x0F, 0x48,
0x75, 0x6D, 0x61, 0x6E, 0x20, 0x52, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73, 0xFFFFFFA3,
0x10, 0x04, 0x03, 0x75, 0x69, 0x64, 0x04, 0x09, 0x61, 0x6B, 0x61, 0x72, 0x61, 0x73, 0x75,
0x6C, 0x75, 0xFFFFFFA3, 0x10, 0x04, 0x01, 0x6C, 0x04, 0x0B, 0x53, 0x61, 0x6E, 0x74, 0x61,
0x20, 0x43, 0x6C, 0x61, 0x72, 0x61, 0x30, 0x15, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x30,
0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x31, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x32};
+        SearchRequest decoded = ( SearchRequest ) decode( pdu );
+
+        SearchRequestImpl expected = new SearchRequestImpl( 33 );
+        expected.setBase( "dc=example,dc=com" );
+        expected.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        expected.setScope( ScopeEnum.BASEOBJECT );
+        expected.setSizeLimit( 2 );
+        expected.setTimeLimit( 3 );
+        expected.setTypesOnly( true );
+
+        expected.addAttribute( "attr0" );
+        expected.addAttribute( "attr1" );
+        expected.addAttribute( "attr2" );
 
         FilterParserImpl parser = new FilterParserImpl();
         ExprNode node = null ;
@@ -677,65 +504,30 @@
                 "( | ( 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 ) );
+        expected.setFilter( node );
 
-        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()) ;
+        assertEquals( expected, decoded );
     }
 
-
     /**
      * 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" );
+        byte[] pdu = new byte[] {0x30, 0xFFFFFF81, 0xFFFFFF87, 0x02, 0x01, 0x21, 0x63, 0xFFFFFF81,
0xFFFFFF81, 0x04, 0x11, 0x64, 0x63, 0x3D, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2C,
0x64, 0x63, 0x3D, 0x63, 0x6F, 0x6D, 0x0A, 0x01, 0x00, 0x0A, 0x01, 0x02, 0x02, 0x01, 0x02,
0x02, 0x01, 0x03, 0x01, 0x01, 0xFFFFFFFF, 0xFFFFFFA1, 0x46, 0xFFFFFFA3, 0x10, 0x04, 0x01,
0x6C, 0x04, 0x0B, 0x53, 0x61, 0x6E, 0x74, 0x61, 0x20, 0x43, 0x6C, 0x61, 0x72, 0x61, 0xFFFFFFA3,
0x10, 0x04, 0x03, 0x75, 0x69, 0x64, 0x04, 0x09, 0x61, 0x6B, 0x61, 0x72, 0x61, 0x73, 0x75,
0x6C, 0x75, 0xFFFFFFA3, 0x15, 0x04, 0x02, 0x6F, 0x75, 0x04, 0x0F, 0x48, 0x75, 0x6D, 0x61,
0x6E, 0x20, 0x52, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73, 0xFFFFFFA3, 0x09, 0x04,
0x02, 0x63, 0x6E, 0x04, 0x03, 0x61, 0x6F, 0x6B, 0x30, 0x15, 0x04, 0x05, 0x61, 0x74, 0x74,
0x72, 0x30, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x31, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72,
0x32};
+        SearchRequest decoded = ( SearchRequest ) decode( pdu );
+
+        SearchRequestImpl expected = new SearchRequestImpl( 33 );
+        expected.setBase( "dc=example,dc=com" );
+        expected.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        expected.setScope( ScopeEnum.BASEOBJECT );
+        expected.setSizeLimit( 2 );
+        expected.setTimeLimit( 3 );
+        expected.setTypesOnly( true );
 
+        expected.addAttribute( "attr0" );
+        expected.addAttribute( "attr1" );
+        expected.addAttribute( "attr2" );
 
         FilterParserImpl parser = new FilterParserImpl();
         ExprNode node = null ;
@@ -743,64 +535,30 @@
                 "( | ( 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 ) );
+        expected.setFilter( node );
 
-        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()) ;
+        assertEquals( expected, decoded );
     }
 
-
     /**
      * 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" );
+        byte[] pdu = new byte[] {0x30, 0xFFFFFF81, 0xFFFFFF93, 0x02, 0x01, 0x21, 0x63, 0xFFFFFF81,
0xFFFFFF8D, 0x04, 0x11, 0x64, 0x63, 0x3D, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2C,
0x64, 0x63, 0x3D, 0x63, 0x6F, 0x6D, 0x0A, 0x01, 0x00, 0x0A, 0x01, 0x02, 0x02, 0x01, 0x02,
0x02, 0x01, 0x03, 0x01, 0x01, 0xFFFFFFFF, 0xFFFFFFA1, 0x52, 0xFFFFFFA3, 0x10, 0x04, 0x03,
0x75, 0x69, 0x64, 0x04, 0x09, 0x61, 0x6B, 0x61, 0x72, 0x61, 0x73, 0x75, 0x6C, 0x75, 0xFFFFFFA3,
0x09, 0x04, 0x02, 0x63, 0x6E, 0x04, 0x03, 0x61, 0x6F, 0x6B, 0xFFFFFFA3, 0x15, 0x04, 0x02,
0x6F, 0x75, 0x04, 0x0F, 0x48, 0x75, 0x6D, 0x61, 0x6E, 0x20, 0x52, 0x65, 0x73, 0x6F, 0x75,
0x72, 0x63, 0x65, 0x73, 0xFFFFFFA3, 0x10, 0x04, 0x01, 0x6C, 0x04, 0x0B, 0x53, 0x61, 0x6E,
0x74, 0x61, 0x20, 0x43, 0x6C, 0x61, 0x72, 0x61, 0xFFFFFFA3, 0x0A, 0x04, 0x02, 0x63, 0x6E,
0x04, 0x04, 0x61, 0x62, 0x6F, 0x6B, 0x30, 0x15, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x30,
0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x31, 0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x32};
+        SearchRequest decoded = ( SearchRequest ) decode( pdu );
+
+        SearchRequestImpl expected = new SearchRequestImpl( 33 );
+        expected.setBase( "dc=example,dc=com" );
+        expected.setDerefAliases( DerefAliasesEnum.DEREFFINDINGBASEOBJ );
+        expected.setScope( ScopeEnum.BASEOBJECT );
+        expected.setSizeLimit( 2);
+        expected.setTimeLimit( 3 );
+        expected.setTypesOnly( true );
+
+        expected.addAttribute( "attr0" );
+        expected.addAttribute( "attr1" );
+        expected.addAttribute( "attr2" );
 
         FilterParserImpl parser = new FilterParserImpl();
         ExprNode node = null ;
@@ -808,44 +566,8 @@
                 "( | ( 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 ) );
+        expected.setFilter( node );
 
-        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()) ;
+        assertEquals( expected, decoded );
     }
 }

Modified: incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/testutils/RuleTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/testutils/RuleTestCase.java?view=diff&r1=153669&r2=153670
==============================================================================
--- incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/testutils/RuleTestCase.java
(original)
+++ incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/testutils/RuleTestCase.java
Sun Feb 13 13:14:35 2005
@@ -67,24 +67,4 @@
         getDigester().decode( ByteBuffer.wrap( pdu ) ) ;
         return ( Message ) history.getMostRecent() ;
     }
-
-    public Message snickersDecode( ByteBuffer buf ) throws Exception
-    {
-        CallbackHistory history = new CallbackHistory() ;
-        getDigester().setCallback( history ) ;
-        getDigester().decode( buf ) ;
-        return ( Message ) history.getMostRecent() ;
-    }
-
-
-    public ByteBuffer snaccEncode( Message req )
-    {
-        // @todo replace this with the Snickers encoder or use serialized
-        // PDUs stubs for test cases rather than decoding live.
-        Properties env = new Properties();
-        env.setProperty( Provider.BERLIB_PROVIDER,
-                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
-        MessageEncoder encoder = new MessageEncoder( env );
-        return encoder.encodeBlocking( req );
-    }
 }

Modified: incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/testutils/TestUtils.java
URL: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/testutils/TestUtils.java?view=diff&r1=153669&r2=153670
==============================================================================
--- incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/testutils/TestUtils.java
(original)
+++ incubator/directory/ldap/trunk/apache-provider/src/test/org/apache/ldap/common/berlib/asn1/decoder/testutils/TestUtils.java
Sun Feb 13 13:14:35 2005
@@ -39,52 +39,6 @@
  */
 public class TestUtils
 {
-    /**
-     * Generates the tuple tree for an LDAP Message PDU.
-     *
-     * @param pdu the LDAP message PDU to generate the tree for
-     * @return the root node of the tuple tree
-     * @throws Exception if there are any problems generating the Tuple tree
-     */
-    public static DefaultMutableTupleNode getTupleTree( Message pdu )
-            throws Exception
-    {
-        DefaultMutableTupleNode node = null ;
-
-        // @todo replace this with the Snickers encoder or use serialized
-        // PDUs stubs for test cases rather than decoding live.
-        Properties env = new Properties();
-        env.setProperty( Provider.BERLIB_PROVIDER,
-                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
-        MessageEncoder encoder = new MessageEncoder( env );
-        ByteBuffer buf = encoder.encodeBlocking( pdu ) ;
-        TupleTreeDecoder decoder = new TupleTreeDecoder() ;
-        CallbackHistory cb = new CallbackHistory() ;
-
-        decoder.setCallback( cb ) ;
-        decoder.decode( buf ) ;
-        node = ( DefaultMutableTupleNode ) cb.getMostRecent() ;
-        return node ;
-    }
-
-
-    /**
-     * Generates a string containing the pretty printed and nested tuple tree
-     * for an LDAP Message PDU.
-     *
-     * @param pdu the LDAP message PDU to print the tree for
-     * @return a string containing the pretty printed and nested tuple tree
-     * @throws Exception if there are any problems generating the Tuple tree
-     */
-    public static String printTupleTree( Message pdu ) throws Exception
-    {
-        DefaultMutableTupleNode node = null ;
-        StringBuffer sb = new StringBuffer() ;
-        node = getTupleTree( pdu ) ;
-        node.printDepthFirst( sb, 0 ) ;
-        return sb.toString() ;
-    }
-
     public static void assertEquals( byte[] expected, byte[] actual )
     {
         String msg = "\nexpected <" + toString( expected ) + ">\nbut was  <" + toString(
actual ) + ">";



Mime
View raw message