directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r503338 - in /directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap: filter/FilterParserImplTest.java name/LdapDNTest.java name/LdapDnParserTest.java
Date Sun, 04 Feb 2007 00:35:32 GMT
Author: elecharny
Date: Sat Feb  3 16:35:32 2007
New Revision: 503338

URL: http://svn.apache.org/viewvc?view=rev&rev=503338
Log:
Reformatted LdapDnParserTest
Remove so useless toString() calls
Remove some dead code

Modified:
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserImplTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserImplTest.java?view=diff&rev=503338&r1=503337&r2=503338
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/filter/FilterParserImplTest.java
Sat Feb  3 16:35:32 2007
@@ -664,24 +664,4 @@
         assertNull( node.getInitial() );
         assertNull( node.getFinal() );
     }
-
-    /* @todo look at custom error handlers for the parser */
-    // ///// Causes parser to hang rather than really bombing out. Looks like
-    // ///// we may need to implement a custom error handler for this parser.
-    // public void testSubstringNoAnyDoubleStar() throws IOException,
-    // ParseException
-    // {
-    // SubstringNode node = null;
-    //
-    // try
-    // {
-    // node = ( SubstringNode ) parser.parse( "( ou = foo**bar )" );
-    // fail("should not get here");
-    // }
-    // catch( Exception e )
-    // {
-    // }
-    //
-    // assertNull( node );
-    // }
 }

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java?view=diff&rev=503338&r1=503337&r2=503338
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
Sat Feb  3 16:35:32 2007
@@ -1612,12 +1612,12 @@
 
            if ( i == 0 )
            {
-               assertEquals( "ou=East", element.toString() );
+               assertEquals( "ou=East", element );
            }
 
            if ( i == 1 )
            {
-               assertEquals( "ou=Marketing", element.toString() );
+               assertEquals( "ou=Marketing", element );
            }
        }
 
@@ -1630,17 +1630,17 @@
 
            if ( i == 0 )
            {
-               assertEquals( "ou=East", element.toString() );
+               assertEquals( "ou=East", element );
            }
 
            if ( i == 1 )
            {
-               assertEquals( "ou=Marketing", element.toString() );
+               assertEquals( "ou=Marketing", element );
            }
 
            if ( i == 2 )
            {
-               assertEquals( "cn=John", element.toString() );
+               assertEquals( "cn=John", element );
            }
        }
 
@@ -1653,22 +1653,22 @@
 
            if ( i == 0 )
            {
-               assertEquals( "ou=East", element.toString() );
+               assertEquals( "ou=East", element );
            }
 
            if ( i == 1 )
            {
-               assertEquals( "ou=Marketing", element.toString() );
+               assertEquals( "ou=Marketing", element );
            }
 
            if ( i == 2 )
            {
-               assertEquals( "cn=John", element.toString() );
+               assertEquals( "cn=John", element );
            }
 
            if ( i == 3 )
            {
-               assertEquals( "cn=HomeDir", element.toString() );
+               assertEquals( "cn=HomeDir", element );
            }
        }
 
@@ -1681,27 +1681,27 @@
 
            if ( i == 0 )
            {
-               assertEquals( "ou=West", element.toString() );
+               assertEquals( "ou=West", element );
            }
 
            if ( i == 1 )
            {
-               assertEquals( "ou=Marketing", element.toString() );
+               assertEquals( "ou=Marketing", element );
            }
 
            if ( i == 2 )
            {
-               assertEquals( "cn=John", element.toString() );
+               assertEquals( "cn=John", element );
            }
 
            if ( i == 3 )
            {
-               assertEquals( "cn=HomeDir", element.toString() );
+               assertEquals( "cn=HomeDir", element );
            }
 
            if ( i == 4 )
            {
-               assertEquals( "cn=Website", element.toString() );
+               assertEquals( "cn=Website", element );
            }
        }
 
