harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r593041 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/provider/ldap/ main/java/org/apache/harmony/jndi/provider/ldap/parser/ test/java/org/apache/harmony/jndi/provider/ldap/ test/java/org/apache/h...
Date Thu, 08 Nov 2007 07:07:38 GMT
Author: tonywu
Date: Wed Nov  7 23:07:37 2007
New Revision: 593041

URL: http://svn.apache.org/viewvc?rev=593041&view=rev
Log:
Apply patch Harmony-5089 ( [classlib][jndi][ldap] refactor LdapOperation add getResult method,
and some other misc improvement)

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/AddOp.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/CompareOp.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapOperation.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOp.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/FilterParserConstants.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParser.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/url.g
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParserTest.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/AddOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/AddOp.java?rev=593041&r1=593040&r2=593041&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/AddOp.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/AddOp.java
Wed Nov  7 23:07:37 2007
@@ -31,12 +31,13 @@
  * formate bytes to java objects.
  */
 final public class AddOp implements LdapOperation, ASN1Encodable {
+    // Attribute list
     private List<LdapAttribute> attrList;
 
     // LDAP distinguished name
     private String entry;
 
-    // Attribute list
+    // LDAP operation result
     private LdapResult result;
 
     public AddOp(String entry, List<LdapAttribute> attrList) {
@@ -76,6 +77,14 @@
     public void encodeValues(Object[] values) {
         values[0] = Utils.getBytes(entry);
         values[1] = attrList;
+    }
+
+    public List<LdapAttribute> getAttributeList() {
+        return attrList;
+    }
+
+    public String getEntry() {
+        return entry;
     }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/CompareOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/CompareOp.java?rev=593041&r1=593040&r2=593041&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/CompareOp.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/CompareOp.java
Wed Nov  7 23:07:37 2007
@@ -61,4 +61,8 @@
         values[1] = objs;
     }
 
+    public LdapResult getResult() {
+        return result;
+    }
+
 }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapOperation.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapOperation.java?rev=593041&r1=593040&r2=593041&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapOperation.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapOperation.java
Wed Nov  7 23:07:37 2007
@@ -53,4 +53,15 @@
      * @return index of response of this operation
      */
     public int getResponseId();
+
+    /**
+     * Get <code>LdapResult</code> from response. Except unbind and abandon
+     * operation, all ldap operation response contains LdapResult, which
+     * indicate whether the operation is successful or what error occurs.
+     * 
+     * @return instance of <code>LdapResult</code>. <code>null</code>
if
+     *         operation has not completed or response donesn't contian
+     *         LDAPResult.
+     */
+    public LdapResult getResult();
 }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOp.java?rev=593041&r1=593040&r2=593041&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOp.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyDNOp.java
Wed Nov  7 23:07:37 2007
@@ -66,4 +66,24 @@
         }
     }
 
+    public LdapResult getResult() {
+        return result;
+    }
+
+    public boolean isDeleteoldrdn() {
+        return deleteoldrdn;
+    }
+
+    public String getEntry() {
+        return entry;
+    }
+
+    public String getNewrdn() {
+        return newrdn;
+    }
+
+    public String getNewSuperior() {
+        return newSuperior;
+    }
+
 }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java?rev=593041&r1=593040&r2=593041&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ModifyOp.java
Wed Nov  7 23:07:37 2007
@@ -82,4 +82,9 @@
             values[1] = attr;
         }
     }
+
+    public LdapResult getResult() {
+        return result;
+    }
+    
 }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java?rev=593041&r1=593040&r2=593041&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/SearchOp.java
Wed Nov  7 23:07:37 2007
@@ -33,14 +33,17 @@
     private String baseObject;
 
     private boolean typesOnly = false;
+    
+    // default value is 'always' = 3
+    private int derefAliases = 3;
 
     private Filter filter;
 
     private SearchControls controls;
 
-    private LdapSearchResult result = new LdapSearchResult();
+    private LdapSearchResult result;
 
