directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r279887 [15/15] - in /directory/shared/ldap/branches/elecharny-cleanup/apache2-provider: ./ conf/ perfs/ perfs/org/ perfs/org/apache/ perfs/org/apache/asn1new/ perfs/org/apache/asn1new/ber/ src/ src/java/ src/java/main/ src/java/main/org/ s...
Date Fri, 09 Sep 2005 21:43:24 GMT
Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultEntryTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultEntryTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultEntryTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultEntryTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,370 @@
+/*
+ *   Copyright 2005 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+import java.util.HashSet;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.ldap.pojo.SearchResultEntry;
+import org.apache.asn1new.primitives.OctetString;
+import org.apache.asn1new.util.StringUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the SearchResultEntry codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SearchResultEntryTest extends TestCase {
+    /**
+     * Test the decoding of a SearchResultEntry
+     */
+    public void testDecodeSearchResultEntrySuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x50 );
+        
+        stream.put(
+            new byte[]
+            {
+                 
+                
+                0x30, 0x4e, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				0x64, 0x49, 		//     CHOICE { ..., searchResEntry  SearchResultEntry, ...
+                        			// SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+									//     objectName      LDAPDN,
+				0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm',
+									//     attributes      PartialAttributeList }
+									// PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30, 0x2a, 
+                0x30, 0x28, 
+                					//     type    AttributeDescription,
+                0x04, 0x0b, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+                					//     vals    SET OF AttributeValue }
+                0x31, 0x19, 
+                					// AttributeValue ::= OCTET STRING
+                0x04, 0x03, 't', 'o', 'p', 
+									// AttributeValue ::= OCTET STRING
+                0x04, 0x12, 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a', 't', 'i', 'o', 'n', 'a', 'l', 'U', 'n', 'i', 't'
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a BindRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        SearchResultEntry searchResultEntry      = message.getSearchResultEntry();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName() );
+
+        Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+        
+        Assert.assertEquals( 1, partialAttributesList.size() );
+        
+        for ( int i = 0; i < partialAttributesList.size(); i++ )
+        {
+            BasicAttribute attributeValue = (BasicAttribute)partialAttributesList.get( "objectclass" );
+            
+            Assert.assertEquals( "objectClass".toLowerCase(), attributeValue.getID().toLowerCase() );
+            
+            NamingEnumeration values = attributeValue.getAll();
+            
+            HashSet expectedValues = new HashSet();
+            
+            expectedValues.add( "top" );
+            expectedValues.add( "organizationalUnit" ); 
+            
+            while ( values.hasMore() )
+            {
+                OctetString value = (OctetString)values.next();
+                
+                Assert.assertTrue( expectedValues.contains( value.toString() ) );
+                
+                expectedValues.remove( value.toString() );
+            }
+        }
+        
+        // Check the length
+        Assert.assertEquals(0x50, message.computeLength());
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+
+    /**
+     * Test the decoding of a SearchResultEntry
+     */
+    public void testDecodeSearchResultEntry2AttrsSuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x7b );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x79, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				0x64, 0x74, 		//     CHOICE { ..., searchResEntry  SearchResultEntry, ...
+                        			// SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+									//     objectName      LDAPDN,
+				0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm',
+									//     attributes      PartialAttributeList }
+									// PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30, 0x55, 
+                0x30, 0x28, 
+                					//     type    AttributeDescription,
+                0x04, 0x0b, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+                					//     vals    SET OF AttributeValue }
+                0x31, 0x19, 
+                					// AttributeValue ::= OCTET STRING
+                0x04, 0x03, 't', 'o', 'p', 
+									// AttributeValue ::= OCTET STRING
+                0x04, 0x12, 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a', 't', 'i', 'o', 'n', 'a', 'l', 'U', 'n', 'i', 't',
+                0x30, 0x29, 
+				//     type    AttributeDescription,
+				0x04, 0x0c, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', '2',
+								//     vals    SET OF AttributeValue }
+				0x31, 0x19, 
+								// AttributeValue ::= OCTET STRING
+				0x04, 0x03, 't', 'o', 'p', 
+								// AttributeValue ::= OCTET STRING
+				0x04, 0x12, 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a', 't', 'i', 'o', 'n', 'a', 'l', 'U', 'n', 'i', 't'
+            } );
+
+        stream.flip();
+
+        // Allocate a BindRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        SearchResultEntry searchResultEntry      = message.getSearchResultEntry();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName() );
+
+        Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+        
+        Assert.assertEquals( 2, partialAttributesList.size() );
+        
+        String[] expectedAttributes = new String[]{"objectClass", "objectClass2"}; 
+        
+        for ( int i = 0; i < expectedAttributes.length; i++ )
+        {
+            BasicAttribute attributeValue = (BasicAttribute)partialAttributesList.get( expectedAttributes[i] );
+            
+            Assert.assertEquals( expectedAttributes[i].toLowerCase(), attributeValue.getID().toLowerCase() );
+            
+            NamingEnumeration values = attributeValue.getAll();
+            
+            HashSet expectedValues = new HashSet();
+            
+            expectedValues.add( "top" );
+            expectedValues.add( "organizationalUnit" ); 
+            
+            while ( values.hasMore() )
+            {
+                OctetString value = (OctetString)values.next();
+                
+                Assert.assertTrue( expectedValues.contains( value.toString() ) );
+                
+                expectedValues.remove( value.toString() );
+            }
+        }
+        
+        // Check the length
+        Assert.assertEquals(0x7b, message.computeLength());
+
+        // Check the encoding
+        try
+        {
+            message.encode( null );
+            
+            // We cant compare the encodings, the order of the attributes has changed
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+    
+    /**
+     * Test the decoding of a SearchResultEntry with more bytes
+     * to be decoded at the end
+     */
+    public void testDecodeSearchResultEntrySuccessWithFollowingMessage() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x66 );
+        
+        stream.put(
+            new byte[]
+            {
+                  0x30, 0x5F, 		// LDAPMessage ::=SEQUENCE {
+                  0x02, 0x01, 0x02, //     messageID MessageID
+                  0x64, 0x5A,       //     CHOICE { ..., searchResEntry  SearchResultEntry, ...
+      								// SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+									//     objectName      LDAPDN,
+                    0x04, 0x13, 'u', 'i', 'd', '=', 'a', 'd', 'm', 'i', 'n', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
+									//     attributes      PartialAttributeList }
+                    0x30, 0x43, 	// PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+                      0x30, 0x41, 
+                      				//     type    AttributeDescription,
+                        0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 
+                        0x31, 0x32, //     vals    SET OF AttributeValue }
+                        			// AttributeValue ::= OCTET STRING
+                          0x04, 0x0D, 'i', 'n', 'e', 't', 'O', 'r', 'g', 'P', 'e', 'r', 's', 'o', 'n',  
+              						// AttributeValue ::= OCTET STRING
+                          0x04, 0x14, 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a', 't', 'i', 'o', 'n', 'a', 'l', 'P', 'e', 'r', 's', 'o', 'n', 
+              						// AttributeValue ::= OCTET STRING
+                          0x04, 0x06, 'p', 'e', 'r', 's', 'o', 'n', 
+              						// AttributeValue ::= OCTET STRING
+                          0x04, 0x03, 't', 'o', 'p', 
+                  0x30, 0x45, 		// Start of the next message
+                  0x02, 0x01, 0x02  // messageID MessageID ...
+            } );
+                
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a BindRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        SearchResultEntry searchResultEntry      = message.getSearchResultEntry();
+
+        Assert.assertEquals( 2, message.getMessageId() );
+        Assert.assertEquals( "uid=admin,ou=system", searchResultEntry.getObjectName() );
+
+        Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+        
+        Assert.assertEquals( 1, partialAttributesList.size() );
+        
+        for ( int i = 0; i < partialAttributesList.size(); i++ )
+        {
+            BasicAttribute attributeValue = (BasicAttribute)partialAttributesList.get( "objectclass" );
+            
+            Assert.assertEquals( "objectClass".toLowerCase(), attributeValue.getID().toLowerCase() );
+            
+            NamingEnumeration values = attributeValue.getAll();
+            
+            HashSet expectedValues = new HashSet();
+            
+            expectedValues.add( "top" );
+            expectedValues.add( "person" );
+            expectedValues.add( "organizationalPerson" ); 
+            expectedValues.add( "inetOrgPerson" ); 
+            
+            while ( values.hasMore() )
+            {
+                OctetString value = (OctetString)values.next();
+                
+                Assert.assertTrue( expectedValues.contains( value.toString() ) );
+                
+                expectedValues.remove( value.toString() );
+            }
+        }
+        
+        // Check the length
+        Assert.assertEquals(0x61, message.computeLength());
+        
+        // Check that the next bytes is the first of the next PDU
+        Assert.assertEquals(0x30, stream.get(stream.position()));
+        Assert.assertEquals(0x45, stream.get(stream.position() + 1));
+        Assert.assertEquals(0x02, stream.get(stream.position() + 2));
+        Assert.assertEquals(0x01, stream.get(stream.position() + 3));
+        Assert.assertEquals(0x02, stream.get(stream.position() + 4));
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            // We have to supress the last 5 chars from the decodedPDU, as they
+            // belongs to the next message.
+            Assert.assertEquals(encodedPdu, decodedPdu.substring(0, 0x61 * 5) );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultEntryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultReferenceTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultReferenceTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultReferenceTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultReferenceTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,171 @@
+/*
+ *   Copyright 2005 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import javax.naming.NamingException;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.codec.primitives.LdapURL;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.ldap.pojo.SearchResultReference;
+import org.apache.asn1new.util.StringUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the SearchResultReference codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SearchResultReferenceTest extends TestCase {
+    /**
+     * Test the decoding of a SearchResultReference
+     */
+    public void testDecodeSearchResultReferenceSuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x3d8 );
+        
+        String[] ldapUrls = new String[] 
+                                       {
+                                       	"ldap:///",
+                       			        "ldap://directory.apache.org:80/",
+                       			        "ldap://d-a.org:80/",
+                       			        "ldap://1.2.3.4/",
+                       			        "ldap://1.2.3.4:80/",
+                       			        "ldap://1.1.1.100000.a/",
+                       			        "ldap://directory.apache.org:389/dc=example,dc=org/",
+                       			        "ldap://directory.apache.org:389/dc=example",
+                       			        "ldap://directory.apache.org:389/dc=example%202,dc=org",
+                       			        "ldap://directory.apache.org:389/dc=example,dc=org?ou",
+                       			        "ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc",
+                       			        "ldap://directory.apache.org:389/dc=example,dc=org?ou,dc,ou",
+                       			        "ldap:///o=University%20of%20Michigan,c=US",
+                       			        "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US",
+                       			        "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress",
+                       			        "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)",
+                       			        "ldap://ldap.itd.umich.edu/c=GB?objectClass?one",
+                       			        "ldap://ldap.question.com/o=Question%3f,c=US?mail",
+                       			        "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)",
+                       			        "ldap:///??sub??bindname=cn=Manager%2co=Foo",
+                       			        "ldap:///??sub??!bindname=cn=Manager%2co=Foo"
+                       			    };
+
+        stream.put(
+            new byte[]
+            {
+                 
+                
+                0x30, (byte)0x82, 0x03, (byte)0xd4,	// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 					//     messageID MessageID
+				0x73, (byte)0x82, 0x03, (byte)0xcd, //     CHOICE { ..., searchResEntry  SearchResultEntry, ...
+                        							// SearchResultReference ::= [APPLICATION 19] SEQUENCE OF LDAPURL
+            } );
+
+        
+        for (int i = 0; i < ldapUrls.length; i++)
+        {
+            stream.put((byte)0x04);
+            stream.put((byte)ldapUrls[i].getBytes().length);
+            
+            byte[] bytes = ldapUrls[i].getBytes();
+            
+            for (int j=0; j < bytes.length; j++)
+            {
+                stream.put(bytes[j]);
+            }
+        }
+        
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a BindRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        SearchResultReference searchResultReference      = message.getSearchResultReference();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        
+        HashSet ldapUrlsSet = new HashSet();
+        
+        try {
+	        for (int i = 0; i < ldapUrls.length; i++)
+	        {
+	            ldapUrlsSet.add( new LdapURL( ldapUrls[i].getBytes() ).toString() );
+	        }
+        } catch (DecoderException de)
+        {
+            Assert.fail();
+        }
+        
+        Iterator iter = searchResultReference.getSearchResultReferences().iterator();
+        
+        while (iter.hasNext())
+        {
+            LdapURL ldapUrl = (LdapURL)iter.next();
+            
+            if (ldapUrlsSet.contains( ldapUrl.toString()) )
+            {
+                ldapUrlsSet.remove( ldapUrl.toString() );
+            }
+            else
+            {
+                Assert.fail(ldapUrl.toString() + " is not present");
+            }
+        }
+        
+        Assert.assertTrue( ldapUrlsSet.size() == 0 );
+        
+        // Check the length
+        Assert.assertEquals(0x3D8, message.computeLength());
+        
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultReferenceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/UnBindRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/UnBindRequestTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/UnBindRequestTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/UnBindRequestTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,89 @@
+/*
+ *   Copyright 2005 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class UnBindRequestTest extends TestCase {
+    /**
+     * Test the decoding of a UnBindRequest with no controls
+     */
+    public void testDecodeUnBindRequestNoControls()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x07 );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x05, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//         messageID MessageID
+				0x42, 0x00, 		//        CHOICE { ..., unbindRequest UnbindRequest,...
+									// UnbindRequest ::= [APPLICATION 2] NULL
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a BindRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        
+        // Check the length
+        Assert.assertEquals(7, message.computeLength());
+
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/UnBindRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/DNUtilsTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/DNUtilsTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/DNUtilsTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/DNUtilsTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,136 @@
+/*
+ *   Copyright 2005 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.asn1new.ldap.codec.utils;
+
+import org.apache.asn1new.util.StringUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the class DNUtils
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DNUtilsTest extends TestCase
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+	/**
+     * Test the DNUtils AreEquals method
+     */
+    public void testAreEqualsFull()
+    {
+        // Full compare
+        Assert.assertEquals( 6, StringUtils.areEquals( "azerty".getBytes(), 0, "azerty" ) );
+    }
+
+    /**
+     * Test the DNUtils AreEquals method
+     */
+    public void testAreEqualsDiff()
+    {
+        // First character is !=
+        Assert.assertEquals( -1, StringUtils.areEquals( "azerty".getBytes(), 0, "Azerty" ) );
+    }
+
+    /**
+     * Test the DNUtils AreEquals method
+     */
+    public void testAreEqualsEmpty()
+    {
+        // Compare to an empty string
+        Assert.assertEquals( -1, StringUtils.areEquals( "azerty".getBytes(), 0, "" ) );
+    }
+
+    /**
+     * Test the DNUtils AreEquals method
+     */
+    public void testAreEqualsFirstCharDiff()
+    {
+        // First character is !=
+        Assert.assertEquals( -1, StringUtils.areEquals( "azerty".getBytes(), 0, "Azerty" ) );
+    }
+    
+    /**
+     * Test the DNUtils AreEquals method
+     */
+    public void testAreEqualsMiddleCharDiff()
+    {
+        // First character is !=
+        Assert.assertEquals( -1, StringUtils.areEquals( "azerty".getBytes(), 0, "azeRty" ) );
+    }
+    
+    /**
+     * Test the DNUtils AreEquals method
+     */
+    public void testAreEqualsLastCharDiff()
+    {
+        // First character is !=
+        Assert.assertEquals( -1, StringUtils.areEquals( "azerty".getBytes(), 0, "azertY" ) );
+    }
+    
+    /**
+     * Test the DNUtils AreEquals method
+     */
+    public void testAreEqualsCharByChar()
+    {
+        // Index must be incremented after each comparison
+        Assert.assertEquals( 1, StringUtils.areEquals( "azerty".getBytes(), 0, "a" ) );
+        Assert.assertEquals( 2, StringUtils.areEquals( "azerty".getBytes(), 1, "z" ) );
+        Assert.assertEquals( 3, StringUtils.areEquals( "azerty".getBytes(), 2, "e" ) );
+        Assert.assertEquals( 4, StringUtils.areEquals( "azerty".getBytes(), 3, "r" ) );
+        Assert.assertEquals( 5, StringUtils.areEquals( "azerty".getBytes(), 4, "t" ) );
+        Assert.assertEquals( 6, StringUtils.areEquals( "azerty".getBytes(), 5, "y" ) );
+    }
+
+    /**
+     * Test the DNUtils AreEquals method
+     */
+    public void testAreEqualsTooShort()
+    {
+        // length too short
+        Assert.assertEquals( -1, StringUtils.areEquals( "azerty".getBytes(), 0, "azertyiop" ) );
+    }
+
+    /**
+     * Test the DNUtils AreEquals method
+     */
+    public void testAreEqualsTooShortMiddle()
+    {
+        // length too short
+        Assert.assertEquals( -1, StringUtils.areEquals( "azerty".getBytes(), 0, "ertyiop" ) );
+    }
+
+    /**
+     * Test the DNUtils AreEquals method
+     */
+    public void testAreEqualsLastChar()
+    {
+        // last character
+        Assert.assertEquals( 6, StringUtils.areEquals( "azerty".getBytes(), 5, "y" ) );
+    }
+
+    /**
+     * Test the DNUtils AreEquals method
+     */
+    public void testAreEqualsMiddle()
+    {
+        // In the middle
+        Assert.assertEquals( 4, StringUtils.areEquals( "azerty".getBytes(), 2, "er" ) );
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/DNUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapDNTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapDNTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapDNTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapDNTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,171 @@
+/*
+ *   Copyright 2005 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.asn1new.ldap.codec.utils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.ldap.codec.primitives.LdapDN;
+
+/**
+ * Test the class LdapDN
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapDNTest extends TestCase
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Setup the test
+     */
+    protected void setUp()
+    {
+    }
+
+    /**
+     * Test a null DN
+     */
+    public void testLdapDNNull() throws DecoderException
+    {
+        Assert.assertEquals( "", new LdapDN( null ).toString() );
+    }
+
+    /**
+     * test an empty DN
+     */
+    public void testLdapDNEmpty() throws DecoderException
+    {
+        Assert.assertEquals( "", new LdapDN( "".getBytes() ).toString() );
+    }
+
+    /**
+     * test a simple DN : a = b
+     */
+    public void testLdapDNSimple() throws DecoderException
+    {
+        Assert.assertEquals( "a = b", new LdapDN( "a = b".getBytes() ).toString() );
+    }
+
+    /**
+     * test a composite DN : a = b, d = e
+     */
+    public void testLdapDNComposite() throws DecoderException
+    {
+        Assert.assertEquals( "a = b, c = d", new LdapDN( "a = b, c = d".getBytes() ).toString() );
+    }
+
+    /**
+     * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a  =  b
+     */
+    public void testLdapDNCompositeWithSpace() throws DecoderException
+    {
+        Assert.assertEquals( "a=b, a =b, a= b, a = b, a  =  b",
+                new LdapDN( "a=b, a =b, a= b, a = b, a  =  b".getBytes() ).toString() );
+    }
+
+    /**
+     * test a composite DN with differents separators : a=b;c=d,e=f
+     * It should return a=b,c=d,e=f (the ';' is replaced by a ',')
+     */
+    public void testLdapDNCompositeSepators() throws DecoderException
+    {
+        Assert.assertEquals( "a=b,c=d,e=f", new LdapDN( "a=b;c=d,e=f".getBytes() ).toString() );
+    }
+
+    /**
+     * test a simple DN with differents separators : a = b + c = d
+     */
+    public void testLdapDNSimpleMultivaluedAttribute() throws DecoderException
+    {
+        Assert.assertEquals( "a = b + c = d",
+                new LdapDN( "a = b + c = d".getBytes() ).toString() );
+    }
+
+    /**
+     * test a composite DN with differents separators : a=b+c=d, e=f + g=h + i=j
+     */
+    public void testLdapDNCompositeMultivaluedAttribute() throws DecoderException
+    {
+        Assert.assertEquals( "a=b+c=d, e=f + g=h + i=j",
+                new LdapDN( "a=b+c=d, e=f + g=h + i=j".getBytes() ).toString() );
+    }
+
+    /**
+     * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
+     */
+    public void testLdapDNOidUpper() throws DecoderException
+    {
+        Assert.assertEquals( "OID.12.34.56 = azerty",
+                new LdapDN( "OID.12.34.56 = azerty".getBytes() ).toString() );
+    }
+
+    /**
+     * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
+     */
+    public void testLdapDNOidLower() throws DecoderException
+    {
+        Assert.assertEquals( "oid.12.34.56 = azerty",
+                new LdapDN( "oid.12.34.56 = azerty".getBytes() ).toString() );
+    }
+
+    /**
+     * test a simple DN with an oid attribut wiithout oid prefix : 12.34.56 = azerty
+     */
+    public void testLdapDNOidWithoutPrefix() throws DecoderException
+    {
+        Assert.assertEquals( "12.34.56 = azerty",
+                new LdapDN( "12.34.56 = azerty".getBytes() ).toString() );
+    }
+
+    /**
+     * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 = azerty; 7.8 = test
+     */
+    public void testLdapDNCompositeOidWithoutPrefix() throws DecoderException
+    {
+        Assert.assertEquals( "12.34.56 = azerty, 7.8 = test",
+                new LdapDN( "12.34.56 = azerty; 7.8 = test".getBytes() ).toString() );
+    }
+
+    /**
+     * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\A0\00"
+     */
+    public void testLdapDNPairCharAttributeValue() throws DecoderException
+    {
+        Assert.assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\A0\\00",
+                new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\A0\\00".getBytes() ).toString() );
+    }
+
+    /**
+     * test a simple DN with hexString attribute value : a = #0010A0AAFF
+     */
+    public void testLdapDNHexStringAttributeValue() throws DecoderException
+    {
+        Assert.assertEquals( "a = #0010A0AAFF",
+                new LdapDN( "a = #0010A0AAFF".getBytes() ).toString() );
+    }
+
+    /**
+     * test a simple DN with quoted attribute value : a = "quoted \"value"
+     */
+    public void testLdapDNQuotedAttributeValue() throws DecoderException
+    {
+        Assert.assertEquals( "a = quoted \\\"value",
+                new LdapDN( "a = quoted \\\"value".getBytes() ).toString() );
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapDNTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapUrlTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapUrlTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapUrlTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapUrlTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,540 @@
+/*
+ *   Copyright 2005 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.asn1new.ldap.codec.utils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.ldap.codec.primitives.LdapURL;
+
+/**
+ * Test the class LdapURL
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapUrlTest extends TestCase
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Setup the test
+     */
+    protected void setUp()
+    {
+    }
+
+    /**
+     * Test a null LdapURL
+     */
+    public void testLdapUrlNull() throws DecoderException
+    {
+        Assert.assertEquals( "ldap:///", new LdapURL().toString() );
+    }
+
+    /**
+     * test an empty LdapURL
+     */
+    public void testLdapDNEmpty() throws DecoderException
+    {
+        Assert.assertEquals( "ldap:///", new LdapURL( "".getBytes() ).toString() );
+    }
+
+    /**
+     * test a simple LdapURL
+     */
+    public void testLdapDNSimple() throws DecoderException
+    {
+        Assert.assertEquals( "ldap://directory.apache.org:80/", new LdapURL( "ldap://directory.apache.org:80/".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL host 1
+     */
+    public void testLdapDNWithMinus() throws DecoderException
+    {
+        Assert.assertEquals( "ldap://d-a.org:80/", new LdapURL( "ldap://d-a.org:80/".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with a bad port
+     */
+    public void testLdapDNBadPort() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad port 2
+     */
+    public void testLdapDNBadPort2() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:-1/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad port 3
+     */
+    public void testLdapDNBadPort3() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:abc/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad port 4
+     */
+    public void testLdapDNBadPort4() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:65536/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with no host 
+     */
+    public void testLdapDNBadHost1() throws DecoderException
+    {
+        Assert.assertEquals("ldap:///", new LdapURL( "ldap:///".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with a bad host 2
+     */
+    public void testLdapDNBadHost2() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://./".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+    
+    /**
+     * test a LdapURL with a bad host 3
+     */
+    public void testLdapDNBadHost3() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://a..b/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad host 4
+     */
+    public void testLdapDNBadHost4() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://-/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad host 5
+     */
+    public void testLdapDNBadHost5() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://a.b.c-/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad host 6
+     */
+    public void testLdapDNBadHost6() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://a.b.-c/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad host 7
+     */
+    public void testLdapDNBadHost7() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://a.-.c/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL IP host
+     */
+    public void testLdapDNIPHost() throws DecoderException
+    {
+        Assert.assertEquals( "ldap://1.2.3.4/", new LdapURL( "ldap://1.2.3.4/".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL IP host and port
+     */
+    public void testLdapDNIPHostPort() throws DecoderException
+    {
+        Assert.assertEquals( "ldap://1.2.3.4:80/", new LdapURL( "ldap://1.2.3.4:80/".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with a bad IP host 1
+     */
+    public void testLdapDNBadHostIP1() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://1.1.1/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad IP host 2
+     */
+    public void testLdapDNBadHostIP2() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://1.1.1./".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad IP host 3
+     */
+    public void testLdapDNBadHostIP3() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://1.1.1.100000/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a bad IP host 4
+     */
+    public void testLdapDNBadHostIP4() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://1.1.1.1.1/".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+        
+        Assert.fail();
+    }
+
+    /**
+     * test a LdapURL with a valid host hich is not an IP
+     */
+    public void testLdapDNNotAnIP() throws DecoderException
+    {
+        Assert.assertEquals("ldap://1.1.1.100000.a/", new LdapURL( "ldap://1.1.1.100000.a/".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with valid simpleDN
+     */
+    public void testLdapDNSimpleDN() throws DecoderException
+    {
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org/", new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org/".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with valid simpleDN 2
+     */
+    public void testLdapDNSimpleDN2() throws DecoderException
+    {
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example", new LdapURL( "ldap://directory.apache.org:389/dc=example".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with a valid encoded DN
+     */
+    public void testLdapDNSimpleDNEncoded() throws DecoderException
+    {
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example%202,dc=org", new LdapURL( "ldap://directory.apache.org:389/dc=example%202,dc=org".getBytes() ).toString() );
+    }
+    
+    /**
+     * test a LdapURL with an invalid DN
+     */
+    public void testLdapDNInvalidDN() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:389/dc=example%202,dc : org".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+    }
+
+    /**
+     * test a LdapURL with an invalid DN 2
+     */
+    public void testLdapDNInvalidDN2() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:389/dc=example%202,dc = org,".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+    }
+
+    /**
+     * test a LdapURL with valid unique attributes
+     */
+    public void testLdapDNUniqueAttribute() throws DecoderException
+    {
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org?ou", new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with valid attributes
+     */
+    public void testLdapDNAttributes() throws DecoderException
+    {
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc", new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with valid duplicated attributes
+     */
+    public void testLdapDNDuplicatedAttributes() throws DecoderException
+    {
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org?ou,dc", new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou,dc,ou".getBytes() ).toString() );
+    }
+
+    /**
+     * test a LdapURL with invalid attributes
+     */
+    public void testLdapInvalideAttributes() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou=,dc".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+    }
+    /**
+     * test a LdapURL with attributes but no DN
+     */
+    public void testLdapNoDNAttributes() throws DecoderException
+    {
+        try 
+        {
+            new LdapURL( "ldap://directory.apache.org:389/?ou,dc".getBytes() );
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+            return;
+        }
+    }
+
+    /**
+     * test 1 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_1() throws DecoderException
+    {
+        Assert.assertEquals("ldap:///o=University%20of%20Michigan,c=US", new LdapURL( "ldap:///o=University%20of%20Michigan,c=US".getBytes() ).toString() );
+    }
+    
+    /**
+     * test 2 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_2() throws DecoderException
+    {
+        Assert.assertEquals("ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US", new LdapURL( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US".getBytes() ).toString() );
+    }
+
+    /**
+     * test 3 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_3() throws DecoderException
+    {
+        Assert.assertEquals("ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress", new LdapURL( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress".getBytes() ).toString() );
+    }
+
+    /**
+     * test 4 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_4() throws DecoderException
+    {
+        Assert.assertEquals("ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)", new LdapURL( "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)".getBytes() ).toString() );
+    }
+
+    /**
+     * test 5 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_5() throws DecoderException
+    {
+        Assert.assertEquals("ldap://ldap.itd.umich.edu/c=GB?objectClass?one", new LdapURL( "ldap://ldap.itd.umich.edu/c=GB?objectClass?one".getBytes() ).toString() );
+    }
+
+    /**
+     * test 6 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_6() throws DecoderException
+    {
+        Assert.assertEquals("ldap://ldap.question.com/o=Question%3f,c=US?mail", new LdapURL( "ldap://ldap.question.com/o=Question%3f,c=US?mail".getBytes() ).toString() );
+    }
+
+    /**
+     * test 7 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_7() throws DecoderException
+    {
+        Assert.assertEquals("ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", new LdapURL( "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)".getBytes() ).toString() );
+    }
+
+    /**
+     * test 8 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_8() throws DecoderException
+    {
+        Assert.assertEquals("ldap:///??sub??bindname=cn=Manager%2co=Foo", new LdapURL( "ldap:///??sub??bindname=cn=Manager%2co=Foo".getBytes() ).toString() );
+    }
+
+    /**
+     * test 9 from RFC 2255 LdapURL 
+     */
+    public void testLdapRFC2255_9() throws DecoderException
+    {
+        Assert.assertEquals("ldap:///??sub??!bindname=cn=Manager%2co=Foo", new LdapURL( "ldap:///??sub??!bindname=cn=Manager%2co=Foo".getBytes() ).toString() );
+    }
+}
+

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapUrlTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message