directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1084194 - in /directory/shared/trunk: integ/src/test/java/org/apache/directory/shared/ldap/model/name/ ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/ ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/
Date Tue, 22 Mar 2011 14:33:58 GMT
Author: elecharny
Date: Tue Mar 22 14:33:57 2011
New Revision: 1084194

URL: http://svn.apache.org/viewvc?rev=1084194&view=rev
Log:
Removed the DnParser and RnParser classes

Removed:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/DnParser.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/RdnParser.java
Modified:
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/SchemaAwareRdnTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/FastDnParserTest.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/SchemaAwareRdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/SchemaAwareRdnTest.java?rev=1084194&r1=1084193&r2=1084194&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/SchemaAwareRdnTest.java
(original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/SchemaAwareRdnTest.java
Tue Mar 22 14:33:57 2011
@@ -277,26 +277,6 @@ public class SchemaAwareRdnTest
 
     /**
      * Test the clone method for a Rdn.
-     */
-    @Test
-    public void testParseRDNNull()
-    {
-        Rdn rdn = null;
-
-        try
-        {
-            RdnParser.parse( "cn=d", rdn );
-            fail();
-        }
-        catch ( LdapException ine )
-        {
-            assertTrue( true );
-        }
-    }
-
-
-    /**
-     * Test the clone method for a Rdn.
      * 
      * @throws LdapException
      */
@@ -307,14 +287,14 @@ public class SchemaAwareRdnTest
 
         Rdn rdnClone = (Rdn) rdn.clone();
 
-        RdnParser.parse( "cn=d", rdn );
+        rdn = new Rdn( schemaManager, "cn=d" );
 
         assertEquals( "b", rdnClone.getValue( "Cn" ) );
     }
 
 
     /**
-     * Test teh creation of a new Rdn
+     * Test the creation of a new Rdn
      * 
      * @throws org.apache.directory.shared.ldap.model.exception.LdapException
      */
@@ -340,7 +320,7 @@ public class SchemaAwareRdnTest
         Rdn rdnClone = (Rdn) rdn.clone();
 
         rdn.clear();
-        RdnParser.parse( "l=d", rdn );
+         rdn = new Rdn( schemaManager, "l=d" );
 
         assertEquals( "b", rdnClone.getValue( "2.5.4.3" ) );
         assertEquals( "bb", rdnClone.getValue( "SN" ) );
@@ -1151,8 +1131,8 @@ public class SchemaAwareRdnTest
     @Test
     public void testRdnWithEmptyValue() throws LdapException
     {
-        assertTrue( RdnParser.isValid("cn=") );
-        assertTrue( RdnParser.isValid( "cn=\"\"" ) );
+        assertTrue( Rdn.isValid("cn=") );
+        assertTrue( Rdn.isValid( "cn=\"\"" ) );
         assertEquals( "2.5.4.3=", new Rdn( schemaManager,  "cn=\"\"" ).getNormName() );
         assertEquals( "2.5.4.3=", new Rdn( schemaManager,  "cn=" ).getNormName() );
     }