-    public LdapSearchResult getResult() {
+    public LdapSearchResult getSearchResult() {
         return result;
     }
 
@@ -70,20 +73,15 @@
     public void encodeValues(Object[] values) {
         values[0] = Utils.getBytes(baseObject);
         values[1] = ASN1Integer.fromIntValue(controls.getSearchScope());
-        if (controls.getDerefLinkFlag()) {
-            // derefAlways
-            values[2] = ASN1Integer.fromIntValue(3);
-        } else {
-            // neverDerefAliases
-            values[2] = ASN1Integer.fromIntValue(0);
-        }
+        values[2] = ASN1Integer.fromIntValue(derefAliases);
         values[3] = ASN1Integer.fromIntValue((int) controls.getCountLimit());
         values[4] = ASN1Integer.fromIntValue(controls.getTimeLimit());
         values[5] = Boolean.valueOf(typesOnly);
         values[6] = filter;
         String[] attributes = controls.getReturningAttributes();
+        // if null, return all attributes
         if (attributes == null) {
-            attributes = new String[] { "" };
+            attributes = new String[0];
         }
 
         List<byte[]> list = new ArrayList<byte[]>(attributes.length);
@@ -95,8 +93,57 @@
     }
 
     public void decodeValues(Object[] values) {
-        
+        if (result == null) {
+            result = new LdapSearchResult();
+        }
         result.decodeSearchResponse(values);
+    }
+
+    public String getBaseObject() {
+        return baseObject;
+    }
+
+    public SearchControls getControls() {
+        return controls;
+    }
+
+    public Filter getFilter() {
+        return filter;
+    }
+
+    public boolean isTypesOnly() {
+        return typesOnly;
+    }
+
+    public void setSearchResult(LdapSearchResult result) {
+        this.result = result;
+    }
+
+    public LdapResult getResult() {
+        if (result == null) {
+            return null;
+        }
+        return result.getResult();
+    }
+
+    public int getDerefAliases() {
+        return derefAliases;
+    }
+
+    public void setDerefAliases(int derefAliases) {
+        this.derefAliases = derefAliases;
+    }
+
+    public void setTypesOnly(boolean typesOnly) {
+        this.typesOnly = typesOnly;
+    }
+
+    public void setBaseObject(String baseObject) {
+        this.baseObject = baseObject;
+    }
+
+    public void setFilter(Filter filter) {
+        this.filter = filter;
     }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/FilterParserConstants.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/FilterParserConstants.java?rev=593041&r1=593040&r2=593041&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/FilterParserConstants.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/FilterParserConstants.java
Wed Nov  7 23:07:37 2007
@@ -1,4 +1,3 @@
-/* Generated By:JavaCC: Do not edit this line. FilterParserConstants.java */
 /* 
  *  Licensed to the Apache Software Foundation (ASF) under one or more 
  *  contributor license agreements.  See the NOTICE file distributed with 
@@ -15,6 +14,7 @@
  *  See the License for the specific language governing permissions and 
  *  limitations under the License. 
  */
+/* Generated By:JavaCC: Do not edit this line. FilterParserConstants.java */
 
 package org.apache.harmony.jndi.provider.ldap.parser;
 

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParser.java?rev=593041&r1=593040&r2=593041&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParser.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParser.java
Wed Nov  7 23:07:37 2007
@@ -32,14 +32,28 @@
 
     private Filter filter;
 
-    private String baseObject;
+    private String baseObject = "";
 
-    private String host;
+    private String host = DEFAULT_HOST;
 
-    private int port = -1;
+    private int port = DEFAULT_PORT;
+
+    private boolean hasAttributes = false;
+
+    private boolean hasScope = false;
+
+    private boolean hasFilter = false;
+
+    private boolean hasExtensions= false;
 
     private boolean isEndEOF = false;
 
+    private static final int DEFAULT_PORT = 389;
+
+    private static final int DEFAULT_SSL_PORT = 636;
+
+    private static final String DEFAULT_HOST = "localhost";
+
     public LdapUrlParser(String url) {
         this(new StringReader(url));
         isEndEOF = true;
@@ -82,6 +96,22 @@
         return baseObject;
     }
 
+    public boolean hasFilter() {
+        return hasFilter;
+    }
+
+    public boolean hasAttributes() {
+        return hasAttributes;
+    }
+
+    public boolean hasScope() {
+        return hasScope;
+    }
+
+    public boolean hasExtensions() {
+        return hasExtensions;
+    }
+
     public static void main(String args[]) throws ParseException, FileNotFoundException {
         LdapUrlParser parser = new LdapUrlParser(new FileInputStream("parser.url.test"));
 //        URLParser parser = new URLParser(System.in);
@@ -92,7 +122,11 @@
     }
 
   final public void parseURL() throws ParseException {
-    jj_consume_token(SCHEME);
+            Token t;
+    t = jj_consume_token(SCHEME);
+                    if (t.image.equals("ldaps://")) {
+                        port = DEFAULT_SSL_PORT;
+                    }
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
     case SCHEME:
     case PRE_XTOKEN:
@@ -453,9 +487,10 @@
       ;
     }
                 if (attrs.size() != 0) {
+                    hasAttributes = true;
                     if (controls == null) {
                         // FIXME: test what default search parameter value is
-                        controls = new SearchControls(SearchControls.OBJECT_SCOPE, 0, 0,
null, false, false);
+                        controls = new SearchControls();
                     }
                     controls.setReturningAttributes((String[]) attrs.toArray(new String[0]));
                 }
@@ -481,9 +516,9 @@
     case SCOPE:
       t = jj_consume_token(SCOPE);
                     scope = t.image;
+                    hasScope = true;
                     if (controls == null) {
-                        // FIXME: test what default search parameter value is
-                        controls = new SearchControls(SearchControls.OBJECT_SCOPE, 0, 0,
null, false, false);
+                        controls = new SearchControls();
                     }
                     if (scope.equals("base")) {
                         controls.setSearchScope(SearchControls.OBJECT_SCOPE);
@@ -526,6 +561,7 @@
       value = value();
                     FilterParser parser = new FilterParser(new StringReader(value));
                     filter = parser.parse();
+                    hasFilter = true;
       break;
     default:
       jj_la1[21] = jj_gen;
@@ -544,6 +580,7 @@
 
   final public void extensions() throws ParseException {
     extension();
+                         hasExtensions = true;
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
     case COMMA:
       label_6:

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/url.g
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/url.g?rev=593041&r1=593040&r2=593041&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/url.g
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/url.g
Wed Nov  7 23:07:37 2007
@@ -39,14 +39,28 @@
     
     private Filter filter;
  
-    private String baseObject;
+    private String baseObject = "";
 
-    private String host;
+    private String host = DEFAULT_HOST;
 
-    private int port = -1;
+    private int port = DEFAULT_PORT;
+
+    private boolean hasAttributes = false;
+
+    private boolean hasScope = false;
+
+    private boolean hasFilter = false;
+
+    private boolean hasExtensions= false;
 
     private boolean isEndEOF = false;
 
+    private static final int DEFAULT_PORT = 389;
+
+    private static final int DEFAULT_SSL_PORT = 636;
+
+    private static final String DEFAULT_HOST = "localhost";
+
     public LdapUrlParser(String url) {
         this(new StringReader(url));
         isEndEOF = true;
@@ -89,6 +103,22 @@
         return baseObject;
     }
 
+    public boolean hasFilter() {
+        return hasFilter;
+    }
+
+    public boolean hasAttributes() {
+        return hasAttributes;
+    }
+
+    public boolean hasScope() {
+        return hasScope;
+    }
+
+    public boolean hasExtensions() {
+        return hasExtensions;
+    }
+
     public static void main(String args[]) throws ParseException, FileNotFoundException {
         LdapUrlParser parser = new LdapUrlParser(new FileInputStream("parser.url.test"));
 //        URLParser parser = new URLParser(System.in);
@@ -140,9 +170,16 @@
 
 
 void parseURL():
-        {}
         {
-            <SCHEME> 
+            Token t;
+        }
+        {
+            t = <SCHEME> 
+                {
+                    if (t.image.equals("ldaps://")) {
+                        port = DEFAULT_SSL_PORT;
+                    }
+                }
             [hostport()] 
             [<SLASH> [dn() 
                   [<QUESTION_MARK> attributes()]]]
@@ -254,9 +291,10 @@
              [(<COMMA> value = value() {attrs.add(value);})+]]
             {
                 if (attrs.size() != 0) {
+                    hasAttributes = true;
                     if (controls == null) {
                         // FIXME: test what default search parameter value is
-                        controls = new SearchControls(SearchControls.OBJECT_SCOPE, 0, 0,
null, false, false);
+                        controls = new SearchControls();
                     }
                     controls.setReturningAttributes((String[]) attrs.toArray(new String[0]));
                 }
@@ -279,9 +317,9 @@
             [t = <SCOPE> 
                 {
                     scope = t.image;
+                    hasScope = true;
                     if (controls == null) {
-                        // FIXME: test what default search parameter value is
-                        controls = new SearchControls(SearchControls.OBJECT_SCOPE, 0, 0,
null, false, false);
+                        controls = new SearchControls();
                     }
                     if (scope.equals("base")) {
                         controls.setSearchScope(SearchControls.OBJECT_SCOPE);
@@ -305,13 +343,15 @@
                 {
                     FilterParser parser = new FilterParser(new StringReader(value));
                     filter = parser.parse();
+                    hasFilter = true;
                 }] 
             [<QUESTION_MARK> extensions()]
         }
+
 void extensions():
         {}
         {
-            extension() [(<COMMA> extension())+]
+            extension() {hasExtensions = true;} [(<COMMA> extension())+]
         }
 
 void extension():

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java?rev=593041&r1=593040&r2=593041&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java
Wed Nov  7 23:07:37 2007
@@ -17,6 +17,8 @@
 
 package org.apache.harmony.jndi.provider.ldap;
 
+import java.util.Collection;
+
 import javax.naming.directory.SearchControls;
 
 import junit.framework.TestCase;
@@ -31,7 +33,14 @@
         Filter filter = new Filter(7);
         filter.setValue(Utils.getBytes("objectClass"));
         SearchOp op = new SearchOp("test", controls, filter);
-        
-        ASN1TestUtils.checkEncode(op.getRequest(), LdapASN1Constant.SearchRequest);
+
+        ASN1TestUtils.checkEncode(op.getRequest(),
+                LdapASN1Constant.SearchRequest);
+
+        Object[] encoded = new Object[8];
+        op.encodeValues(encoded);
+        // return attributes is null, encode to empty collection
+        assertNull(controls.getReturningAttributes());
+        assertEquals(((Collection) encoded[7]).size(), 0);
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParserTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParserTest.java?rev=593041&r1=593040&r2=593041&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParserTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParserTest.java
Wed Nov  7 23:07:37 2007
@@ -37,57 +37,85 @@
     }
 
     public void test_parseURL() throws Exception {
-        parser = new LdapUrlParser("ldap://192.168.1.3:389");
+        parser = new LdapUrlParser("ldap://192.168.1.3:666");
         parser.parseURL();
-        assertNull(parser.getBaseObject());
+        // default dn is empty
+        assertEquals("", parser.getBaseObject());
+        assertFalse(parser.hasFilter());
         assertNull(parser.getFilter());
+        assertFalse(parser.hasAttributes());
+        assertFalse(parser.hasScope());
+        assertFalse(parser.hasExtensions());
         assertNull(parser.getControls());
         assertEquals("192.168.1.3", parser.getHost());
-        assertEquals(389, parser.getPort());
+        assertEquals(666, parser.getPort());
 
         parser = new LdapUrlParser("ldap://192.168.1.3/o=University,c=US");
         parser.parseURL();
         assertEquals("o=University,c=US", parser.getBaseObject());
+        assertFalse(parser.hasFilter());
         assertNull(parser.getFilter());
+        assertFalse(parser.hasAttributes());
+        assertFalse(parser.hasScope());
+        assertFalse(parser.hasExtensions());
         assertNull(parser.getControls());
         assertEquals("192.168.1.3", parser.getHost());
+        // default port is 389
+        assertEquals(389, parser.getPort());
 
         parser = new LdapUrlParser(
-                "ldap://192.168.1.3/o=University,c=US?postalAddress");
+                "ldaps://192.168.1.3/o=University,c=US?postalAddress");
         parser.parseURL();
         assertEquals("o=University,c=US", parser.getBaseObject());
         assertEquals("192.168.1.3", parser.getHost());
         assertNotNull(parser.getControls());
+        assertTrue(parser.hasAttributes());
+        assertFalse(parser.hasScope());
+        assertFalse(parser.hasExtensions());
         controls = parser.getControls();
-        assertEquals(SearchControls.OBJECT_SCOPE, controls.getSearchScope());
+        assertEquals(SearchControls.ONELEVEL_SCOPE, controls.getSearchScope());
         assertEquals(1, controls.getReturningAttributes().length);
         assertEquals("postalAddress", controls.getReturningAttributes()[0]);
         assertNull(parser.getFilter());
-
+        // default ssl port is 636
+        assertEquals(636, parser.getPort());
+        
+        
         parser = new LdapUrlParser(
                 "ldap://192.168.1.3/o=University,c=US?postalAddress,o");
         parser.parseURL();
         assertEquals("o=University,c=US", parser.getBaseObject());
         assertEquals("192.168.1.3", parser.getHost());
+        assertTrue(parser.hasAttributes());
         assertNotNull(parser.getControls());
+        assertFalse(parser.hasScope());
+        assertFalse(parser.hasExtensions());
         controls = parser.getControls();
-        assertEquals(SearchControls.OBJECT_SCOPE, controls.getSearchScope());
+        assertEquals(SearchControls.ONELEVEL_SCOPE, controls.getSearchScope());
         assertEquals(2, controls.getReturningAttributes().length);
         assertEquals("postalAddress", controls.getReturningAttributes()[0]);
         assertEquals("o", controls.getReturningAttributes()[1]);
         assertNull(parser.getFilter());
-
+        // default port is 389
+        assertEquals(389, parser.getPort());
+        
         parser = new LdapUrlParser("ldap:///o=University,c=US");
         parser.parseURL();
         assertEquals("o=University,c=US", parser.getBaseObject());
         assertNull(parser.getFilter());
         assertNull(parser.getControls());
-        assertNull(parser.getHost());
+        // default host is 'localhost'
+        assertEquals("localhost", parser.getHost());
+        // default port is 389
+        assertEquals(389, parser.getPort());
 
         parser = new LdapUrlParser("ldap://192.168.1.3/o=University,c=US??sub");
         parser.parseURL();
         assertEquals("o=University,c=US", parser.getBaseObject());
         assertEquals("192.168.1.3", parser.getHost());
+        assertFalse(parser.hasAttributes());
+        assertTrue(parser.hasScope());
+        assertFalse(parser.hasExtensions());
         assertNotNull(parser.getControls());
         controls = parser.getControls();
         assertEquals(SearchControls.SUBTREE_SCOPE, controls.getSearchScope());
@@ -107,8 +135,12 @@
         assertEquals("c=US", parser.getBaseObject());
         assertEquals("192.168.1.3", parser.getHost());
         assertNotNull(parser.getControls());
+        assertTrue(parser.hasAttributes());
+        assertTrue(parser.hasScope());
+        assertFalse(parser.hasExtensions());
         controls = parser.getControls();
         assertEquals(SearchControls.SUBTREE_SCOPE, controls.getSearchScope());
+        assertTrue(parser.hasFilter());
         assertNotNull(parser.getFilter());
 
         parser = new LdapUrlParser(



Mime
View raw message