harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r548890 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/javax/naming/ldap/LdapName.java test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java
Date Wed, 20 Jun 2007 01:52:45 GMT
Author: tonywu
Date: Tue Jun 19 18:52:44 2007
New Revision: 548890

URL: http://svn.apache.org/viewvc?view=rev&rev=548890
Log:
Apply patch HARMONY-4231 ([classlib][jndi] LdapName.toString() should return the original
String when no modification)

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/LdapName.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/LdapName.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/LdapName.java?view=diff&rev=548890&r1=548889&r2=548890
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/LdapName.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/LdapName.java
Tue Jun 19 18:52:44 2007
@@ -42,6 +42,8 @@
     private static final long serialVersionUID = -1595520034788997356L;
 
     private transient List<Rdn> 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<Rdn> lista = new ArrayList<Rdn>();
         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 "";
         }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java?view=diff&rev=548890&r1=548889&r2=548890
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapNameTest.java
Tue Jun 19 18:52:44 2007
@@ -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 @@
      * <p>
      * Test method for 'javax.naming.ldap.LdapName(String)'
      * </p>
+     */
+    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\\ \\ ");
+    }
+
+    /**
+     * <p>
+     * Test method for 'javax.naming.ldap.LdapName(String)'
+     * </p>
      * <p>
      * 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 @@
 
     /**
      * <p>
+     * Test method for 'javax.naming.ldap.LdapName.LdapName(List<Rdn>)'
+     * </p>
+     * <p>
+     * Here we are testing the constructor method of LdapName reciving a list of
+     * valid names.
+     * </p>
+     * <p>
+     * The expected result is an instance of an object of LdapName, and also
+     * that the indexing is made like the other way around.
+     * </p>
+     */    
+    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<Rdn> rdns = new LinkedList<Rdn>();
+            rdns.add(rdn1);
+            LdapName ln = new LdapName(rdns);
+            assertEquals("test1=test1+test2=test2+test3=test3", ln.getAll().nextElement());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * <p>
      * Test method for 'javax.naming.ldap.LdapName.hashCode()'
      * </p>
      * <p>
@@ -1030,7 +1077,7 @@
      * </p>
      */
     public void testToString004() throws Exception {
-        LdapName ln = new LdapName("t=\\4c\\4c");
+        LdapName ln = new LdapName("t=ll");
         assertEquals("T=LL", ln.toString().toUpperCase());
     }
 



Mime
View raw message