You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2012/02/21 02:58:57 UTC
svn commit: r1291551 - in /directory/shared/trunk:
dsml/parser/src/test/java/org/apache/directory/shared/dsmlv2/modDNRequest/
integ/src/test/java/org/apache/directory/shared/ldap/model/name/
ldap/model/src/main/java/org/apache/directory/shared/ldap/mod...
Author: elecharny
Date: Tue Feb 21 01:58:56 2012
New Revision: 1291551
URL: http://svn.apache.org/viewvc?rev=1291551&view=rev
Log:
o Fixed the Ava class to correctly handle special characters
o added some ests
Added:
directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
Modified:
directory/shared/trunk/dsml/parser/src/test/java/org/apache/directory/shared/dsmlv2/modDNRequest/ModifyDNRequestTest.java
directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java
directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java
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/Ava.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/AvaTest.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnParserTest.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/dsml/parser/src/test/java/org/apache/directory/shared/dsmlv2/modDNRequest/ModifyDNRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml/parser/src/test/java/org/apache/directory/shared/dsmlv2/modDNRequest/ModifyDNRequestTest.java?rev=1291551&r1=1291550&r2=1291551&view=diff
==============================================================================
--- directory/shared/trunk/dsml/parser/src/test/java/org/apache/directory/shared/dsmlv2/modDNRequest/ModifyDNRequestTest.java (original)
+++ directory/shared/trunk/dsml/parser/src/test/java/org/apache/directory/shared/dsmlv2/modDNRequest/ModifyDNRequestTest.java Tue Feb 21 01:58:56 2012
@@ -6,16 +6,16 @@
* to you 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.shared.dsmlv2.modDNRequest;
@@ -119,7 +119,7 @@ public class ModifyDNRequestTest extends
assertNotNull( control );
assertTrue( control.isCritical() );
assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
- assertEquals( "Some text", Strings.utf8ToString( ( byte[] ) ( ( DsmlControl<?> ) control ).getValue() ) );
+ assertEquals( "Some text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
@@ -154,7 +154,7 @@ public class ModifyDNRequestTest extends
assertNotNull( control );
assertTrue( control.isCritical() );
assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
- assertEquals( "DSMLv2.0 rocks!!", Strings.utf8ToString( ( byte[] ) ( ( DsmlControl<?> ) control ).getValue() ) );
+ assertEquals( "DSMLv2.0 rocks!!", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
@@ -224,7 +224,7 @@ public class ModifyDNRequestTest extends
assertNotNull( control );
assertFalse( control.isCritical() );
assertEquals( "1.2.840.113556.1.4.789", control.getOid() );
- assertEquals( "Some other text", Strings.utf8ToString( ( byte[] ) ( ( DsmlControl<?> ) control ).getValue() ) );
+ assertEquals( "Some other text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
@@ -308,7 +308,7 @@ public class ModifyDNRequestTest extends
assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", modifyDNRequest.getName().getNormName() );
- assertEquals( "cn=Steve Jobs", modifyDNRequest.getNewRdn().getNormName() );
+ assertEquals( "CN=Steve Jobs", modifyDNRequest.getNewRdn().getName() );
}
Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java?rev=1291551&r1=1291550&r2=1291551&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java (original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java Tue Feb 21 01:58:56 2012
@@ -6,16 +6,16 @@
* to you 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.shared.ldap.model.name;
@@ -44,7 +44,6 @@ import com.mycila.junit.concurrent.Concu
@Concurrency()
public class AvaTest
{
-
private static SchemaManager schemaManager;
@@ -111,24 +110,24 @@ public class AvaTest
public void testAttributeTypeAndValueValidType() throws LdapException
{
Ava ava = new Ava( schemaManager, "CN", " " );
- assertEquals( "CN= ", ava.toString() );
+ assertEquals( "CN=\\ ", ava.toString() );
assertEquals( "2.5.4.3=\\ ", ava.getNormName() );
- assertEquals( "CN= ", ava.getUpName() );
+ assertEquals( "CN=\\ ", ava.getUpName() );
ava = new Ava( schemaManager, " CN ", " " );
- assertEquals( " CN = ", ava.toString() );
+ assertEquals( " CN =\\ ", ava.toString() );
assertEquals( "2.5.4.3=\\ ", ava.getNormName() );
- assertEquals( " CN = ", ava.getUpName() );
+ assertEquals( " CN =\\ ", ava.getUpName() );
ava = new Ava( schemaManager, "cn", " " );
- assertEquals( "cn= ", ava.toString() );
+ assertEquals( "cn=\\ ", ava.toString() );
assertEquals( "2.5.4.3=\\ ", ava.getNormName() );
- assertEquals( "cn= ", ava.getUpName() );
+ assertEquals( "cn=\\ ", ava.getUpName() );
ava = new Ava( schemaManager, " cn ", " " );
- assertEquals( " cn = ", ava.toString() );
+ assertEquals( " cn =\\ ", ava.toString() );
assertEquals( "2.5.4.3=\\ ", ava.getNormName() );
- assertEquals( " cn = ", ava.getUpName() );
+ assertEquals( " cn =\\ ", ava.getUpName() );
}
@@ -170,9 +169,9 @@ public class AvaTest
public void testAvaSimpleNorm() throws LdapException
{
Ava atav = new Ava( schemaManager, " CommonName ", " This is a TEST " );
- assertEquals( " CommonName = This is a TEST ", atav.toString() );
+ assertEquals( " CommonName =\\ This is a TEST\\ ", atav.toString() );
assertEquals( "2.5.4.3=this is a test", atav.getNormName() );
- assertEquals( " CommonName = This is a TEST ", atav.getUpName() );
+ assertEquals( " CommonName =\\ This is a TEST\\ ", atav.getUpName() );
}
@@ -200,4 +199,114 @@ public class AvaTest
assertTrue( atav1.equals( atav2 ) );
}
+
+
+ /**
+ * Test the returned values for Ava. \u00E4 is the unicode char for "ä", encoded
+ * \C3\A4 in UTF8
+ */
+ @Test
+ public void testAvaValuesNoSchema() throws LdapException
+ {
+ String errors = null;
+
+ Ava ava = new Ava( "OU", "Exemple + Rdn\u00E4 " );
+
+ if ( !"ou=Exemple \\+ Rdn\\C3\\A4\\ ".equals( ava.getNormName() ) )
+ {
+ errors = "\nAva.getNormName fails '" + ava.getNormName() + "'";
+ }
+
+ if ( !"ou".equals( ava.getNormType() ) )
+ {
+ errors += "\nAva.getNormType fails '" + ava.getNormType() + "'";
+ }
+
+ if ( !"Exemple + Rdn\u00E4 ".equals( ava.getNormValue().getString() ) )
+ {
+ errors += "\nAva.getNormValue fails '" + ava.getNormValue().getString() + "'";
+ }
+
+ if ( !"OU=Exemple \\+ Rdn\\C3\\A4\\ ".equals( ava.getUpName() ) )
+ {
+ errors += "\nAva.getUpName fails '" + ava.getUpName() + "'";
+ }
+
+ if ( !"OU".equals( ava.getUpType() ) )
+ {
+ errors += "\nAva.getUpType fails '" + ava.getUpType() + "'";
+ }
+
+ if ( !"Exemple + Rdn\u00E4 ".equals( ava.getUpValue().getString() ) )
+ {
+ errors += "\nAva.getUpValue fails '" + ava.getUpValue() .getString() + "'";
+ }
+
+ if ( !"ou=Exemple \\+ Rdn\\C3\\A4\\ ".equals( ava.normalize() ) )
+ {
+ errors += "\nAva.normalize fails '" + ava.normalize() + "'";
+ }
+
+ if ( !"OU=Exemple \\+ Rdn\\C3\\A4\\ ".equals( ava.toString() ) )
+ {
+ errors += "\nAva.toString fails '" + ava.toString() + "'";
+ }
+
+ assertEquals( null, errors );
+ }
+
+
+ /**
+ * Test the returned values for a schema aware Ava.
+ * \u00E4 is the unicode char for "ä", encoded \C3\A4 in UTF8
+ */
+ @Test
+ public void testAvaValuesSchemaAware() throws LdapException
+ {
+ String errors = null;
+
+ Ava ava = new Ava( schemaManager, "OU", "Exemple + Rdn\u00E4 " );
+
+ if ( !"2.5.4.11=exemple \\+ rdn\\C3\\A4".equals( ava.getNormName() ) )
+ {
+ errors = "\nAva.getNormName fails '" + ava.getNormName() + "'";
+ }
+
+ if ( !"2.5.4.11".equals( ava.getNormType() ) )
+ {
+ errors += "\nAva.getNormType fails '" + ava.getNormType() + "'";
+ }
+
+ if ( !"exemple + rdn\u00E4".equals( ava.getNormValue().getString() ) )
+ {
+ errors += "\nAva.getNormValue fails '" + ava.getNormValue().getString() + "'";
+ }
+
+ if ( !"OU=Exemple \\+ Rdn\\C3\\A4\\ ".equals( ava.getUpName() ) )
+ {
+ errors += "\nAva.getUpName fails '" + ava.getUpName() + "'";
+ }
+
+ if ( !"OU".equals( ava.getUpType() ) )
+ {
+ errors += "\nAva.getUpType fails '" + ava.getUpType() + "'";
+ }
+
+ if ( !"Exemple + Rdn\u00E4 ".equals( ava.getUpValue().getString() ) )
+ {
+ errors += "\nAva.getUpValue fails '" + ava.getUpValue().getString() + "'";
+ }
+
+ if ( !"2.5.4.11=exemple \\+ rdn\\C3\\A4".equals( ava.normalize() ) )
+ {
+ errors += "\nAva.normalize fails '" + ava.normalize() + "'";
+ }
+
+ if ( !"OU=Exemple \\+ Rdn\\C3\\A4\\ ".equals( ava.toString() ) )
+ {
+ errors += "\nAva.toString fails '" + ava.toString() + "'";
+ }
+
+ assertEquals( null, errors );
+ }
}
Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java?rev=1291551&r1=1291550&r2=1291551&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java (original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java Tue Feb 21 01:58:56 2012
@@ -294,7 +294,7 @@ public class DnTest
Dn dn = new Dn( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
assertTrue( Dn.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
- assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\u010D", dn.getNormName() );
+ assertEquals( "a=\\,\\=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.getNormName() );
assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getName() );
}
@@ -308,7 +308,7 @@ public class DnTest
Dn dn = new Dn( "SN=Lu\\C4\\8Di\\C4\\87" );
assertTrue( Dn.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
- assertEquals( "sn=Lu\u010Di\u0107", dn.getNormName() );
+ assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.getNormName() );
assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getName() );
}
@@ -1235,7 +1235,7 @@ public class DnTest
Dn name = new Dn( dn );
assertEquals( dn, ( name ).getName() );
- assertEquals( "cn=Emmanuel L\u00E9charny", ( name ).getNormName() );
+ assertEquals( "cn=Emmanuel L\\C3\\A9charny", ( name ).getNormName() );
}
Added: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java?rev=1291551&view=auto
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java (added)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java Tue Feb 21 01:58:56 2012
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.model.name;
+
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+/**
+ * Tests for the schemaAware Rdn class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class RdnTest
+{
+ private static SchemaManager schemaManager;
+
+
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ schemaManager = new DefaultSchemaManager();
+ }
+
+ @Test
+ public void testRdnValuesNoSchema() throws LdapException
+ {
+ /*
+ String errors = null;
+
+ Rdn rdn = new Rdn( "OU = Exemple \\+ Rdn\\C3\\A4\\ +cn= TEST" );
+
+ if ( !"OU = Exemple \\+ Rdn\\C3\\A4\\ +cn= TEST".equals( rdn.getName() ) )
+ {
+ errors += "\nRdn.getName fails '" + rdn.getName() + "'";
+ }
+
+ if ( !"ou=Exemple \\+ Rdn\\C3\\A4\\ +cn=TEST" .equals( rdn.getNormName() ) )
+ {
+ errors = "\nRdn.getNormName fails '" + rdn.getNormName() + "'";
+ }
+
+ if ( !"ou".equals( rdn.getNormType() ) )
+ {
+ errors += "\nRdn.getNormType fails '" + rdn.getNormType() + "'";
+ }
+
+ if ( !"Exemple + Rdn\u00E4 ".equals( rdn.getNormValue().getString() ) )
+ {
+ errors += "\nRdn.getNormValue fails '" + rdn.getNormValue().getString() + "'";
+ }
+
+ if ( !"OU".equals( rdn.getUpType() ) )
+ {
+ errors += "\nRdn.getUpType fails '" + rdn.getUpType() + "'";
+ }
+
+ if ( !"Exemple + Rdn\u00E4 ".equals( rdn.getUpValue().getString() ) )
+ {
+ errors += "\nRdn.getUpValue fails '" + rdn.getUpValue() + "'";
+ }
+
+ if ( !"Exemple + Rdn\u00E4 ".equals( rdn.getValue( "ou" ) ) )
+ {
+ errors += "\nRdn.getValue( 'ou' ) fails '" + rdn.getValue( "ou" ) + "'";
+ }
+
+ if ( !"TEST".equals( rdn.getValue( "cn" ) ) )
+ {
+ errors += "\nRdn.getValue( 'test' ) fails '" + rdn.getValue( "cn" ) + "'";
+ }
+
+ if ( !"OU = Exemple \\+ Rdn\\C3\\A4\\ +cn= TEST".equals( rdn.toString() ) )
+ {
+ errors += "\nRdn.toString fails '" + rdn.toString() + "'";
+ }
+
+ assertEquals( null, errors );
+ }
+
+
+ @Test
+ public void testRdnValuesSchemaAware() throws LdapException
+ {
+ String errors = null;
+
+ Rdn rdn = new Rdn( schemaManager, "OU = Exemple \\+ Rdn\\C3\\A4\\ +cn= TEST" );
+
+ if ( !"OU = Exemple \\+ Rdn\\C3\\A4\\ +cn= TEST".equals( rdn.getName() ) )
+ {
+ errors += "\nRdn.getName fails '" + rdn.getName() + "'";
+ }
+
+ if ( !"2.5.4.11=exemple \\+ rdn\\C3\\A4\\ +2.5.4.3=test" .equals( rdn.getNormName() ) )
+ {
+ errors = "\nRdn.getNormName fails '" + rdn.getNormName() + "'";
+ }
+
+ if ( !"2.5.4.11".equals( rdn.getNormType() ) )
+ {
+ errors += "\nRdn.getNormType fails '" + rdn.getNormType() + "'";
+ }
+
+ if ( !"exemple + rdn\u00E4 ".equals( rdn.getNormValue().getString() ) )
+ {
+ errors += "\nRdn.getNormValue fails '" + rdn.getNormValue().getString() + "'";
+ }
+
+ if ( !"OU".equals( rdn.getUpType() ) )
+ {
+ errors += "\nRdn.getUpType fails '" + rdn.getUpType() + "'";
+ }
+
+ if ( !"Exemple + Rdn\u00E4 ".equals( rdn.getUpValue().getString() ) )
+ {
+ errors += "\nRdn.getUpValue fails '" + rdn.getUpValue().getString() + "'";
+ }
+
+ if ( !"Exemple + Rdn\u00E4 ".equals( rdn.getValue( "ou" ).toString() ) )
+ {
+ errors += "\nRdn.getValue( 'ou' ) fails '" + rdn.getValue( "ou" ) + "'";
+ }
+
+ if ( !"TEST".equals( rdn.getValue( "cn" ).toString() ) )
+ {
+ errors += "\nRdn.getValue( 'test' ) fails '" + rdn.getValue( "cn" ) + "'";
+ }
+
+ if ( !"OU = Exemple \\+ Rdn\\C3\\A4\\ +cn= TEST".equals( rdn.toString() ) )
+ {
+ errors += "\nRdn.toString fails '" + rdn.toString() + "'";
+ }
+
+ assertEquals( null, errors );
+ */
+ }
+}
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=1291551&r1=1291550&r2=1291551&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 Feb 21 01:58:56 2012
@@ -6,16 +6,16 @@
* to you 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.shared.ldap.model.name;
@@ -234,7 +234,7 @@ public class SchemaAwareRdnTest
String rdn = Strings.utf8ToString( new byte[]
{ 'l', '=', '\\', ',', '=', '\\', '+', '\\', '<', '\\', '>', '#', '\\', ';', '\\', '\\', '\\', '"', '\\',
'C', '3', '\\', 'A', '9' } );
- assertEquals( "2.5.4.7=\\,=\\+\\<\\>#\\;\\\\\\\"\u00E9", new Rdn( schemaManager, rdn ).getNormName() );
+ assertEquals( "2.5.4.7=\\,\\=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9", new Rdn( schemaManager, rdn ).getNormName() );
}
@@ -288,7 +288,7 @@ public class SchemaAwareRdnTest
{
Rdn rdn = new Rdn( schemaManager, "CN", "B" );
- Rdn rdnClone = ( Rdn ) rdn.clone();
+ Rdn rdnClone = rdn.clone();
rdn = new Rdn( schemaManager, "cn=d" );
@@ -320,7 +320,7 @@ public class SchemaAwareRdnTest
{
Rdn rdn = new Rdn( schemaManager, "cn = b + sn = bb" );
- Rdn rdnClone = ( Rdn ) rdn.clone();
+ Rdn rdnClone = rdn.clone();
rdn.clear();
rdn = new Rdn( schemaManager, "l=d" );
@@ -1170,10 +1170,10 @@ public class SchemaAwareRdnTest
@Test
public void testComparingOfClonedMultiValuedRDNs() throws LdapException
{
- // Use upper case attribute types to test if normalized types are used
+ // Use upper case attribute types to test if normalized types are used
// for comparison
Rdn rdn = new Rdn( schemaManager, " CN = b + SN = d" );
- Rdn clonedRdn = ( Rdn ) rdn.clone();
+ Rdn clonedRdn = rdn.clone();
assertTrue( rdn.equals( clonedRdn ) );
}
@@ -1188,7 +1188,7 @@ public class SchemaAwareRdnTest
@Test
public void testComparingOfCopyConstructedMultiValuedRDNs() throws LdapException
{
- // Use upper case attribute types to test if normalized types are used
+ // Use upper case attribute types to test if normalized types are used
// for comparison
Rdn rdn = new Rdn( schemaManager, " CN = b + SN = d" );
Rdn copiedRdn = new Rdn( rdn );
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java?rev=1291551&r1=1291550&r2=1291551&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java Tue Feb 21 01:58:56 2012
@@ -6,16 +6,16 @@
* to you 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.shared.ldap.model.name;
@@ -47,7 +47,7 @@ import org.slf4j.LoggerFactory;
* and trailing spaces MUST have been trimmed before. The value MUST be in UTF8
* format, according to RFC 2253. If the type is in OID form, then the value
* must be a hexadecimal string prefixed by a '#' character. Otherwise, the
- * string must respect the RC 2253 grammar.
+ * string must respect the RC 2253 grammar.
*
* We will also keep a User Provided form of the AVA (Attribute Type And Value),
* called upName.
@@ -120,10 +120,10 @@ public class Ava implements Externalizab
/**
- * Construct an Ava containing a binary value.
+ * Construct an Ava containing a binary value.
* <p>
* Note that the upValue should <b>not</b> be null or empty, or resolve
- * to an empty string after having trimmed it.
+ * to an empty string after having trimmed it.
*
* @param upType The User Provided type
* @param upValue The User Provided binary value
@@ -141,7 +141,7 @@ public class Ava implements Externalizab
* and value will be normalized accordingly to the given SchemaManager.
* <p>
* Note that the upValue should <b>not</b> be null or empty, or resolve
- * to an empty string after having trimmed it.
+ * to an empty string after having trimmed it.
*
* @param schemaManager The SchemaManager instance
* @param upType The User Provided type
@@ -183,10 +183,10 @@ public class Ava implements Externalizab
/**
- * Construct an Ava with a String value.
+ * Construct an Ava with a String value.
* <p>
* Note that the upValue should <b>not</b> be null or empty, or resolve
- * to an empty string after having trimmed it.
+ * to an empty string after having trimmed it.
*
* @param upType The User Provided type
* @param upValue The User Provided String value
@@ -203,7 +203,7 @@ public class Ava implements Externalizab
* Construct a schema aware Ava with a String value.
* <p>
* Note that the upValue should <b>not</b> be null or empty, or resolve
- * to an empty string after having trimmed it.
+ * to an empty string after having trimmed it.
*
* @param schemaManager The SchemaManager instance
* @param upType The User Provided type
@@ -249,7 +249,7 @@ public class Ava implements Externalizab
* to the SchemaManager.
* <p>
* Note that the upValue should <b>not</b> be null or empty, or resolve
- * to an empty string after having trimmed it.
+ * to an empty string after having trimmed it.
*
* @param schemaManager The SchemaManager instance
* @param upType The User Provided type
@@ -285,7 +285,7 @@ public class Ava implements Externalizab
this.upValue = upValue;
- upName = this.upType + '=' + ( this.upValue == null ? "" : this.upValue.getString() );
+ upName = this.upType + '=' + ( this.upValue == null ? "" : Rdn.escapeValue( this.upValue.getString() ) );
hashCode();
}
@@ -296,7 +296,7 @@ public class Ava implements Externalizab
* <li> the value is trimmed </li>
* <p>
* Note that the upValue should <b>not</b> be null or empty, or resolved
- * to an empty string after having trimmed it.
+ * to an empty string after having trimmed it.
*
* @param upType The User Provided type
* @param upValue The User Provided value
@@ -339,7 +339,7 @@ public class Ava implements Externalizab
this.normValue = upValue;
this.upValue = upValue;
- upName = this.upType + '=' + ( this.upValue == null ? "" : this.upValue.getString() );
+ upName = this.upType + '=' + ( this.upValue == null ? "" : Rdn.escapeValue( this.upValue.getString() ) );
hashCode();
}
@@ -350,7 +350,7 @@ public class Ava implements Externalizab
* <li> the value is trimmed </li>
* <p>
* Note that the upValue should <b>not</b> be null or empty, or resolved
- * to an empty string after having trimmed it.
+ * to an empty string after having trimmed it.
*
* @param schemaManager The SchemaManager
* @param upType The User Provided type
@@ -388,7 +388,7 @@ public class Ava implements Externalizab
* <li> the value is trimmed </li>
* <p>
* Note that the upValue should <b>not</b> be null or empty, or resolved
- * to an empty string after having trimmed it.
+ * to an empty string after having trimmed it.
*
* @param upType The User Provided type
* @param normType The normalized type
@@ -650,7 +650,7 @@ public class Ava implements Externalizab
false,
false,
false,
- false, // 0x30 -> 0x37
+ false, // 0x30 -> 0x37
false,
false,
false,
@@ -728,7 +728,7 @@ public class Ava implements Externalizab
/**
* Normalize the value in order to be able to use it in a DN as a String. Some
- * characters will be escaped (prefixed with '\'),
+ * characters will be escaped (prefixed with '\'),
*
* @return The normalized Ava
*/
@@ -801,7 +801,7 @@ public class Ava implements Externalizab
/**
* A Normalized String representation of a Ava :
* <ul>
- * <li>type is trimed and lowercased</li>
+ * <li>type is trimed and lowercased</li>
* <li>value is trimed and lowercased, and special characters</li>
* </ul>
* are escaped if needed.
@@ -822,7 +822,7 @@ public class Ava implements Externalizab
if ( normalizedValue.length() > 0 )
{
- sb.append( normalizeValue() );
+ sb.append( Rdn.escapeValue( normalizedValue ) );
}
return sb.toString();
@@ -1050,7 +1050,7 @@ public class Ava implements Externalizab
/**
- * We read back the data to create a new ATAV. The structure
+ * We read back the data to create a new ATAV. The structure
* read is exposed in the {@link Ava#writeExternal(ObjectOutput)}
* method
*
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=1291551&r1=1291550&r2=1291551&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 Feb 21 01:58:56 2012
@@ -1221,108 +1221,116 @@ public class Rdn implements Cloneable, E
return "";
}
- char[] chars = value.toCharArray();
- char[] newChars = new char[chars.length * 3];
+ byte[] bytes = Strings.getBytesUtf8( value );
+ byte[] newBytes = new byte[bytes.length * 3];
int pos = 0;
- for ( int i = 0; i < chars.length; i++ )
+ for ( int i = 0; i < bytes.length; i++ )
{
- switch ( chars[i] )
+ if ( ( bytes[i] & 0x0080 ) != 0 )
{
- case ' ':
- if ( ( i > 0 ) && ( i < chars.length - 1 ) )
- {
- newChars[pos++] = chars[i];
- }
- else
- {
- newChars[pos++] = '\\';
- newChars[pos++] = chars[i];
- }
-
- break;
-
- case '#':
- if ( i != 0 )
- {
- newChars[pos++] = chars[i];
- }
- else
- {
- newChars[pos++] = '\\';
- newChars[pos++] = chars[i];
- }
-
- break;
-
- case '"':
- case '+':
- case ',':
- case ';':
- case '=':
- case '<':
- case '>':
- case '\\':
- newChars[pos++] = '\\';
- newChars[pos++] = chars[i];
- break;
-
- case 0x7F:
- newChars[pos++] = '\\';
- newChars[pos++] = '7';
- newChars[pos++] = 'F';
- break;
-
- case 0x00:
- case 0x01:
- case 0x02:
- case 0x03:
- case 0x04:
- case 0x05:
- case 0x06:
- case 0x07:
- case 0x08:
- case 0x09:
- case 0x0A:
- case 0x0B:
- case 0x0C:
- case 0x0D:
- case 0x0E:
- case 0x0F:
- newChars[pos++] = '\\';
- newChars[pos++] = '0';
- newChars[pos++] = Strings.dumpHex( ( byte ) ( chars[i] & 0x0F ) );
- break;
-
- case 0x10:
- case 0x11:
- case 0x12:
- case 0x13:
- case 0x14:
- case 0x15:
- case 0x16:
- case 0x17:
- case 0x18:
- case 0x19:
- case 0x1A:
- case 0x1B:
- case 0x1C:
- case 0x1D:
- case 0x1E:
- case 0x1F:
- newChars[pos++] = '\\';
- newChars[pos++] = '1';
- newChars[pos++] = Strings.dumpHex( ( byte ) ( chars[i] & 0x0F ) );
- break;
-
- default:
- newChars[pos++] = chars[i];
- break;
-
+ newBytes[pos++] = '\\';
+ newBytes[pos++] = (byte)Strings.dumpHex( (byte)( (bytes[i] & 0x00F0 ) >> 4 ) );
+ newBytes[pos++] = (byte)Strings.dumpHex( (byte)(bytes[i] & 0x000F) );
+ }
+ else
+ {
+ switch ( bytes[i] )
+ {
+ case ' ':
+ if ( ( i > 0 ) && ( i < bytes.length - 1 ) )
+ {
+ newBytes[pos++] = bytes[i];
+ }
+ else
+ {
+ newBytes[pos++] = '\\';
+ newBytes[pos++] = bytes[i];
+ }
+
+ break;
+
+ case '#':
+ if ( i != 0 )
+ {
+ newBytes[pos++] = bytes[i];
+ }
+ else
+ {
+ newBytes[pos++] = '\\';
+ newBytes[pos++] = bytes[i];
+ }
+
+ break;
+
+ case '"':
+ case '+':
+ case ',':
+ case ';':
+ case '=':
+ case '<':
+ case '>':
+ case '\\':
+ newBytes[pos++] = '\\';
+ newBytes[pos++] = bytes[i];
+ break;
+
+ case 0x7F:
+ newBytes[pos++] = '\\';
+ newBytes[pos++] = '7';
+ newBytes[pos++] = 'F';
+ break;
+
+ case 0x00:
+ case 0x01:
+ case 0x02:
+ case 0x03:
+ case 0x04:
+ case 0x05:
+ case 0x06:
+ case 0x07:
+ case 0x08:
+ case 0x09:
+ case 0x0A:
+ case 0x0B:
+ case 0x0C:
+ case 0x0D:
+ case 0x0E:
+ case 0x0F:
+ newBytes[pos++] = '\\';
+ newBytes[pos++] = '0';
+ newBytes[pos++] = (byte)Strings.dumpHex( ( byte ) ( bytes[i] & 0x0F ) );
+ break;
+
+ case 0x10:
+ case 0x11:
+ case 0x12:
+ case 0x13:
+ case 0x14:
+ case 0x15:
+ case 0x16:
+ case 0x17:
+ case 0x18:
+ case 0x19:
+ case 0x1A:
+ case 0x1B:
+ case 0x1C:
+ case 0x1D:
+ case 0x1E:
+ case 0x1F:
+ newBytes[pos++] = '\\';
+ newBytes[pos++] = '1';
+ newBytes[pos++] = (byte)Strings.dumpHex( ( byte ) ( bytes[i] & 0x0F ) );
+ break;
+
+ default:
+ newBytes[pos++] = bytes[i];
+ break;
+ }
}
}
- return new String( newChars, 0, pos );
+ return new String( newBytes, 0, pos );
}
Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java?rev=1291551&r1=1291550&r2=1291551&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java (original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java Tue Feb 21 01:58:56 2012
@@ -6,16 +6,16 @@
* to you 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.shared.ldap.model.name;
@@ -252,8 +252,8 @@ public class AvaTest
public void testAvaSimpleNorm() throws LdapException
{
Ava atav = new Ava( schemaManager, " CommonName ", " This is a TEST " );
- assertEquals( " CommonName = This is a TEST ", atav.toString() );
+ assertEquals( " CommonName =\\ This is a TEST\\ ", atav.toString() );
assertEquals( "commonname=\\ This is a TEST\\ ", atav.getNormName() );
- assertEquals( " CommonName = This is a TEST ", atav.getUpName() );
+ assertEquals( " CommonName =\\ This is a TEST\\ ", atav.getUpName() );
}
}
Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnParserTest.java?rev=1291551&r1=1291550&r2=1291551&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnParserTest.java (original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/DnParserTest.java Tue Feb 21 01:58:56 2012
@@ -189,11 +189,11 @@ public class DnParserTest
public void testLdapDNPairCharAttributeValue() throws LdapException
{
Dn dn = new Dn( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9" );
- assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\u00e9", dn.getNormName() );
+ assertEquals( "a=\\,\\=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9", dn.getNormName() );
assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C3\\A9", dn.getName() );
dn = new Dn( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\u00e9" );
- assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\u00e9", dn.getNormName() );
+ assertEquals( "a=\\,\\=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9", dn.getNormName() );
assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\u00e9", dn.getName() );
}
@@ -281,7 +281,7 @@ public class DnParserTest
Dn name = new Dn( dn );
assertEquals( dn, name.getName() );
- assertEquals( "cn=Emmanuel L\u00e9charny", name.getNormName() );
+ assertEquals( "cn=Emmanuel L\\C3\\A9charny", name.getNormName() );
}
@@ -294,7 +294,7 @@ public class DnParserTest
Dn name = new Dn( dn );
assertEquals( dn, name.getName() );
- assertEquals( "c=E\u00e9c", name.getNormName() );
+ assertEquals( "c=E\\C3\\A9c", name.getNormName() );
}
@@ -557,7 +557,7 @@ public class DnParserTest
String result = new Dn( cn ).getNormName();
- assertEquals( "cn=\u00c4\\+", result );
+ assertEquals( "cn=\\C3\\84\\+", result );
}
@@ -565,11 +565,11 @@ public class DnParserTest
public void testAUmlautPlusChar() throws Exception
{
String cn = new String( new byte[]
- { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, '\\', '+' }, "UTF-8" );
+ { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0xA4, '\\', '+' }, "UTF-8" );
String result = new Dn( cn ).toString();
- assertEquals( "cn=\u00c4\\+", result );
+ assertEquals( "cn=\u00E4\\+", result );
}
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=1291551&r1=1291550&r2=1291551&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 Feb 21 01:58:56 2012
@@ -6,16 +6,16 @@
* to you 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.shared.ldap.model.name;
@@ -53,12 +53,12 @@ public class FastDnParserTest
@Test
public void testLdapDNEmpty() throws LdapException
{
- assertEquals( "", ( ( Dn ) FastDnParser.parse( "" ) ).getName() );
+ assertEquals( "", FastDnParser.parse( "" ).getName() );
}
/**
- * Tests incomplete DNs, used to check that the parser does not
+ * Tests incomplete DNs, used to check that the parser does not
* run into infinite loops.
*/
@Test
@@ -410,7 +410,7 @@ public class FastDnParserTest
Dn name = FastDnParser.parse( dn );
assertEquals( dn, name.getName() );
- assertEquals( "cn=Emmanuel L\u00e9charny", name.getNormName() );
+ assertEquals( "cn=Emmanuel L\\C3\\A9charny", name.getNormName() );
}
@@ -423,7 +423,7 @@ public class FastDnParserTest
Dn name = FastDnParser.parse( dn );
assertEquals( dn, name.getName() );
- assertEquals( "c=E\u00e9c", name.getNormName() );
+ assertEquals( "c=E\\C3\\A9c", name.getNormName() );
}
@@ -504,7 +504,7 @@ public class FastDnParserTest
{
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() );
+ assertEquals( "RFC2253_1 : ", "CN=Steve Kille,O=Isode limited,C=GB", nameRFC2253_1.getName() );
}
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=1291551&r1=1291550&r2=1291551&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 Feb 21 01:58:56 2012
@@ -226,7 +226,7 @@ public class RdnTest
String rdn = Strings.utf8ToString( new byte[]
{ 'a', '=', '\\', ',', '=', '\\', '+', '\\', '<', '\\', '>', '#', '\\', ';', '\\', '\\', '\\', '"', '\\',
'C', '3', '\\', 'A', '9' } );
- assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\u00E9", new Rdn( rdn ).getNormName() );
+ assertEquals( "a=\\,\\=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9", new Rdn( rdn ).getNormName() );
}