Index: modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java =================================================================== --- modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java (revision 548599) +++ modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java (working copy) @@ -28,11 +28,14 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; + import javax.naming.InvalidNameException; +import javax.naming.directory.BasicAttributes; import javax.naming.ldap.LdapName; import javax.naming.ldap.Rdn; import junit.framework.TestCase; + import org.apache.harmony.testframework.serialization.SerializationTest; /** @@ -280,6 +283,21 @@ *

* Test method for 'javax.naming.ldap.LdapName(String)' *

+ */ + public void testLdapNameString002() throws Exception { + String str = "t=\\20\\ te\\ s\\20t\\20\\20 + t2 = test1\\20\\ "; + LdapName ln = new LdapName(str); + assertEquals(ln.toString(), str); + ln.get(0); + assertEquals(ln.toString(), str); + ln.add("t=test"); + assertEquals(ln.toString(), "t=test,t=\\ \\ te s t\\ +t2=test1\\ \\ "); + } + + /** + *

+ * Test method for 'javax.naming.ldap.LdapName(String)' + *

*

* Here we are testing the constructor method, this method should recive a * non-null String, this string must be a valid string like @@ -760,6 +778,35 @@ /** *

+ * Test method for 'javax.naming.ldap.LdapName.LdapName(List)' + *

+ *

+ * Here we are testing the constructor method of LdapName reciving a list of + * valid names. + *

+ *

+ * The expected result is an instance of an object of LdapName, and also + * that the indexing is made like the other way around. + *

+ */ + public void testLdapNameListOfRdn006() throws Exception { + try { + BasicAttributes bas = new BasicAttributes(); + bas.put("test2", "test2"); + bas.put("test1", "test1"); + bas.put("test3", "test3"); + Rdn rdn1 = new Rdn(bas); + LinkedList rdns = new LinkedList(); + rdns.add(rdn1); + LdapName ln = new LdapName(rdns); + assertEquals("test1=test1+test2=test2+test3=test3", ln.getAll().nextElement()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + *

* Test method for 'javax.naming.ldap.LdapName.hashCode()' *

*

@@ -1030,7 +1077,7 @@ *

*/ public void testToString004() throws Exception { - LdapName ln = new LdapName("t=\\4c\\4c"); + LdapName ln = new LdapName("t=ll"); assertEquals("T=LL", ln.toString().toUpperCase()); } Index: modules/jndi/src/main/java/javax/naming/ldap/LdapName.java =================================================================== --- modules/jndi/src/main/java/javax/naming/ldap/LdapName.java (revision 548599) +++ modules/jndi/src/main/java/javax/naming/ldap/LdapName.java (working copy) @@ -42,6 +42,8 @@ private static final long serialVersionUID = -1595520034788997356L; private transient List rdns; + + private transient String rdnsStr; /** * @ar.org.fitc.spec_ref @@ -59,7 +61,8 @@ * @ar.org.fitc.spec_ref */ public LdapName(String name) throws InvalidNameException { - LdapNameParser parser = new LdapNameParser(name); + rdnsStr = name; + LdapNameParser parser = new LdapNameParser(rdnsStr); this.rdns = parser.getList(); } @@ -78,6 +81,7 @@ } rdns.add(posn, comp); + rdnsStr = null; return this; } @@ -116,6 +120,7 @@ } rdns.addAll(posn, suffixRdns); + rdnsStr = null; return this; } @@ -152,6 +157,12 @@ * @ar.org.fitc.spec_ref */ public Object clone() { + try { + if (rdnsStr != null) { + return new LdapName(rdnsStr); + } + } catch (InvalidNameException e) { + } List lista = new ArrayList(); for (int i = 0; i < rdns.size(); i++) { lista.add(rdns.get(i)); @@ -324,6 +335,7 @@ * @ar.org.fitc.spec_ref */ public Object remove(int posn) throws InvalidNameException { + rdnsStr = null; return rdns.remove(posn).toString(); } @@ -370,6 +382,9 @@ * @ar.org.fitc.spec_ref */ public String toString() { + if (rdnsStr != null) { + return rdnsStr; + } if (rdns.size() == 0) { return ""; }