@@ -1714,32 +1714,32 @@
 
            if ( i == 0 )
            {
-               assertEquals( "ou=West", element.toString() );
+               assertEquals( "ou=West", element );
            }
 
            if ( i == 1 )
            {
-               assertEquals( "ou=Marketing", element.toString() );
+               assertEquals( "ou=Marketing", element );
            }
 
            if ( i == 2 )
            {
-               assertEquals( "cn=John", element.toString() );
+               assertEquals( "cn=John", element );
            }
 
            if ( i == 3 )
            {
-               assertEquals( "cn=HomeDir", element.toString() );
+               assertEquals( "cn=HomeDir", element );
            }
 
            if ( i == 4 )
            {
-               assertEquals( "cn=Website", element.toString() );
+               assertEquals( "cn=Website", element );
            }
 
            if ( i == 5 )
            {
-               assertEquals( "cn=Airline", element.toString() );
+               assertEquals( "cn=Airline", element );
            }
        }
    }
@@ -1764,32 +1764,32 @@
 
            if ( i == 0 )
            {
-               assertEquals( "ou=West", element.toString() );
+               assertEquals( "ou=West", element );
            }
 
            if ( i == 1 )
            {
-               assertEquals( "ou=Marketing", element.toString() );
+               assertEquals( "ou=Marketing", element );
            }
 
            if ( i == 2 )
            {
-               assertEquals( "cn=John", element.toString() );
+               assertEquals( "cn=John", element );
            }
 
            if ( i == 3 )
            {
-               assertEquals( "cn=HomeDir", element.toString() );
+               assertEquals( "cn=HomeDir", element );
            }
 
            if ( i == 4 )
            {
-               assertEquals( "cn=Website", element.toString() );
+               assertEquals( "cn=Website", element );
            }
 
            if ( i == 5 )
            {
-               assertEquals( "cn=Airline", element.toString() );
+               assertEquals( "cn=Airline", element );
            }
        }
    }

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java?view=diff&rev=503338&r1=503337&r2=503338
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDnParserTest.java
Sat Feb  3 16:35:32 2007
@@ -39,511 +39,514 @@
  */
 public class LdapDnParserTest extends TestCase
 {
-   // ~ Methods
-   // ------------------------------------------------------------------------------------
+    // ~ Methods
+    // ------------------------------------------------------------------------------------
 
-   // CONSTRUCTOR functions --------------------------------------------------
+    // CONSTRUCTOR functions --------------------------------------------------
 
-   /**
-    * test an empty DN
-    */
-   public void testLdapDNEmpty() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-
-       Assert.assertEquals( "", ( ( LdapDN ) dnParser.parse( "" ) ).getUpName() );
-   }
-
-
-   /**
-    * test a simple DN : a = b
-    */
-   public void testLdapDNSimple() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-
-       Assert.assertEquals( "a = b", ( ( LdapDN ) dnParser.parse( "a = b" ) ).getUpName()
);
-       Assert.assertEquals( "a=b", ( ( LdapDN ) dnParser.parse( "a = b" ) ).toString() );
-   }
-
-
-   /**
-    * test a composite DN : a = b, d = e
-    */
-   public void testLdapDNComposite() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "a = b, c = d" );
-       Assert.assertEquals( "a=b,c=d", dn.toString() );
-       Assert.assertEquals( "a = b, c = d", dn.getUpName() );
-   }
-
-
-   /**
-    * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
-    */
-   public void testLdapDNCompositeWithSpace() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "a=b, a =b, a= b, a = b, a  =  b" );
-       Assert.assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
-       Assert.assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
-   }
-
-
-   /**
-    * 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 NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "a=b;c=d,e=f" );
-       Assert.assertEquals( "a=b,c=d,e=f", dn.toString() );
-       Assert.assertEquals( "a=b;c=d,e=f", dn.getUpName() );
-   }
-
-
-   /**
-    * test a simple DN with multiple NameComponents : a = b + c = d
-    */
-   public void testLdapDNSimpleMultivaluedAttribute() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "a = b + c = d" );
-       Assert.assertEquals( "a=b+c=d", dn.toString() );
-       Assert.assertEquals( "a = b + c = d", dn.getUpName() );
-   }
-
-
-   /**
-    * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
-    * i=j
-    */
-   public void testLdapDNCompositeMultivaluedAttribute() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "a=b+c=d, e=f + g=h + i=j" );
-       Assert.assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
-       Assert.assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
-   }
-
-
-   /**
-    * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
-    */
-   public void testLdapDNOidUpper() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "OID.12.34.56 = azerty" );
-       Assert.assertEquals( "oid.12.34.56=azerty", dn.toString() );
-       Assert.assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
-   }
-
-
-   /**
-    * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
-    */
-   public void testLdapDNOidLower() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "oid.12.34.56 = azerty" );
-       Assert.assertEquals( "oid.12.34.56=azerty", dn.toString() );
-       Assert.assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
-   }
-
-
-   /**
-    * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
-    * azerty
-    */
-   public void testLdapDNOidWithoutPrefix() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "12.34.56 = azerty" );
-       Assert.assertEquals( "12.34.56=azerty", dn.toString() );
-       Assert.assertEquals( "12.34.56 = azerty", dn.getUpName() );
-   }
-
-
-   /**
-    * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
-    * azerty; 7.8 = test
-    */
-   public void testLdapDNCompositeOidWithoutPrefix() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "12.34.56 = azerty; 7.8 = test" );
-       Assert.assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
-       Assert.assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
-   }
-
-
-   /**
-    * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C3\A9"
-    */
-   public void testLdapDNPairCharAttributeValue() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9"
);
-       Assert.assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9", dn.toString() );
-       Assert.assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9", dn.getUpName()
);
-   }
-
-
-   /**
-    * test a simple DN with hexString attribute value : a = #0010A0AAFF
-    */
-   public void testLdapDNHexStringAttributeValue() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "a = #0010A0AAFF" );
-       Assert.assertEquals( "a=#0010A0AAFF", dn.toString() );
-       Assert.assertEquals( "a = #0010A0AAFF", dn.getUpName() );
-   }
-
-
-   /**
-    * test a simple DN with quoted attribute value : a = "quoted \"value"
-    */
-   public void testLdapDNQuotedAttributeValue() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "a = quoted \\\"value" );
-       Assert.assertEquals( "a=quoted \\\"value", dn.toString() );
-       Assert.assertEquals( "a = quoted \\\"value", dn.getUpName() );
-   }
-
-
-   /**
-    * Test the encoding of a LdanDN
-    */
-   public void testNameToBytes() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN dn = ( LdapDN ) dnParser.parse( "cn = John, ou = People, OU = Marketing" );
-
-       byte[] bytes = LdapDN.getBytes( dn );
-
-       Assert.assertEquals( 30, bytes.length );
-       Assert.assertEquals( "cn=John,ou=People,ou=Marketing", StringTools.utf8ToString( bytes
) );
-   }
-
-
-   public void testStringParser() throws NamingException
-   {
-       String dn = StringTools.utf8ToString( new byte[]{'C', 'N', ' ', '=', ' ', 'E', 'm',
'm', 'a', 'n', 'u', 'e', 
-           'l', ' ', ' ', 'L', (byte)0xc3, (byte)0xa9, 'c', 'h', 'a', 'r', 'n', 'y'} );
-
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN name = ( LdapDN ) dnParser.parse( dn );
-
-       Assert.assertEquals( dn, name.getUpName() );
-       Assert.assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
-   }
-
-
-   public void testVsldapExtras() throws NamingException
-   {
-       NameParser dnParser = LdapDnParser.getNameParser();
-       LdapDN name = ( LdapDN ) dnParser
-           .parse( "cn=Billy Bakers, OID.2.5.4.11=Corporate Tax, ou=Fin-Accounting, ou=Americas,
ou=Search, o=IMC, c=US" );
-
-       Assert.assertEquals(
-           "cn=Billy Bakers, OID.2.5.4.11=Corporate Tax, ou=Fin-Accounting, ou=Americas,
ou=Search, o=IMC, c=US", name
-               .getUpName() );
-       Assert.assertEquals(
-           "cn=Billy Bakers,oid.2.5.4.11=Corporate Tax,ou=Fin-Accounting,ou=Americas,ou=Search,o=IMC,c=US",
name
-               .toString() );
-   }
-
-
-   // ~ Methods
-   // ----------------------------------------------------------------
-
-   /**
-    * Class under test for void DnParser()
-    *
-    * @throws NamingException
-    *             if anything goes wrong
-    */
-   public final void testDnParser()
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-
-       assertNotNull( parser );
-   }
-
-
-   /**
-    * Class under test for Name parse(String)
-    *
-    * @throws NamingException
-    *             if anything goes wrong
-    */
-   public final void testParseStringEmpty() throws NamingException
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-
-       Name nameEmpty = parser.parse( "" );
-
-       assertNotNull( nameEmpty );
-   }
-
-
-   /**
-    * Class under test for Name parse(String)
-    *
-    * @throws NamingException
-    *             if anything goes wrong
-    */
-   public final void testParseStringNull() throws NamingException
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-
-       Name nameNull = parser.parse( null );
-
-       assertEquals( "Null DN are legal : ", "", nameNull.toString() );
-   }
-
-
-   /**
-    * Class under test for Name parse(String)
-    *
-    * @throws NamingException
-    *             if anything goes wrong
-    */
-   public final void testParseStringRFC1779_1() throws NamingException
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-
-       Name nameRFC1779_1 = parser
-           .parse( "CN=Marshall T. Rose, O=Dover Beach Consulting, L=Santa Clara, ST=California,
C=US" );
-
-       assertEquals( "RFC1779_1 : ",
-           "CN=Marshall T. Rose, O=Dover Beach Consulting, L=Santa Clara, ST=California,
C=US",
-           ( ( LdapDN ) nameRFC1779_1 ).getUpName() );
-       assertEquals( "RFC1779_1 : ", "cn=Marshall T. Rose,o=Dover Beach Consulting,l=Santa
Clara,st=California,c=US",
-           nameRFC1779_1.toString() );
-   }
-
-
-   /**
-    * Class under test for Name parse(String)
-    *
-    * @throws NamingException
-    *             if anything goes wrong
-    */
-   public final void testParseStringRFC2253_1() throws NamingException
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-
-       Name nameRFC2253_1 = parser.parse( "CN=Steve Kille,O=Isode limited,C=GB" );
-
-       assertEquals( "RFC2253_1 : ", "CN=Steve Kille,O=Isode limited,C=GB", ( ( LdapDN )
nameRFC2253_1 ).getUpName() );
-   }
-
-
-   /**
-    * Class under test for Name parse(String)
-    *
-    * @throws NamingException
-    *             if anything goes wrong
-    */
-   public final void testParseStringRFC2253_2() throws NamingException
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-
-       Name nameRFC2253_2 = parser.parse( "CN = Sales + CN =   J. Smith , O = Widget Inc.
, C = US" );
-
-       assertEquals( "RFC2253_2 : ", "CN = Sales + CN =   J. Smith , O = Widget Inc. , C
= US",
-           ( ( LdapDN ) nameRFC2253_2 ).getUpName() );
-       assertEquals( "RFC2253_2 : ", "cn=J. Smith+cn=Sales,o=Widget Inc.,c=US", nameRFC2253_2.toString()
);
-   }
-
-   /**
-    * Class under test for Name parse(String)
-    *
-    * @throws NamingException
-    *             if anything goes wrong
-    */
-   public final void testParseStringRFC2253_3() throws NamingException
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-
-       Name nameRFC2253_3 = parser.parse( "CN=L. Eagle,   O=Sue\\, Grabbit and Runn, C=GB"
);
-
-       assertEquals( "RFC2253_3 : ", "CN=L. Eagle,   O=Sue\\, Grabbit and Runn, C=GB", (
( LdapDN ) nameRFC2253_3 )
-           .getUpName() );
-       assertEquals( "RFC2253_3 : ", "cn=L. Eagle,o=Sue\\, Grabbit and Runn,c=GB", nameRFC2253_3.toString()
);
-   }
-
-
-   /**
-    * Class under test for Name parse(String)
-    *
-    * @throws NamingException
-    *             if anything goes wrong
-    */
-   public final void testParseStringRFC2253_4() throws NamingException
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-
-       Name nameRFC2253_4 = parser.parse( "CN=Before\\0DAfter,O=Test,C=GB" );
-       assertEquals( "RFC2253_4 : ", "CN=Before\\0DAfter,O=Test,C=GB", ( ( LdapDN ) nameRFC2253_4
).getUpName() );
-   }
-
-
-   /**
-    * Class under test for Name parse(String)
-    *
-    * @throws NamingException
-    *             if anything goes wrong
-    */
-   public final void testParseStringRFC2253_5() throws NamingException
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-
-       Name nameRFC2253_5 = parser.parse( "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB" );
-
-       assertEquals( "RFC2253_5 : ", "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB", ( ( LdapDN
) nameRFC2253_5 )
-           .getUpName() );
-   }
-
-
-   /**
-    * Class under test for Name parse(String)
-    *
-    * @throws NamingException
-    *             if anything goes wrong
-    */
-   public final void testParseStringRFC2253_6() throws NamingException
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-
-       Name nameRFC2253_6 = parser.parse( "SN=Lu\\C4\\8Di\\C4\\87" );
-
-       assertEquals( "RFC2253_6 : ", "SN=Lu\\C4\\8Di\\C4\\87", ( ( LdapDN ) nameRFC2253_6
).getUpName() );
-   }
-
-
-   /**
-    * Class under test for Name parse(String)
-    *
-    * @throws NamingException
-    *             if anything goes wrong
-    */
-   public final void testParseInvalidString()
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-
-       try
-       {
-           parser.parse( "&#347;=&#347;rasulu,dc=example,dc=com" );
-           fail( "the invalid name should never succeed in a parse" );
-       }
-       catch ( Exception e )
-       {
-           assertNotNull( e );
-       }
-   }
-
-
-   /**
-    * Tests to see if inner whitespace is preserved after an escaped ',' in a
-    * value of a name component. This test was added to try to reproduce the
-    * bug encountered in DIREVE-179 <a
-    * href="http://issues.apache.org/jira/browse/DIREVE-179"> here</a>.
-    *
-    * @throws NamingException
-    *             if anything goes wrong on parse()
-    */
-   public final void testPreserveSpaceAfterEscape() throws NamingException
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-       String input = "ou=some test\\,  something else";
-       String result = parser.parse( input ).toString();
-       assertEquals( "ou=some test\\,  something else", result );
-   }
-
-
-   public void testWindowsFilePath() throws Exception
-   {
-       // '\' should be escaped as stated in RFC 2253
-       String path = "windowsFilePath=C:\\\\cygwin";
-       NameParser parser = LdapDnParser.getNameParser();
-       Name result = parser.parse( path );
-       assertEquals( path, ( ( LdapDN ) result ).getUpName() );
-       assertEquals( "windowsfilepath=C:\\\\cygwin", result.toString() );
-   }
-
-
-   public void testNameFrenchChars() throws Exception
-   {
-       String cn = new String( new byte[]
-           { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte
) 0xB4, 0x6D, 0x65 }, "UTF-8" );
-
-       NameParser parser = LdapDnParser.getNameParser();
-       String result = parser.parse( cn ).toString();
-
-       assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", result.toString() );
-
-   }
-
-
-   public void testNameGermanChars() throws Exception
-   {
-       String cn = new String( new byte[]
-           { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, (
byte ) 0xC3, ( byte ) 0x9C,
-               ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3,
( byte ) 0xB6,
-               ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
-
-       NameParser parser = LdapDnParser.getNameParser();
-       String result = parser.parse( cn ).toString();
-
-       assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", result.toString()
);
-   }
-
-
-   public void testNameTurkishChars() throws Exception
-   {
-       String cn = new String( new byte[]
-           { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, (
byte ) 0xC5, ( byte ) 0x9E,
-               ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3,
( byte ) 0xB6,
-               ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4,
( byte ) 0x9E,
-               ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
-
-       NameParser parser = LdapDnParser.getNameParser();
-       String result = parser.parse( cn ).toString();
-
-       assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F",
result.toString() );
-
-   }
-
-   /**
-    * Test to check that even with a non escaped char, the DN is parsed ok
-    * or at least an error is generated.
-    *
-    * @throws NamingException
-    *             if anything goes wrong on parse()
-    */
-   public final void testNonEscapedChars()
-   {
-       NameParser parser = LdapDnParser.getNameParser();
-       String input = "ou=ou+test";
-
-       try
-       {
-           String res = parser.parse( input ).toString();
-           System.out.println( res);
-       }
-       catch ( NamingException ne )
-       {
-           assertTrue( true );
-           return;
-       }
-
-       fail( "Should never rech this point" );
-   }
+    /**
+     * test an empty DN
+     */
+    public void testLdapDNEmpty() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+
+        Assert.assertEquals( "", ( ( LdapDN ) dnParser.parse( "" ) ).getUpName() );
+    }
+
+
+    /**
+     * test a simple DN : a = b
+     */
+    public void testLdapDNSimple() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+
+        Assert.assertEquals( "a = b", ( ( LdapDN ) dnParser.parse( "a = b" ) ).getUpName()
);
+        Assert.assertEquals( "a=b", ( ( LdapDN ) dnParser.parse( "a = b" ) ).toString() );
+    }
+
+
+    /**
+     * test a composite DN : a = b, d = e
+     */
+    public void testLdapDNComposite() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "a = b, c = d" );
+        Assert.assertEquals( "a=b,c=d", dn.toString() );
+        Assert.assertEquals( "a = b, c = d", dn.getUpName() );
+    }
+
+
+    /**
+     * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
+     */
+    public void testLdapDNCompositeWithSpace() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "a=b, a =b, a= b, a = b, a  =  b" );
+        Assert.assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
+        Assert.assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
+    }
+
+
+    /**
+     * 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 NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "a=b;c=d,e=f" );
+        Assert.assertEquals( "a=b,c=d,e=f", dn.toString() );
+        Assert.assertEquals( "a=b;c=d,e=f", dn.getUpName() );
+    }
+
+
+    /**
+     * test a simple DN with multiple NameComponents : a = b + c = d
+     */
+    public void testLdapDNSimpleMultivaluedAttribute() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "a = b + c = d" );
+        Assert.assertEquals( "a=b+c=d", dn.toString() );
+        Assert.assertEquals( "a = b + c = d", dn.getUpName() );
+    }
+
+
+    /**
+     * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
+     * i=j
+     */
+    public void testLdapDNCompositeMultivaluedAttribute() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "a=b+c=d, e=f + g=h + i=j" );
+        Assert.assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
+        Assert.assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
+    }
+
+
+    /**
+     * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
+     */
+    public void testLdapDNOidUpper() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "OID.12.34.56 = azerty" );
+        Assert.assertEquals( "oid.12.34.56=azerty", dn.toString() );
+        Assert.assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
+    }
+
+
+    /**
+     * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
+     */
+    public void testLdapDNOidLower() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "oid.12.34.56 = azerty" );
+        Assert.assertEquals( "oid.12.34.56=azerty", dn.toString() );
+        Assert.assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
+    }
+
+
+    /**
+     * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
+     * azerty
+     */
+    public void testLdapDNOidWithoutPrefix() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "12.34.56 = azerty" );
+        Assert.assertEquals( "12.34.56=azerty", dn.toString() );
+        Assert.assertEquals( "12.34.56 = azerty", dn.getUpName() );
+    }
+
+
+    /**
+     * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
+     * azerty; 7.8 = test
+     */
+    public void testLdapDNCompositeOidWithoutPrefix() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "12.34.56 = azerty; 7.8 = test" );
+        Assert.assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
+        Assert.assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
+    }
+
+
+    /**
+     * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C3\A9"
+     */
+    public void testLdapDNPairCharAttributeValue() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9"
);
+        Assert.assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9", dn.toString() );
+        Assert.assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9", dn.getUpName()
);
+    }
+
+
+    /**
+     * test a simple DN with hexString attribute value : a = #0010A0AAFF
+     */
+    public void testLdapDNHexStringAttributeValue() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "a = #0010A0AAFF" );
+        Assert.assertEquals( "a=#0010A0AAFF", dn.toString() );
+        Assert.assertEquals( "a = #0010A0AAFF", dn.getUpName() );
+    }
+
+
+    /**
+     * test a simple DN with quoted attribute value : a = "quoted \"value"
+     */
+    public void testLdapDNQuotedAttributeValue() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "a = quoted \\\"value" );
+        Assert.assertEquals( "a=quoted \\\"value", dn.toString() );
+        Assert.assertEquals( "a = quoted \\\"value", dn.getUpName() );
+    }
+
+
+    /**
+     * Test the encoding of a LdanDN
+     */
+    public void testNameToBytes() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN dn = ( LdapDN ) dnParser.parse( "cn = John, ou = People, OU = Marketing" );
+
+        byte[] bytes = LdapDN.getBytes( dn );
+
+        Assert.assertEquals( 30, bytes.length );
+        Assert.assertEquals( "cn=John,ou=People,ou=Marketing", StringTools.utf8ToString(
bytes ) );
+    }
+
+
+    public void testStringParser() throws NamingException
+    {
+        String dn = StringTools.utf8ToString( new byte[]
+            { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ',
'L', ( byte ) 0xc3,
+                ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
+
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN name = ( LdapDN ) dnParser.parse( dn );
+
+        Assert.assertEquals( dn, name.getUpName() );
+        Assert.assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
+    }
+
+
+    public void testVsldapExtras() throws NamingException
+    {
+        NameParser dnParser = LdapDnParser.getNameParser();
+        LdapDN name = ( LdapDN ) dnParser
+            .parse( "cn=Billy Bakers, OID.2.5.4.11=Corporate Tax, ou=Fin-Accounting, ou=Americas,
ou=Search, o=IMC, c=US" );
+
+        Assert.assertEquals(
+            "cn=Billy Bakers, OID.2.5.4.11=Corporate Tax, ou=Fin-Accounting, ou=Americas,
ou=Search, o=IMC, c=US", name
+                .getUpName() );
+        Assert.assertEquals(
+            "cn=Billy Bakers,oid.2.5.4.11=Corporate Tax,ou=Fin-Accounting,ou=Americas,ou=Search,o=IMC,c=US",
name
+                .toString() );
+    }
+
+
+    // ~ Methods
+    // ----------------------------------------------------------------
+
+    /**
+     * Class under test for void DnParser()
+     *
+     * @throws NamingException
+     *             if anything goes wrong
+     */
+    public final void testDnParser()
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+
+        assertNotNull( parser );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException
+     *             if anything goes wrong
+     */
+    public final void testParseStringEmpty() throws NamingException
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+
+        Name nameEmpty = parser.parse( "" );
+
+        assertNotNull( nameEmpty );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException
+     *             if anything goes wrong
+     */
+    public final void testParseStringNull() throws NamingException
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+
+        Name nameNull = parser.parse( null );
+
+        assertEquals( "Null DN are legal : ", "", nameNull.toString() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException
+     *             if anything goes wrong
+     */
+    public final void testParseStringRFC1779_1() throws NamingException
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+
+        Name nameRFC1779_1 = parser
+            .parse( "CN=Marshall T. Rose, O=Dover Beach Consulting, L=Santa Clara, ST=California,
C=US" );
+
+        assertEquals( "RFC1779_1 : ",
+            "CN=Marshall T. Rose, O=Dover Beach Consulting, L=Santa Clara, ST=California,
C=US",
+            ( ( LdapDN ) nameRFC1779_1 ).getUpName() );
+        assertEquals( "RFC1779_1 : ", "cn=Marshall T. Rose,o=Dover Beach Consulting,l=Santa
Clara,st=California,c=US",
+            nameRFC1779_1.toString() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException
+     *             if anything goes wrong
+     */
+    public final void testParseStringRFC2253_1() throws NamingException
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+
+        Name nameRFC2253_1 = parser.parse( "CN=Steve Kille,O=Isode limited,C=GB" );
+
+        assertEquals( "RFC2253_1 : ", "CN=Steve Kille,O=Isode limited,C=GB", ( ( LdapDN )
nameRFC2253_1 ).getUpName() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException
+     *             if anything goes wrong
+     */
+    public final void testParseStringRFC2253_2() throws NamingException
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+
+        Name nameRFC2253_2 = parser.parse( "CN = Sales + CN =   J. Smith , O = Widget Inc.
, C = US" );
+
+        assertEquals( "RFC2253_2 : ", "CN = Sales + CN =   J. Smith , O = Widget Inc. , C
= US",
+            ( ( LdapDN ) nameRFC2253_2 ).getUpName() );
+        assertEquals( "RFC2253_2 : ", "cn=J. Smith+cn=Sales,o=Widget Inc.,c=US", nameRFC2253_2.toString()
);
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException
+     *             if anything goes wrong
+     */
+    public final void testParseStringRFC2253_3() throws NamingException
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+
+        Name nameRFC2253_3 = parser.parse( "CN=L. Eagle,   O=Sue\\, Grabbit and Runn, C=GB"
);
+
+        assertEquals( "RFC2253_3 : ", "CN=L. Eagle,   O=Sue\\, Grabbit and Runn, C=GB", (
( LdapDN ) nameRFC2253_3 )
+            .getUpName() );
+        assertEquals( "RFC2253_3 : ", "cn=L. Eagle,o=Sue\\, Grabbit and Runn,c=GB", nameRFC2253_3.toString()
);
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException
+     *             if anything goes wrong
+     */
+    public final void testParseStringRFC2253_4() throws NamingException
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+
+        Name nameRFC2253_4 = parser.parse( "CN=Before\\0DAfter,O=Test,C=GB" );
+        assertEquals( "RFC2253_4 : ", "CN=Before\\0DAfter,O=Test,C=GB", ( ( LdapDN ) nameRFC2253_4
).getUpName() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException
+     *             if anything goes wrong
+     */
+    public final void testParseStringRFC2253_5() throws NamingException
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+
+        Name nameRFC2253_5 = parser.parse( "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB" );
+
+        assertEquals( "RFC2253_5 : ", "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB", ( ( LdapDN
) nameRFC2253_5 )
+            .getUpName() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException
+     *             if anything goes wrong
+     */
+    public final void testParseStringRFC2253_6() throws NamingException
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+
+        Name nameRFC2253_6 = parser.parse( "SN=Lu\\C4\\8Di\\C4\\87" );
+
+        assertEquals( "RFC2253_6 : ", "SN=Lu\\C4\\8Di\\C4\\87", ( ( LdapDN ) nameRFC2253_6
).getUpName() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException
+     *             if anything goes wrong
+     */
+    public final void testParseInvalidString()
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+
+        try
+        {
+            parser.parse( "&#347;=&#347;rasulu,dc=example,dc=com" );
+            fail( "the invalid name should never succeed in a parse" );
+        }
+        catch ( Exception e )
+        {
+            assertNotNull( e );
+        }
+    }
+
+
+    /**
+     * Tests to see if inner whitespace is preserved after an escaped ',' in a
+     * value of a name component. This test was added to try to reproduce the
+     * bug encountered in DIREVE-179 <a
+     * href="http://issues.apache.org/jira/browse/DIREVE-179"> here</a>.
+     *
+     * @throws NamingException
+     *             if anything goes wrong on parse()
+     */
+    public final void testPreserveSpaceAfterEscape() throws NamingException
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+        String input = "ou=some test\\,  something else";
+        String result = parser.parse( input ).toString();
+        assertEquals( "ou=some test\\,  something else", result );
+    }
+
+
+    public void testWindowsFilePath() throws Exception
+    {
+        // '\' should be escaped as stated in RFC 2253
+        String path = "windowsFilePath=C:\\\\cygwin";
+        NameParser parser = LdapDnParser.getNameParser();
+        Name result = parser.parse( path );
+        assertEquals( path, ( ( LdapDN ) result ).getUpName() );
+        assertEquals( "windowsfilepath=C:\\\\cygwin", result.toString() );
+    }
+
+
+    public void testNameFrenchChars() throws Exception
+    {
+        String cn = new String( new byte[]
+            { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte
) 0xB4, 0x6D, 0x65 },
+            "UTF-8" );
+
+        NameParser parser = LdapDnParser.getNameParser();
+        String result = parser.parse( cn ).toString();
+
+        assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", result );
+
+    }
+
+
+    public void testNameGermanChars() throws Exception
+    {
+        String cn = new String( new byte[]
+            { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96,
( byte ) 0xC3, ( byte ) 0x9C,
+                ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3,
( byte ) 0xB6,
+                ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
+
+        NameParser parser = LdapDnParser.getNameParser();
+        String result = parser.parse( cn ).toString();
+
+        assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", result
);
+    }
+
+
+    public void testNameTurkishChars() throws Exception
+    {
+        String cn = new String( new byte[]
+            { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1,
( byte ) 0xC5, ( byte ) 0x9E,
+                ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3,
( byte ) 0xB6,
+                ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4,
( byte ) 0x9E,
+                ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
+
+        NameParser parser = LdapDnParser.getNameParser();
+        String result = parser.parse( cn ).toString();
+
+        assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F",
result );
+
+    }
+
+
+    /**
+     * Test to check that even with a non escaped char, the DN is parsed ok
+     * or at least an error is generated.
+     *
+     * @throws NamingException
+     *             if anything goes wrong on parse()
+     */
+    public final void testNonEscapedChars()
+    {
+        NameParser parser = LdapDnParser.getNameParser();
+        String input = "ou=ou+test";
+
+        try
+        {
+            String res = parser.parse( input ).toString();
+            System.out.println( res );
+        }
+        catch ( NamingException ne )
+        {
+            assertTrue( true );
+            return;
+        }
 
+        fail( "Should never rech this point" );
+    }
 }



Mime
View raw message