You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by No...@apache.org on 2004/03/13 19:39:37 UTC

svn commit: rev 9434 - in incubator/directory/snickers/trunk/ber: . src/java/org/apache/snickers/ber src/test/org/apache/snickers/ber

Author: None
Date: Sat Mar 13 10:39:36 2004
New Revision: 9434

Added:
   incubator/directory/snickers/trunk/ber/berlib.properties
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/LdapMessageTests.java
   incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TupleTreeDecoderTest.java
Modified:
   incubator/directory/snickers/trunk/ber/project.xml
   incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java
Log:
Created a BER stream to TLV TupleTree stream stateful decoder that uses the 
base BER stream to TLV Tuple stream decoder underneath to get TLV events and 
build the TLV TupleTree.

Also added more test cases and the ability to process message from snacc.  The
dependency will go away once we have stabilized the new snickers APIs.


Added: incubator/directory/snickers/trunk/ber/berlib.properties
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/berlib.properties	Sat Mar 13 10:39:36 2004
@@ -0,0 +1 @@
+asn.1.berlib.provider=org.apache.ldap.common.berlib.snacc.SnaccProvider

Modified: incubator/directory/snickers/trunk/ber/project.xml
==============================================================================
--- incubator/directory/snickers/trunk/ber/project.xml	(original)
+++ incubator/directory/snickers/trunk/ber/project.xml	Sat Mar 13 10:39:36 2004
@@ -38,6 +38,37 @@
       <version>SNAPSHOT</version>
       <url>http://jakarta.apache.org/commons/codec</url>
     </dependency>
+
+    <dependency>
+      <groupId>directory</groupId>
+      <artifactId>ldap-common</artifactId>
+      <version>SNAPSHOT</version>
+      <url>http://incubator.apache.org/directory/subprojects/ldap/common</url>
+    </dependency>
+
+    <dependency>
+      <groupId>directory</groupId>
+      <artifactId>ldap-snacc-provider</artifactId>
+      <version>SNAPSHOT</version>
+      <url>
+        http://incubator.apache.org/directory/subprojects/ldap/snacc-provider
+      </url>
+    </dependency>
+
+    <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>
+			<url>http://jakarta.apache.org/regexp/index.html</url>
+		</dependency>
+
   </dependencies>
 </project>
 

Modified: incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java
==============================================================================
--- incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java	(original)
+++ incubator/directory/snickers/trunk/ber/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java	Sat Mar 13 10:39:36 2004
@@ -29,6 +29,9 @@
 
 import org.apache.commons.lang.exception.ExceptionUtils ;
 
+import org.apache.ldap.common.message.Message ;
+import org.apache.ldap.common.message.MessageEncoder ;
+
 import junit.framework.TestCase ;
 
 
@@ -247,6 +250,24 @@
         {
             return decoder.getCurrentTuple() ;
         }
+        
+        return ( Tuple ) tlvList.get( tlvList.size() - 1 ) ;
+    }
+    
+    
+    /**
+     * Encodes a message using the message framework and the default BERLib
+     * provider which is snacc for now.  Later we shall remove this dependency.
+     * It then decodes encoded output generated.
+     * 
+     * @param msg the BER encoded message
+     * @return the last tuple generated by decoding the encoded message
+     * @throws DecoderException if there are any failures
+     */
+    public Tuple decode( Message msg ) throws DecoderException
+    {
+        MessageEncoder encoder = new MessageEncoder() ;
+        decode( encoder.encode( msg ) ) ;
         
         return ( Tuple ) tlvList.get( tlvList.size() - 1 ) ;
     }

