harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r671862 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java
Date Thu, 26 Jun 2008 11:36:12 GMT
Author: hindessm
Date: Thu Jun 26 04:36:11 2008
New Revision: 671862

URL: http://svn.apache.org/viewvc?rev=671862&view=rev
Log:
Applying patches from "[#HARMONY-5881] [classlib][jndi][ldap] - check and
change the value of batchSize in
LdapContextImpl.addToEnvironment/removeFromEnvironment methods".

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java?rev=671862&r1=671861&r2=671862&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
Thu Jun 26 04:36:11 2008
@@ -145,6 +145,8 @@
 
     private String[] binaryAttributes;
 
+    private int batchSize = 0;
+
     private static final Control NON_CRITICAL_MANAGE_REF_CONTROL = new ManageReferralControl(
             Control.NONCRITICAL);
 
@@ -1188,6 +1190,7 @@
     LdapSearchResult doSearch(SearchOp op) throws NamingException {
         applyEnvChange();
 
+        op.setBatchSize(batchSize);
         if (env.get(LDAP_DEREF_ALIASES) != null) {
             String derefAliases = (String) env.get(LDAP_DEREF_ALIASES);
             if (derefAliases.equals("always")) {
@@ -1357,13 +1360,6 @@
     LdapSearchResult doSearch(String dn, Filter filter, SearchControls controls)
             throws NamingException {
         SearchOp op = new SearchOp(dn, controls, filter);
-        String stringValue = (String) env.get(Context.BATCHSIZE);
-        if (stringValue == null) {
-            op.setBatchSize(0);
-        } else {
-            op.setBatchSize(Integer.valueOf(stringValue).intValue());
-        }
-
         return doSearch(op);
     }
 
@@ -1372,6 +1368,13 @@
             throw new NullPointerException();
         }
 
+        if (s.equals(Context.BATCHSIZE)) {
+            batchSize = Integer.parseInt((String) o);
+        } else if (s.equals(LDAP_ATTRIBUTES_BINARY)) {
+            String value = (String) o;
+            binaryAttributes = value.trim().split(" ");
+        }
+
         Object preValue = env.put(s, o);
 
         // if preValue equals o, do nothing
@@ -1388,11 +1391,6 @@
             isReBind = true;
         }
 
-        if (s.equals(LDAP_ATTRIBUTES_BINARY)) {
-            String value = (String) o;
-            StringTokenizer st = new StringTokenizer(value.trim());
-            binaryAttributes = value.trim().split(" ");
-        }
         return preValue;
     }
 
@@ -1901,6 +1899,12 @@
             throw new NullPointerException();
         }
 
+        if (s.equals(Context.BATCHSIZE)) {
+            batchSize = 0;
+        } else if (s.equals(LDAP_ATTRIBUTES_BINARY)) {
+            binaryAttributes = null;
+        }
+
         Object preValue = env.remove(s);
 
         // if s doesn't exist in env
@@ -1916,10 +1920,6 @@
             isReBind = true;
         }
 
-        if (s.equals(LDAP_ATTRIBUTES_BINARY)) {
-            binaryAttributes = null;
-        }
-
         return preValue;
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java?rev=671862&r1=671861&r2=671862&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java
Thu Jun 26 04:36:11 2008
@@ -483,6 +483,43 @@
         }
     }
 
+    public void testAddToEnvironment_batchSizeProp() throws Exception {
+        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
+                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
+
+        assertNull(env.get(Context.REFERRAL));
+        InitialDirContext initialDirContext = new InitialDirContext(env);
+
+        initialDirContext.addToEnvironment(Context.BATCHSIZE, "4");
+        assertEquals("4", initialDirContext.getEnvironment().get(
+                Context.BATCHSIZE));
+
+        try {
+            initialDirContext.addToEnvironment(Context.BATCHSIZE, "wrong");
+            fail("Should throw NumberFormatException");
+        } catch (NumberFormatException e) {
+            // expected
+        }
+        assertEquals("4", initialDirContext.getEnvironment().get(
+                Context.BATCHSIZE));
+
+        try {
+            initialDirContext.addToEnvironment(Context.BATCHSIZE, "3.3");
+            fail("Should throw NumberFormatException");
+        } catch (NumberFormatException e) {
+            // expected
+        }
+        assertEquals("4", initialDirContext.getEnvironment().get(
+                Context.BATCHSIZE));
+
+        try {
+            initialDirContext.addToEnvironment(Context.BATCHSIZE, new Object());
+            fail("Should throw ClassCastException");
+        } catch (ClassCastException e) {
+            // expected
+        }
+    }
+
     public void testReconnect() throws Exception {
         Control[] expected = new Control[] { new PagedResultsControl(10,
                 Control.NONCRITICAL) };



Mime
View raw message