directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szoer...@apache.org
Subject svn commit: r330074 - in /directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search: AllTests.java SearchFilterSimpleTest.java
Date Tue, 01 Nov 2005 15:33:17 GMT
Author: szoerner
Date: Tue Nov  1 07:33:13 2005
New Revision: 330074

URL: http://svn.apache.org/viewcvs?rev=330074&view=rev
Log:
Modified test case for search op with NOT operarator and added it to the suite.

Modified:
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/AllTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterSimpleTest.java
  (contents, props changed)

Modified: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/AllTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/AllTests.java?rev=330074&r1=330073&r2=330074&view=diff
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/AllTests.java
(original)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/AllTests.java
Tue Nov  1 07:33:13 2005
@@ -32,6 +32,7 @@
     {
         TestSuite suite = new TestSuite("Search");
 
+        suite.addTestSuite(SearchFilterSimpleTest.class);
         suite.addTestSuite(SearchScopeTest.class);
         suite.addTestSuite(IllegalSearchFilterTest.class);
         suite.addTestSuite(SearchFilterAttributeNamesTest.class);

Modified: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterSimpleTest.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterSimpleTest.java?rev=330074&r1=330073&r2=330074&view=diff
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterSimpleTest.java
(original)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterSimpleTest.java
Tue Nov  1 07:33:13 2005
@@ -20,19 +20,19 @@
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
 import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+import org.apache.ldap.testsuite.ldaptests.jndi.util.AttributesFactory;
 
 /**
- * Tests for the search operations with JNDI.
+ * Tests for the search operations with JNDI containing simple filter
+ * expressions. All boolean operators are covered.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: $
+ * @version $Rev$
  */
 public class SearchFilterSimpleTest extends BaseProtocolTest
 {
@@ -43,19 +43,6 @@
 
     static final String[] lastNames = { "Amos", "Nova", "Morisette", "Bush", "Apple" };
 
-    protected Attributes getPersonAttributes(Person p)
-    {
-        Attributes attributes = new BasicAttributes();
-        Attribute attribute = new BasicAttribute("objectClass");
-        attribute.add("top");
-        attribute.add("person");
-        attributes.put(attribute);
-        attributes.put("sn", p.sn);
-        attributes.put("cn", p.cn);
-
-        return attributes;
-    }
-
     public void setUp() throws NamingException
     {
         super.setUp();
@@ -63,10 +50,17 @@
         ctx = this.createContext();
         ctx = (DirContext) ctx.lookup(this.getTestContainerRdn());
 
+        // Create person entries
         for (int i = 0; i < lastNames.length; ++i) {
-            Person p = new Person(firstNames[i], lastNames[i]);
-            ctx.createSubcontext("cn=" + p.cn, getPersonAttributes(p));
+            String cn = firstNames[i] + " " + lastNames[i];
+            Attributes person = AttributesFactory.createPersonAttributes(cn, lastNames[i]);
+            ctx.createSubcontext("cn=" + cn, person);
         }
+
+        // Create an organization Unit
+        String ou = "anOrgUnit";
+        Attributes orgUnit = AttributesFactory.createOrganizationalUnitAttributes(ou);
+        ctx.createSubcontext("ou=" + ou, orgUnit);
     }
 
     public void tearDown() throws NamingException
@@ -83,7 +77,7 @@
         SearchControls ctls = new SearchControls();
         ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
 
-        NamingEnumeration enm = ctx.search("", "sn=Amos", ctls);
+        NamingEnumeration enm = ctx.search("", "(sn=Amos)", ctls);
         assertTrue(enm.hasMore());
         int numberOfEntries = 0;
         while (enm.hasMore()) {
@@ -98,35 +92,53 @@
         }
 
         assertEquals("number of entries in result", 1, numberOfEntries);
+        enm.close();
     }
 
+    /**
+     * Test with a search filter which contains an NOT operator.
+     */
     public void testFilterWithNot() throws NamingException
     {
-
         SearchControls ctls = new SearchControls();
         ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
 
-        NamingEnumeration enm = ctx.search("", "(!(sn=Amos))", ctls);
+        // Filter "(!(objectClass=person))"
+        //
+        NamingEnumeration enm = ctx.search("", "(!(objectClass=person))", ctls);
         assertTrue(enm.hasMore());
         int numberOfEntries = 0;
         while (enm.hasMore()) {
             SearchResult entry = (SearchResult) enm.next();
             Attributes attrs = entry.getAttributes();
-            Attribute sn = attrs.get("sn");
+            Attribute ocls = attrs.get("objectClass");
 
-            assertFalse(sn.contains("Amos"));
+            assertFalse(ocls.contains("person"));
 
             numberOfEntries++;
         }
-        assertEquals("number of entries in result", firstNames.length - 1, numberOfEntries);
+        // Check whether number of entries foud is 1 (the org unit)
+        assertEquals("number of entries in result", 1, numberOfEntries);
+        enm.close();
+        
+        // Filter "(!(objectClass=*))"
+        //
+        enm = ctx.search("", "(!(objectClass=*))", ctls);
+        assertFalse("entries found", enm.hasMore());
+        enm.close();
     }
 
+    /**
+     * Test with search filters which contain an AND operator.
+     */
     public void testFilterWithAnd() throws NamingException
     {
 
         SearchControls ctls = new SearchControls();
         ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
 
+        // Filter "(&(objectClass=person)(sn=Amos))"
+        //
         NamingEnumeration enm = ctx.search("", "(&(objectClass=person)(sn=Amos))", ctls);
         assertTrue(enm.hasMore());
         int numberOfEntries = 0;
@@ -138,8 +150,18 @@
             numberOfEntries++;
         }
         assertEquals("number of entries in result", 1, numberOfEntries);
+        enm.close();
+        
+        // Filter "(&(sn=Amos)(sn=Bush))"
+        //
+        enm = ctx.search("", "(&(sn=Amos)(sn=Bush))", ctls);
+        assertFalse("entries found", enm.hasMore());
+        enm.close();
     }
 
+    /**
+     * Test with a search filter which contains an OR operator.
+     */
     public void testFilterWithOr() throws NamingException
     {
 
@@ -157,18 +179,6 @@
             numberOfEntries++;
         }
         assertEquals("number of entries in result", 2, numberOfEntries);
-    }
-
-    class Person
-    {
-
-        Person(String firstName, String lastName) {
-            this.sn = lastName;
-            this.cn = firstName + " " + lastName;
-        }
-
-        String sn;
-
-        String cn;
+        enm.close();
     }
 }

Propchange: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/search/SearchFilterSimpleTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



Mime
View raw message