Added: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/LdapMessageTests.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/LdapMessageTests.java	Sat Mar 13 10:39:36 2004
@@ -0,0 +1,158 @@
+/*
+ *   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.ber ;
+
+
+import java.math.BigInteger ;
+
+import javax.naming.directory.Attributes ;
+
+import org.apache.ldap.common.message.ScopeEnum ;
+import org.apache.ldap.common.filter.PresenceNode ;
+import org.apache.ldap.common.message.AddRequestImpl ;
+import org.apache.ldap.common.message.BindRequestImpl ;
+import org.apache.ldap.common.message.DerefAliasesEnum ;
+import org.apache.ldap.common.message.DeleteRequestImpl ;
+import org.apache.ldap.common.message.SearchRequestImpl ;
+import org.apache.ldap.common.message.ModifyRequestImpl ;
+import org.apache.ldap.common.message.AbandonRequestImpl ;
+import org.apache.ldap.common.message.CompareRequestImpl ;
+import org.apache.ldap.common.message.ExtendedRequestImpl ;
+import org.apache.ldap.common.message.ModifyDnRequestImpl ;
+import org.apache.ldap.common.message.LockableAttributesImpl ;
+
+
+/**
+ * $todo$ doc me
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class LdapMessageTests extends AbstractDecoderTestCase
+{
+    public LdapMessageTests()
+    {
+        super ( LdapMessageTests.class.getName() ) ;
+    }
+    
+    
+    public void testBindMessage() throws Exception
+    {
+        BindRequestImpl request = new BindRequestImpl( BigInteger.ONE ) ;
+        request.setName( "uid=akarasulu,dc=example,dc=com" ) ;
+        request.setSimple( true ) ;
+        request.setCredentials( "password".getBytes() ) ;
+        request.setVersion3( true ) ;
+        decode( request ) ;
+        assertFalse( tlvList.isEmpty() ) ;
+    }
+
+
+    public void testAddMessage() throws Exception
+    {
+        AddRequestImpl request = new AddRequestImpl( BigInteger.ONE ) ;
+        request.setName( "uid=akarasulu,dc=example,dc=com" ) ;
+        
+        Attributes attrs = new LockableAttributesImpl() ;
+        attrs.put( "attr0", "val0" ) ;
+        attrs.put( "attr0", "val1" ) ;
+        attrs.put( "attr0", "val2" ) ;
+        attrs.put( "attr1", "val0" ) ;
+        attrs.put( "attr2", "val0" ) ;
+        attrs.put( "attr2", "val1" ) ;
+        
+        request.setEntry( attrs ) ;
+        decode( request ) ;
+        assertFalse( tlvList.isEmpty() ) ;
+    }
+
+
+    public void testDeleteMessage() throws Exception
+    {
+        DeleteRequestImpl request = new DeleteRequestImpl( BigInteger.ONE ) ;
+        request.setName( "uid=akarasulu,dc=example,dc=com" ) ;
+        decode( request ) ;
+        assertFalse( tlvList.isEmpty() ) ;
+    }
+
+
+    public void testAbandonMessage() throws Exception
+    {
+        AbandonRequestImpl request = new AbandonRequestImpl( BigInteger.ONE ) ;
+        request.setAbandoned( new BigInteger( "3" ) ) ;
+        decode( request ) ;
+        assertFalse( tlvList.isEmpty() ) ;
+    }
+
+
+    public void testCompareMessage() throws Exception
+    {
+        CompareRequestImpl request = new CompareRequestImpl( BigInteger.ONE ) ;
+        request.setAssertionValue( "testvalue" ) ;
+        request.setAttributeId( "testattr" ) ;
+        request.setName( "uid=akarasulu,dc=example,dc=com" ) ;
+        decode( request ) ;
+        assertFalse( tlvList.isEmpty() ) ;
+    }
+
+
+    public void testExtendedMessage() throws Exception
+    {
+        ExtendedRequestImpl request = new ExtendedRequestImpl( BigInteger.ONE ) ;
+        request.setOid( "1234.1234.1324" ) ;
+        request.setPayload( "Hello World".getBytes() ) ;
+        decode( request ) ;
+        assertFalse( tlvList.isEmpty() ) ;
+    }
+
+
+    public void testModifyDnMessage() throws Exception
+    {
+        ModifyDnRequestImpl request = new ModifyDnRequestImpl( BigInteger.ONE ) ;
+        request.setDeleteOldRdn(true) ;
+        request.setName( "uid=akarasulu,dc=example,dc=com" ) ;
+        request.setNewRdn( "uid=aok" ) ;
+        request.setNewSuperior( "dc=example,dc=com" ) ;
+        decode( request ) ;
+        assertFalse( tlvList.isEmpty() ) ;
+    }
+
+
+    public void testModifyMessage() throws Exception
+    {
+        ModifyRequestImpl request = new ModifyRequestImpl( BigInteger.ONE ) ;
+        request.setName( "uid=akarasulu,dc=example,dc=com" ) ;
+        decode( request ) ;
+        assertFalse( tlvList.isEmpty() ) ;
+    }
+
+
+    public void testSearchMessage() throws Exception
+    {
+        SearchRequestImpl request = new SearchRequestImpl( BigInteger.ONE ) ;
+        request.setBase( "uid=akarasulu,dc=example,dc=com" ) ;
+        request.setDerefAliases( DerefAliasesEnum.DEREFALWAYS ) ;
+        PresenceNode node = new PresenceNode( "attrib0" ) ;
+        request.setFilter( node ) ;
+        request.setScope( ScopeEnum.BASEOBJECT ) ;
+        request.setSizeLimit( BigInteger.ZERO ) ;
+        request.setTimeLimit( BigInteger.ZERO ) ;
+        decode( request ) ;
+        assertFalse( tlvList.isEmpty() ) ;
+    }
+}

Added: incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TupleTreeDecoderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ber/src/test/org/apache/snickers/ber/TupleTreeDecoderTest.java	Sat Mar 13 10:39:36 2004
@@ -0,0 +1,91 @@
+/*
+ *   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.ber;
+
+import java.io.ByteArrayOutputStream;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+
+import org.apache.commons.codec.stateful.DecoderCallback;
+import org.apache.commons.codec.stateful.StatefulDecoder;
+import org.apache.commons.lang.time.StopWatch;
+import org.apache.ldap.common.message.BindRequestImpl;
+import org.apache.ldap.common.message.MessageEncoder;
+
+import junit.framework.TestCase;
+
+/**
+ * $todo$ doc me
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class TupleTreeDecoderTest extends TestCase implements DecoderCallback
+{
+    DefaultMutableTupleNode root = null ;
+    
+    public static void main( String[] args)
+    {
+        TupleTreeDecoderTest test = new TupleTreeDecoderTest() ;
+        
+        try { test.testTTD() ; } catch ( Exception e ) { e.printStackTrace() ; } 
+    }
+    
+    public void testTTD() throws Exception
+    {
+        ByteArrayOutputStream out = new ByteArrayOutputStream() ;
+        
+        // Setup the bind request
+        BindRequestImpl l_request = new BindRequestImpl( BigInteger.ONE ) ;
+        l_request.setName( "uid=akarasulu,dc=example,dc=com" ) ;
+        l_request.setSimple( true ) ;
+        l_request.setCredentials( "password".getBytes() ) ;
+        l_request.setVersion3( true ) ;
+        
+        // Setup the ASN1 Enoder
+        MessageEncoder l_encoder = new MessageEncoder();
+ 
+        // Send encoded request to server
+        l_encoder.encode( null, out, l_request );
+        
+        StopWatch watch = new StopWatch() ;
+        watch.start() ;
+        TupleTreeDecoder decoder = new TupleTreeDecoder() ;
+        decoder.setCallback( this ) ;
+        decoder.decode( ByteBuffer.wrap( out.toByteArray() ) ) ;
+        watch.stop() ;
+        System.out.println( "time for decode = " + watch.getTime() ) ;
+        
+        StringBuffer buf = new StringBuffer() ;
+        root.printDepthFirst( buf, 0 ) ;
+        System.out.println( "tuple tlv tree =\n" + buf.toString() ) ;
+        TupleTreeAnalyzer analyzer = new TupleTreeAnalyzer( root ) ;
+        analyzer.startup() ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.commons.codec.stateful.DecoderCallback#
+     * decodeOccurred(org.apache.commons.codec.stateful.StatefulDecoder, 
+     * java.lang.Object)
+     */
+    public void decodeOccurred( StatefulDecoder decoder, Object decoded )
+    {
+        root = ( DefaultMutableTupleNode ) decoded ;
+    }
+}