@@ -1164,14 +1144,14 @@ public class SchemaAwareRdnTest
     @Test
     public void testRdnWithEscapedComa() throws LdapException
     {
-        assertTrue( RdnParser.isValid( "cn=b\\,c" ) );
+        assertTrue( Rdn.isValid( "cn=b\\,c" ) );
         assertEquals( "2.5.4.3=b\\,c", new Rdn( schemaManager,  "cn=b\\,c" ).getNormName()
);
 
-        assertTrue( RdnParser.isValid( "cn=\"b,c\"" ) );
+        assertTrue( Rdn.isValid( "cn=\"b,c\"" ) );
         assertEquals( "2.5.4.3=b\\,c", new Rdn( schemaManager,  "cn=\"b,c\"" ).getNormName()
);
         assertEquals( "cn=\"b,c\"", new Rdn( schemaManager,  "cn=\"b,c\"" ).getName() );
 
-        assertTrue( RdnParser.isValid( "cn=\"b\\,c\"" ) );
+        assertTrue( Rdn.isValid( "cn=\"b\\,c\"" ) );
         Rdn rdn = new Rdn( schemaManager,  "cn=\"b\\,c\"" );
         assertEquals( "cn=\"b\\,c\"", rdn.getName() );
         assertEquals( "2.5.4.3=b\\,c", rdn.getNormName() );

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java?rev=1084194&r1=1084193&r2=1084194&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
Tue Mar 22 14:33:57 2011
@@ -279,7 +279,7 @@ public class Dn implements Iterable<Rdn>
         // Stores the representations of a Dn : internal (as a string and as a
         // byte[]) and external.
         upName = sb.toString();
-        DnParser.parseInternal( upName, rdns );
+        parseInternal( upName, rdns );
 
         if ( schemaManager != null )
         {
@@ -1631,19 +1631,6 @@ public class Dn implements Iterable<Rdn>
 
 
     /**
-     * Check if a DistinguishedName is syntactically valid.
-     *
-     * @param dn The Dn to validate
-     * @return <code>true></code> if the Dn is valid, <code>false</code>
-     * otherwise
-     */
-    public static boolean isValid( String dn )
-    {
-        return DnParser.validateInternal( dn );
-    }
-
-
-    /**
      * Tells if the Dn has already been normalized or not
      *
      * @return <code>true</code> if the Dn is already normalized.
@@ -1698,6 +1685,50 @@ public class Dn implements Iterable<Rdn>
     }
     
     
+    /**
+     * Check if a DistinguishedName is syntactically valid.
+     *
+     * @param dn The Dn to validate
+     * @return <code>true></code> if the Dn is valid, <code>false</code>
+     * otherwise
+     */
+    public static boolean isValid( String name )
+    {
+        Dn dn = new Dn();
+        
+        try
+        {
+            parseInternal( name, dn.rdns );
+            return true;
+        }
+        catch ( LdapInvalidDnException e )
+        {
+            return false;
+        }
+    }
+
+    
+    /**
+     * Parse a Dn.
+     *
+     * @param name The Dn to be parsed
+     * @param rdns The list that will contain the RDNs
+     * @throws LdapInvalidDnException If the Dn is invalid
+     */
+    private static void parseInternal( String name, List<Rdn> rdns ) throws LdapInvalidDnException
+    {
+        try
+        {
+            FastDnParser.parseDn( name, rdns );
+        }
+        catch ( TooComplexException e )
+        {
+            rdns.clear();
+            new ComplexDnParser().parseDn( name, rdns );
+        }
+    }
+
+
     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
     {
         // Read the UPName

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java?rev=1084194&r1=1084193&r2=1084194&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java
Tue Mar 22 14:33:57 2011
@@ -45,7 +45,7 @@ public enum FastDnParser
      * Gets the name parser singleton instance.
      * 
      * @return the name parser
-     */
+     *
     public static FastDnParser getNameParser()
     {
         return INSTANCE;
@@ -59,7 +59,7 @@ public enum FastDnParser
      * @return A valid Dn
      * @throws org.apache.directory.shared.ldap.model.exception.LdapException If the Dn was
invalid
      */
-    public Dn parse( String name ) throws LdapException
+    public static Dn parse( String name ) throws LdapException
     {
         Dn dn = new Dn();
         parseDn( name, dn );
@@ -75,14 +75,15 @@ public enum FastDnParser
      * 
      * @throws LdapInvalidDnException the invalid name exception
      */
-    public void parseDn( String name, Dn dn ) throws LdapInvalidDnException
+    public static void parseDn( String name, Dn dn ) throws LdapInvalidDnException
     {
         parseDn(name, dn.rdns);
         dn.setUpName( name );
         dn.normalizeInternal();
     }
     
-    void parseDn( String name, List<Rdn> rdns ) throws LdapInvalidDnException
+    
+    public static void parseDn( String name, List<Rdn> rdns ) throws LdapInvalidDnException
     {
         if ( ( name == null ) || ( name.trim().length() == 0 ) )
         {
@@ -128,7 +129,7 @@ public enum FastDnParser
      * 
      * @throws LdapInvalidDnException the invalid name exception
      */
-    public void parseRdn( String name, Rdn rdn ) throws LdapInvalidDnException
+    public static void parseRdn( String name, Rdn rdn ) throws LdapInvalidDnException
     {
         if ( name == null || name.length() == 0 )
         {
@@ -147,7 +148,7 @@ public enum FastDnParser
     }
 
 
-    private void parseRdnInternal( String name, Position pos, Rdn rdn ) throws LdapInvalidDnException
+    private static void parseRdnInternal( String name, Position pos, Rdn rdn ) throws LdapInvalidDnException
     {
         int rdnStart = pos.start;
 
@@ -193,7 +194,7 @@ public enum FastDnParser
      * @param pos the pos
      * @throws LdapInvalidDnException 
      */
-    private void matchSpaces( String name, Position pos ) throws LdapInvalidDnException
+    private static void matchSpaces( String name, Position pos ) throws LdapInvalidDnException
     {
         while ( hasMoreChars( pos ) )
         {
@@ -217,7 +218,7 @@ public enum FastDnParser
      * 
      * @throws LdapInvalidDnException the invalid name exception
      */
-    private String matchAttributeType( String name, Position pos ) throws LdapInvalidDnException
+    private static String matchAttributeType( String name, Position pos ) throws LdapInvalidDnException
     {
         char c = nextChar( name, pos, false );
         switch ( c )
@@ -307,7 +308,7 @@ public enum FastDnParser
      * 
      * @throws LdapInvalidDnException the invalid name exception
      */
-    private String matchAttributeTypeDescr( String name, Position pos ) throws LdapInvalidDnException
+    private static String matchAttributeTypeDescr( String name, Position pos ) throws LdapInvalidDnException
     {
         StringBuilder descr = new StringBuilder();
         while ( hasMoreChars( pos ) )
@@ -409,7 +410,7 @@ public enum FastDnParser
      * 
      * @throws org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException the
invalid name exception
      */
-    private String matchAttributeTypeNumericOid( String name, Position pos ) throws LdapInvalidDnException
+    private static String matchAttributeTypeNumericOid( String name, Position pos ) throws
LdapInvalidDnException
     {
         StringBuilder numericOid = new StringBuilder();
         int dotCount = 0;
@@ -505,7 +506,7 @@ public enum FastDnParser
      * 
      * @throws LdapInvalidDnException the invalid name exception
      */
-    private void matchEquals( String name, Position pos ) throws LdapInvalidDnException
+    private static void matchEquals( String name, Position pos ) throws LdapInvalidDnException
     {
         char c = nextChar( name, pos, true );
         if ( c != '=' )
@@ -527,7 +528,7 @@ public enum FastDnParser
      * 
      * @throws LdapInvalidDnException the invalid name exception
      */
-    private String matchValue( String name, Position pos ) throws LdapInvalidDnException
+    private static String matchValue( String name, Position pos ) throws LdapInvalidDnException
     {
         StringBuilder value = new StringBuilder();
         int numTrailingSpaces = 0;
@@ -573,7 +574,7 @@ public enum FastDnParser
      * @return the character
      * @throws LdapInvalidDnException If no more characters are available
      */
-    private char nextChar( String name, Position pos, boolean increment ) throws LdapInvalidDnException
+    private static char nextChar( String name, Position pos, boolean increment ) throws LdapInvalidDnException
     {
         if ( !hasMoreChars( pos ) )
         {
@@ -595,7 +596,7 @@ public enum FastDnParser
      * 
      * @return true, if more characters are available
      */
-    private boolean hasMoreChars( Position pos )
+    private static boolean hasMoreChars( Position pos )
     {
         return pos.start < pos.length;
     }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java?rev=1084194&r1=1084193&r2=1084194&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
Tue Mar 22 14:33:57 2011
@@ -233,7 +233,7 @@ public class Rdn implements Cloneable, E
         if ( Strings.isNotEmpty(rdn) )
         {
             // Parse the string. The Rdn will be updated.
-            RdnParser.parse( rdn, this );
+            parse( rdn, this );
 
             // create the internal normalized form
             // and store the user provided form
@@ -1341,6 +1341,57 @@ public class Rdn implements Cloneable, E
 
 
     /**
+     * Validate a NameComponent : <br>
+     * <p>
+     * &lt;name-component&gt; ::= &lt;attributeType&gt; &lt;spaces&gt;
'='
+     * &lt;spaces&gt; &lt;attributeValue&gt; &lt;nameComponents&gt;
+     * </p>
+     *
+     * @param dn The string to parse
+     * @return <code>true</code> if the Rdn is valid
+     */
+    public static boolean isValid( String dn )
+    {
+        Rdn rdn = new Rdn();
+        try
+        {
+            parse( dn, rdn );
+            return true;
+        }
+        catch ( LdapInvalidDnException e )
+        {
+            return false;
+        }
+    }
+
+    
+    /**
+     * Parse a NameComponent : <br>
+     * <p>
+     * &lt;name-component&gt; ::= &lt;attributeType&gt; &lt;spaces&gt;
'='
+     * &lt;spaces&gt; &lt;attributeValue&gt; &lt;nameComponents&gt;
+     * </p>
+     *
+     * @param dn The String to parse
+     * @param rdn The Rdn to fill. Beware that if the Rdn is not empty, the new
+     *            AttributeTypeAndValue will be added.
+     * @throws LdapInvalidDnException If the NameComponent is invalid
+     */
+    private static void parse( String dn, Rdn rdn ) throws LdapInvalidDnException
+    {
+        try
+        {
+            FastDnParser.INSTANCE.parseRdn( dn, rdn );
+        }
+        catch ( TooComplexException e )
+        {
+            rdn.clear();
+            new ComplexDnParser().parseRdn( dn, rdn );
+        }
+    }
+
+
+    /**
       * Gets the hashcode of this rdn.
       *
       * @see java.lang.Object#hashCode()

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/FastDnParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/FastDnParserTest.java?rev=1084194&r1=1084193&r2=1084194&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/FastDnParserTest.java
(original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/FastDnParserTest.java
Tue Mar 22 14:33:57 2011
@@ -20,20 +20,18 @@
 package org.apache.directory.shared.ldap.model.name;
 
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import org.apache.directory.shared.ldap.model.exception.LdapException;
-import org.apache.directory.shared.ldap.model.name.Dn;
-import org.apache.directory.shared.ldap.model.name.FastDnParser;
-import org.apache.directory.shared.ldap.model.name.TooComplexException;
 import org.apache.directory.shared.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertNotNull;
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
 /**
  * Tests the fast Dn parser.
@@ -54,8 +52,7 @@ public class FastDnParserTest
     @Test
     public void testLdapDNEmpty() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
-        assertEquals( "", ( (Dn) dnParser.parse( "" ) ).getName() );
+        assertEquals( "", ( (Dn) FastDnParser.parse( "" ) ).getName() );
     }
 
 
@@ -66,15 +63,13 @@ public class FastDnParserTest
     @Test
     public void testLdapDNIncomplete() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
-
         // empty Dn is ok
-        dnParser.parse( " " );
+        FastDnParser.parse( " " );
 
         // test DNs starting with an descr
         try
         {
-            dnParser.parse( " a" );
+            FastDnParser.parse( " a" );
             fail();
         }
         catch ( LdapException ine )
@@ -83,7 +78,7 @@ public class FastDnParserTest
         }
         try
         {
-            dnParser.parse( " a " );
+            FastDnParser.parse( " a " );
             fail();
         }
         catch ( LdapException ine )
@@ -92,21 +87,21 @@ public class FastDnParserTest
         }
         try
         {
-            dnParser.parse( " a- " );
+            FastDnParser.parse( " a- " );
             fail();
         }
         catch ( LdapException ine )
         {
             // expected
         }
-        dnParser.parse( " a =" );
-        dnParser.parse( " a = " );
-        dnParser.parse( " a = b" );
+        FastDnParser.parse( " a =" );
+        FastDnParser.parse( " a = " );
+        FastDnParser.parse( " a = b" );
 
         // test DNs starting with an OID
         try
         {
-            dnParser.parse( " 1 = b " );
+            FastDnParser.parse( " 1 = b " );
             fail( "OID must contain at least on dot." );
         }
         catch ( LdapException ine )
@@ -115,7 +110,7 @@ public class FastDnParserTest
         }
         try
         {
-            dnParser.parse( " 0" );
+            FastDnParser.parse( " 0" );
             fail();
         }
         catch ( LdapException ine )
@@ -124,7 +119,7 @@ public class FastDnParserTest
         }
         try
         {
-            dnParser.parse( " 0." );
+            FastDnParser.parse( " 0." );
             fail();
         }
         catch ( LdapException ine )
@@ -133,7 +128,7 @@ public class FastDnParserTest
         }
         try
         {
-            dnParser.parse( " 0.5" );
+            FastDnParser.parse( " 0.5" );
             fail();
         }
         catch ( LdapException ine )
@@ -142,7 +137,7 @@ public class FastDnParserTest
         }
         try
         {
-            dnParser.parse( " 0.5 " );
+            FastDnParser.parse( " 0.5 " );
             fail();
         }
         catch ( LdapException ine )
@@ -150,9 +145,9 @@ public class FastDnParserTest
             // expected
         }
         
-        dnParser.parse( " 0.5=" );
-        dnParser.parse( " 0.5 = " );
-        dnParser.parse( " 0.5 = b" );
+        FastDnParser.parse( " 0.5=" );
+        FastDnParser.parse( " 0.5 = " );
+        FastDnParser.parse( " 0.5 = b" );
     }
 
 
@@ -162,8 +157,7 @@ public class FastDnParserTest
     @Test
     public void testLdapDNSimple() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
-        Dn dn = (Dn) dnParser.parse( "a = b" );
+        Dn dn = FastDnParser.parse( "a = b" );
 
         assertEquals( "a = b", dn.getName() );
         assertEquals( "a=b", dn.getNormName() );
@@ -188,8 +182,7 @@ public class FastDnParserTest
     @Test
     public void testLdapDNComposite() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
-        Dn dn = (Dn) dnParser.parse( "a = b, c = d" );
+        Dn dn = FastDnParser.parse( "a = b, c = d" );
         assertEquals( "a=b,c=d", dn.getNormName() );
         assertEquals( "a = b, c = d", dn.getName() );
     }
@@ -201,8 +194,7 @@ public class FastDnParserTest
     @Test
     public void testLdapDNCompositeWithSpace() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
-        Dn dn = (Dn) dnParser.parse( "a=b, a =b, a= b, a = b, a  =  b" );
+        Dn dn = FastDnParser.parse( "a=b, a =b, a= b, a = b, a  =  b" );
         assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.getNormName() );
         assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getName() );
     }
@@ -215,8 +207,7 @@ public class FastDnParserTest
     @Test
     public void testLdapDNCompositeSepators() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
-        Dn dn = (Dn) dnParser.parse( "a=b;c=d,e=f" );
+        Dn dn = FastDnParser.parse( "a=b;c=d,e=f" );
         assertEquals( "a=b,c=d,e=f", dn.getNormName() );
         assertEquals( "a=b;c=d,e=f", dn.getName() );
     }
@@ -228,10 +219,9 @@ public class FastDnParserTest
     @Test
     public void testLdapDNSimpleMultivaluedAttribute() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
         try
         {
-            dnParser.parse( "a = b + c = d" );
+            FastDnParser.parse( "a = b + c = d" );
             fail( "Multivalued Rdn not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -248,10 +238,9 @@ public class FastDnParserTest
     @Test
     public void testLdapDNCompositeMultivaluedAttribute() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
         try
         {
-            dnParser.parse( "a=b+c=d, e=f + g=h + i=j" );
+            FastDnParser.parse( "a=b+c=d, e=f + g=h + i=j" );
             fail( "Multivalued Rdn not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -267,10 +256,9 @@ public class FastDnParserTest
     @Test
     public void testLdapDNOidUpper() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
         try
         {
-            dnParser.parse( "OID.12.34.56 = azerty" );
+            FastDnParser.parse( "OID.12.34.56 = azerty" );
             fail( "OID prefix not supported by fast parser" );
         }
         catch ( Exception e )
@@ -286,10 +274,9 @@ public class FastDnParserTest
     @Test
     public void testLdapDNOidLower() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
         try
         {
-            dnParser.parse( "oid.12.34.56 = azerty" );
+            FastDnParser.parse( "oid.12.34.56 = azerty" );
             fail( "OID prefix not supported by fast parser" );
         }
         catch ( Exception e )
@@ -306,8 +293,7 @@ public class FastDnParserTest
     @Test
     public void testLdapDNOidWithoutPrefix() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
-        Dn dn = (Dn) dnParser.parse( "12.34.56 = azerty" );
+        Dn dn = FastDnParser.parse( "12.34.56 = azerty" );
         assertEquals( "12.34.56=azerty", dn.getNormName() );
         assertEquals( "12.34.56 = azerty", dn.getName() );
     }
@@ -320,8 +306,7 @@ public class FastDnParserTest
     @Test
     public void testLdapDNCompositeOidWithoutPrefix() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
-        Dn dn = (Dn) dnParser.parse( "12.34.56 = azerty; 7.8 = test" );
+        Dn dn = FastDnParser.parse( "12.34.56 = azerty; 7.8 = test" );
         assertEquals( "12.34.56=azerty,7.8=test", dn.getNormName() );
         assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getName() );
     }
@@ -333,10 +318,9 @@ public class FastDnParserTest
     @Test
     public void testLdapDNPairCharAttributeValue() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
         try
         {
-            dnParser.parse( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9" );
+            FastDnParser.parse( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9" );
             fail( "Complex DNs not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -352,10 +336,9 @@ public class FastDnParserTest
     @Test
     public void testLdapDNHexStringAttributeValue() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
         try
         {
-            dnParser.parse( "a = #0010A0AAFF" );
+            FastDnParser.parse( "a = #0010A0AAFF" );
             fail( "Hex DNs not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -373,8 +356,7 @@ public class FastDnParserTest
     {
         try
         {
-            FastDnParser dnParser = FastDnParser.getNameParser();
-            dnParser.parse( "a=#zz" );
+            FastDnParser.parse( "a=#zz" );
             fail( "Hex DNs not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -390,10 +372,9 @@ public class FastDnParserTest
     @Test
     public void testLdapDNQuotedAttributeValue() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
         try
         {
-            dnParser.parse( "a = quoted \\\"value" );
+            FastDnParser.parse( "a = quoted \\\"value" );
             fail( "Quotes not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -409,8 +390,7 @@ public class FastDnParserTest
     @Test
     public void testNameToBytes() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
-        Dn dn = (Dn) dnParser.parse( "cn = John, ou = People, OU = Marketing" );
+        Dn dn = FastDnParser.parse( "cn = John, ou = People, OU = Marketing" );
 
         byte[] bytes = Dn.getBytes(dn);
 
@@ -426,8 +406,7 @@ public class FastDnParserTest
                 {'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', '
', 'L', (byte) 0xc3,
                         (byte) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y'});
 
-        FastDnParser dnParser = FastDnParser.getNameParser();
-        Dn name = (Dn) dnParser.parse( dn );
+        Dn name = FastDnParser.parse( dn );
 
         assertEquals( dn, name.getName() );
         assertEquals( "cn=Emmanuel  L\u00e9charny", name.getNormName() );
@@ -440,8 +419,7 @@ public class FastDnParserTest
         String dn = Strings.utf8ToString(new byte[]
                 {'C', '=', ' ', 'E', (byte) 0xc3, (byte) 0xa9, 'c'});
 
-        FastDnParser dnParser = FastDnParser.getNameParser();
-        Dn name = (Dn) dnParser.parse( dn );
+        Dn name = FastDnParser.parse( dn );
 
         assertEquals( dn, name.getName() );
         assertEquals( "c=E\u00e9c", name.getNormName() );
@@ -451,10 +429,9 @@ public class FastDnParserTest
     @Test
     public void testVsldapExtras() throws LdapException
     {
-        FastDnParser dnParser = FastDnParser.getNameParser();
         try
         {
-            dnParser
+            FastDnParser
                 .parse( "cn=Billy Bakers, OID.2.5.4.11=Corporate Tax, ou=Fin-Accounting,
ou=Americas, ou=Search, o=IMC, c=US" );
             fail( "OID prefix not supported by fast parser" );
         }
@@ -466,21 +443,6 @@ public class FastDnParserTest
 
 
     /**
-     * Class under test for void FastDnParser()
-     *
-     * @throws LdapException
-     *             if anything goes wrong
-     */
-    @Test
-    public final void testDnParser()
-    {
-        FastDnParser parser = FastDnParser.getNameParser();
-
-        assertNotNull( parser );
-    }
-
-
-    /**
      * Class under test for Name parse(String)
      *
      * @throws LdapException
@@ -489,9 +451,7 @@ public class FastDnParserTest
     @Test
     public final void testParseStringEmpty() throws LdapException
     {
-        FastDnParser parser = FastDnParser.getNameParser();
-
-        Dn nameEmpty = parser.parse( "" );
+        Dn nameEmpty = FastDnParser.parse( "" );
 
         assertNotNull( nameEmpty );
     }
@@ -506,9 +466,7 @@ public class FastDnParserTest
     @Test
     public final void testParseStringNull() throws LdapException
     {
-        FastDnParser parser = FastDnParser.getNameParser();
-
-        Dn nameNull = parser.parse( null );
+        Dn nameNull = FastDnParser.parse( null );
 
         assertEquals( "Null Dn are legal : ", "", nameNull.toString() );
     }
@@ -523,16 +481,14 @@ public class FastDnParserTest
     @Test
     public final void testParseStringRFC1779_1() throws LdapException
     {
-        FastDnParser parser = FastDnParser.getNameParser();
-
-        Dn nameRFC1779_1 = parser
+        Dn nameRFC1779_1 = FastDnParser
             .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",
-            ( (Dn) nameRFC1779_1 ).getName() );
+            nameRFC1779_1 .getName() );
         assertEquals( "RFC1779_1 : ", "cn=Marshall T. Rose,o=Dover Beach Consulting,l=Santa
Clara,st=California,c=US",
-            ((Dn)nameRFC1779_1).getNormName() );
+            nameRFC1779_1.getNormName() );
     }
 
 
@@ -545,9 +501,7 @@ public class FastDnParserTest
     @Test
     public final void testParseStringRFC2253_1() throws LdapException
     {
-        FastDnParser parser = FastDnParser.getNameParser();
-
-        Dn nameRFC2253_1 = parser.parse( "CN=Steve Kille,O=Isode limited,C=GB" );
+        Dn nameRFC2253_1 = FastDnParser.parse( "CN=Steve Kille,O=Isode limited,C=GB" );
 
         assertEquals( "RFC2253_1 : ", "CN=Steve Kille,O=Isode limited,C=GB", ( (Dn) nameRFC2253_1
).getName() );
     }
@@ -562,11 +516,9 @@ public class FastDnParserTest
     @Test
     public final void testParseStringRFC2253_2() throws LdapException
     {
-        FastDnParser parser = FastDnParser.getNameParser();
-
         try
         {
-            parser.parse( "CN = Sales + CN =   J. Smith , O = Widget Inc. , C = US" );
+            FastDnParser.parse( "CN = Sales + CN =   J. Smith , O = Widget Inc. , C = US"
);
             fail( "Multivalued Rdn not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -585,11 +537,9 @@ public class FastDnParserTest
     @Test
     public final void testParseStringRFC2253_3() throws LdapException
     {
-        FastDnParser parser = FastDnParser.getNameParser();
-
         try
         {
-            parser.parse( "CN=L. Eagle,   O=Sue\\, Grabbit and Runn, C=GB" );
+            FastDnParser.parse( "CN=L. Eagle,   O=Sue\\, Grabbit and Runn, C=GB" );
             fail( "Complex DNs not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -608,11 +558,9 @@ public class FastDnParserTest
     @Test
     public final void testParseStringRFC2253_4() throws LdapException
     {
-        FastDnParser parser = FastDnParser.getNameParser();
-
         try
         {
-            parser.parse( "CN=Before\\0DAfter,O=Test,C=GB" );
+            FastDnParser.parse( "CN=Before\\0DAfter,O=Test,C=GB" );
             fail( "Complex DNs not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -631,11 +579,9 @@ public class FastDnParserTest
     @Test
     public final void testParseStringRFC2253_5() throws LdapException
     {
-        FastDnParser parser = FastDnParser.getNameParser();
-
         try
         {
-            parser.parse( "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB" );
+            FastDnParser.parse( "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB" );
             fail( "Hex DNs not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -654,11 +600,9 @@ public class FastDnParserTest
     @Test
     public final void testParseStringRFC2253_6() throws LdapException
     {
-        FastDnParser parser = FastDnParser.getNameParser();
-
         try
         {
-            parser.parse( "SN=Lu\\C4\\8Di\\C4\\87" );
+            FastDnParser.parse( "SN=Lu\\C4\\8Di\\C4\\87" );
             fail( "Complex DNs not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -677,11 +621,9 @@ public class FastDnParserTest
     @Test
     public final void testParseInvalidString()
     {
-        FastDnParser parser = FastDnParser.getNameParser();
-
         try
         {
-            parser.parse( "&#347;=&#347;rasulu,dc=example,dc=com" );
+            FastDnParser.parse( "&#347;=&#347;rasulu,dc=example,dc=com" );
             fail( "the invalid name should never succeed in a parse" );
         }
         catch ( LdapException e )
@@ -703,11 +645,11 @@ public class FastDnParserTest
     @Test
     public final void testPreserveSpaceAfterEscape() throws LdapException
     {
-        FastDnParser parser = FastDnParser.getNameParser();
         String input = "ou=some test\\,  something else";
+        
         try
         {
-            parser.parse( input ).toString();
+            FastDnParser.parse( input ).toString();
             fail( "Complex DNs not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -722,10 +664,9 @@ public class FastDnParserTest
     {
         // '\' should be escaped as stated in RFC 2253
         String path = "windowsFilePath=C:\\\\cygwin";
-        FastDnParser parser = FastDnParser.getNameParser();
         try
         {
-            parser.parse( path );
+            FastDnParser.parse( path );
             fail( "Complex DNs not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -742,8 +683,7 @@ public class FastDnParserTest
             { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte
) 0xB4, 0x6D, 0x65 },
             "UTF-8" );
 
-        FastDnParser parser = FastDnParser.getNameParser();
-        String result = parser.parse( cn ).toString();
+        String result = FastDnParser.parse( cn ).toString();
 
         assertEquals( "cn=J\u00e9r\u00f4me", result );
 
@@ -758,8 +698,7 @@ public class FastDnParserTest
                 ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3,
( byte ) 0xB6,
                 ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
 
-        FastDnParser parser = FastDnParser.getNameParser();
-        String result = parser.parse( cn ).toString();
+        String result = FastDnParser.parse( cn ).toString();
 
         assertEquals( "cn=\u00C4\u00D6\u00DC\u00DF\u00E4\u00F6\u00FC", result );
     }
@@ -774,8 +713,7 @@ public class FastDnParserTest
                 ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4,
( byte ) 0x9E,
                 ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
 
-        FastDnParser parser = FastDnParser.getNameParser();
-        String result = parser.parse( cn ).toString();
+        String result = FastDnParser.parse( cn ).toString();
 
         assertEquals( "cn=\u0130\u0131\u015E\u015F\u00D6\u00F6\u00DC\u00FC\u011E\u011F",
result );
 
@@ -787,10 +725,9 @@ public class FastDnParserTest
     {
         String cn = new String( new byte[]
             { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, 0x5C, 0x32, 0x42 }, "UTF-8" );
-        FastDnParser parser = FastDnParser.getNameParser();
         try
         {
-            parser.parse( cn ).toString();
+            FastDnParser.parse( cn ).toString();
             fail( "DNs with special characters not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -806,10 +743,9 @@ public class FastDnParserTest
         String cn = new String( new byte[]
             { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, '\\', '+' }, "UTF-8" );
 
-        FastDnParser parser = FastDnParser.getNameParser();
         try
         {
-            parser.parse( cn ).toString();
+            FastDnParser.parse( cn ).toString();
             fail( "DNs with special characters not supported by fast parser" );
         }
         catch ( TooComplexException tce )
@@ -829,12 +765,11 @@ public class FastDnParserTest
     @Test
     public final void testNonEscapedChars() throws LdapException
     {
-        FastDnParser parser = FastDnParser.getNameParser();
         String input = "ou=ou+test";
 
         try
         {
-            parser.parse( input ).toString();
+            FastDnParser.parse( input ).toString();
             fail( "Should never reach this point" );
         }
         catch ( TooComplexException tce )

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java?rev=1084194&r1=1084193&r2=1084194&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
(original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
Tue Mar 22 14:33:57 2011
@@ -268,26 +268,6 @@ public class RdnTest
 
     /**
      * Test the clone method for a Rdn.
-     */
-    @Test
-    public void testParseRDNNull()
-    {
-        Rdn rdn = null;
-
-        try
-        {
-            RdnParser.parse( "c=d", rdn );
-            fail();
-        }
-        catch ( LdapException ine )
-        {
-            assertTrue( true );
-        }
-    }
-
-
-    /**
-     * Test the clone method for a Rdn.
      * 
      * @throws LdapException
      */
@@ -298,7 +278,7 @@ public class RdnTest
 
         Rdn rdnClone = (Rdn) rdn.clone();
 
-        RdnParser.parse( "c=d", rdn );
+        rdn = new Rdn( "c=d" );
 
         assertEquals( "b", rdnClone.getValue( "a" ) );
     }
@@ -331,7 +311,7 @@ public class RdnTest
         Rdn rdnClone = (Rdn) rdn.clone();
 
         rdn.clear();
-        RdnParser.parse( "c=d", rdn );
+        rdn = new Rdn( "c=d" );
 
         assertEquals( "b", rdnClone.getValue( "a" ) );
         assertEquals( "bb", rdnClone.getValue( "aa" ) );
@@ -1134,8 +1114,8 @@ public class RdnTest
     @Test
     public void testRdnWithEmptyValue() throws LdapException
     {
-        assertTrue( RdnParser.isValid("a=") );
-        assertTrue( RdnParser.isValid( "a=\"\"" ) );
+        assertTrue( Rdn.isValid( "a=" ) );
+        assertTrue( Rdn.isValid( "a=\"\"" ) );
         assertEquals( "a=", new Rdn( "a=\"\"" ).getNormName() );
         assertEquals( "a=", new Rdn( "a=" ).getNormName() );
     }
@@ -1147,14 +1127,14 @@ public class RdnTest
     @Test
     public void testRdnWithEscapedComa() throws LdapException
     {
-        assertTrue( RdnParser.isValid( "a=b\\,c" ) );
+        assertTrue( Rdn.isValid( "a=b\\,c" ) );
         assertEquals( "a=b\\,c", new Rdn( "a=b\\,c" ).getNormName() );
 
-        assertTrue( RdnParser.isValid( "a=\"b,c\"" ) );
+        assertTrue( Rdn.isValid( "a=\"b,c\"" ) );
         assertEquals( "a=b\\,c", new Rdn( "a=\"b,c\"" ).getNormName() );
         assertEquals( "a=\"b,c\"", new Rdn( "a=\"b,c\"" ).getName() );
 
-        assertTrue( RdnParser.isValid( "a=\"b\\,c\"" ) );
+        assertTrue( Rdn.isValid( "a=\"b\\,c\"" ) );
         Rdn rdn = new Rdn( "a=\"b\\,c\"" );
         assertEquals( "a=\"b\\,c\"", rdn.getName() );
         assertEquals( "a=b\\,c", rdn.getNormName() );



Mime
View raw message