directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r683514 [1/2] - in /directory/apacheds/branches/bigbang: server-integ/ server-integ/src/test/java/org/apache/directory/server/operations/search/ server-integ/src/test/java/org/apache/directory/server/suites/ server-unit/src/test/java/org/ap...
Date Thu, 07 Aug 2008 05:44:10 GMT
Author: akarasulu
Date: Wed Aug  6 22:44:09 2008
New Revision: 683514

URL: http://svn.apache.org/viewvc?rev=683514&view=rev
Log:
converted a number of search tests to new integ framework in server-integ: PSearch still not
operational.

Added:
    directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/
    directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/IndexedNegationSearchIT.java
    directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/NegationSearchIT.java
    directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/PersistentSearchTest.java
      - copied, changed from r683480, directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/PersistentSearchTest.java
    directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/SchemaSearchIT.java
    directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
Removed:
    directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/BinarySearchTest.java
    directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DIRSERVER951ITest.java
    directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/NegationOperatorITest.java
    directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/PersistentSearchTest.java
    directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SchemaSearchITest.java
    directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/SearchITest.java
Modified:
    directory/apacheds/branches/bigbang/server-integ/pom.xml
    directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/suites/StockServerISuite.java

Modified: directory/apacheds/branches/bigbang/server-integ/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-integ/pom.xml?rev=683514&r1=683513&r2=683514&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-integ/pom.xml (original)
+++ directory/apacheds/branches/bigbang/server-integ/pom.xml Wed Aug  6 22:44:09 2008
@@ -91,6 +91,7 @@
             <configuration>
               <includes>
                 <include>**/*ISuite.java</include>
+                <include>**/*IndexedNegationSearchIT.java</include>
               </includes>
             </configuration>
           </plugin>

Added: directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/IndexedNegationSearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/IndexedNegationSearchIT.java?rev=683514&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/IndexedNegationSearchIT.java
(added)
+++ directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/IndexedNegationSearchIT.java
Wed Aug  6 22:44:09 2008
@@ -0,0 +1,325 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.operations.search;
+
+
+import org.apache.directory.server.core.DefaultDirectoryService;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.integ.IntegrationUtils;
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.server.core.integ.annotations.Factory;
+import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
+import org.apache.directory.server.integ.LdapServerFactory;
+import org.apache.directory.server.integ.SiRunner;
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
+
+import org.apache.directory.server.newldap.LdapServer;
+import org.apache.directory.server.newldap.handlers.bind.MechanismHandler;
+import org.apache.directory.server.newldap.handlers.bind.SimpleMechanismHandler;
+import org.apache.directory.server.newldap.handlers.bind.cramMD5.CramMd5MechanismHandler;
+import org.apache.directory.server.newldap.handlers.bind.digestMD5.DigestMd5MechanismHandler;
+import org.apache.directory.server.newldap.handlers.bind.gssapi.GssapiMechanismHandler;
+import org.apache.directory.server.newldap.handlers.bind.ntlm.NtlmMechanismHandler;
+import org.apache.directory.server.newldap.handlers.extended.StartTlsHandler;
+import org.apache.directory.server.newldap.handlers.extended.StoredProcedureExtendedOperationHandler;
+import org.apache.directory.server.protocol.shared.SocketAcceptor;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.DateUtils;
+import org.apache.mina.util.AvailablePortFinder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+
+/**
+ * A set of tests to make sure the negation operator is working 
+ * properly when included in search filters on indexed attributes.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@RunWith ( SiRunner.class ) 
+@CleanupLevel ( Level.SUITE )
+@Factory ( IndexedNegationSearchIT.Factory.class )
+@ApplyLdifs( {
+    "dn: ou=test,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: organizationalUnit\n" +
+    "ou: test\n\n" +
+
+    "dn: uid=test1,ou=test,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: account\n" +
+    "uid: test1\n" +
+    "ou: test1\n\n" +
+
+    "dn: uid=test2,ou=test,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: account\n" +
+    "uid: test2\n" +
+    "ou: test2\n\n" +
+
+    "dn: uid=testNoOU,ou=test,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: account\n" +
+    "uid: testNoOU\n\n" +
+    
+    "dn: ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: organizationalUnit\n" +
+    "ou: actors\n\n" +
+
+    "dn: uid=jblack,ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: person\n" +
+    "objectClass: organizationalPerson\n" +
+    "objectClass: uidObject\n" +
+    "uid: jblack\n" +
+    "ou: comedy\n" +
+    "ou: adventure\n" +
+    "cn: Jack Black\n" +
+    "sn: Black\n\n" +
+
+    "dn: uid=bpitt,ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: person\n" +
+    "objectClass: organizationalPerson\n" +
+    "objectClass: uidObject\n" +
+    "uid: bpitt\n" +
+    "ou: drama\n" +
+    "ou: adventure\n" +
+    "cn: Brad Pitt\n" +
+    "sn: Pitt\n\n" +
+
+    "dn: uid=gcloony,ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: person\n" +
+    "objectClass: organizationalPerson\n" +
+    "objectClass: uidObject\n" +
+    "uid: gcloony\n" +
+    "ou: drama\n" +
+    "cn: Goerge Cloony\n" +
+    "sn: Cloony\n\n" +
+
+    "dn: uid=jnewbie,ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: person\n" +
+    "objectClass: organizationalPerson\n" +
+    "objectClass: uidObject\n" +
+    "uid: jnewbie\n" +
+    "cn: Joe Newbie\n" +
+    "sn: Newbie\n\n" 
+
+    }
+)
+public class IndexedNegationSearchIT 
+{
+    public static LdapServer ldapServer;
+
+    
+    public static class Factory implements LdapServerFactory
+    {
+        public LdapServer newInstance() throws Exception
+        {
+            DirectoryService service = new DefaultDirectoryService();
+            IntegrationUtils.doDelete( service.getWorkingDirectory() );
+            service.getChangeLog().setEnabled( true );
+            service.setShutdownHookEnabled( false );
+
+            JdbmPartition system = new JdbmPartition();
+            system.setId( "system" );
+
+            // @TODO need to make this configurable for the system partition
+            system.setCacheSize( 500 );
+
+            system.setSuffix( "ou=system" );
+
+            // Add indexed attributes for system partition
+            Set<Index<?,ServerEntry>> indexedAttrs = new HashSet<Index<?,ServerEntry>>();
+            indexedAttrs.add( new JdbmIndex<String,ServerEntry>( SchemaConstants.OBJECT_CLASS_AT
) );
+            indexedAttrs.add( new JdbmIndex<String,ServerEntry>( SchemaConstants.OU_AT
) );
+            system.setIndexedAttributes( indexedAttrs );
+
+            // Add context entry for system partition
+            LdapDN systemDn = new LdapDN( "ou=system" );
+            ServerEntry systemEntry = new DefaultServerEntry( service.getRegistries(), systemDn
);
+            systemEntry.put( "objectClass", "top", "organizationalUnit", "extensibleObject",
"account" ); 
+            systemEntry.put( SchemaConstants.CREATORS_NAME_AT, "uid=admin, ou=system" );
+            systemEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime()
);
+            systemEntry.put( "ou", "system" );
+            systemEntry.put( "uid", "testUid" );
+            system.setContextEntry( systemEntry );
+            service.setSystemPartition( system );
+
+            // change the working directory to something that is unique
+            // on the system and somewhere either under target directory
+            // or somewhere in a temp area of the machine.
+
+            LdapServer ldapServer = new LdapServer();
+            ldapServer.setDirectoryService( service );
+            ldapServer.setSocketAcceptor( new SocketAcceptor( null ) );
+            ldapServer.setIpPort( AvailablePortFinder.getNextAvailable( 1024 ) );
+            ldapServer.addExtendedOperationHandler( new StartTlsHandler() );
+            ldapServer.addExtendedOperationHandler( new StoredProcedureExtendedOperationHandler()
);
+
+            // Setup SASL Mechanisms
+            
+            Map<String, MechanismHandler> mechanismHandlerMap = new HashMap<String,MechanismHandler>();
+            mechanismHandlerMap.put( SupportedSaslMechanisms.PLAIN, new SimpleMechanismHandler()
);
+
+            CramMd5MechanismHandler cramMd5MechanismHandler = new CramMd5MechanismHandler();
+            mechanismHandlerMap.put( SupportedSaslMechanisms.CRAM_MD5, cramMd5MechanismHandler
);
+
+            DigestMd5MechanismHandler digestMd5MechanismHandler = new DigestMd5MechanismHandler();
+            mechanismHandlerMap.put( SupportedSaslMechanisms.DIGEST_MD5, digestMd5MechanismHandler
);
+
+            GssapiMechanismHandler gssapiMechanismHandler = new GssapiMechanismHandler();
+            mechanismHandlerMap.put( SupportedSaslMechanisms.GSSAPI, gssapiMechanismHandler
);
+
+            NtlmMechanismHandler ntlmMechanismHandler = new NtlmMechanismHandler();
+            mechanismHandlerMap.put( SupportedSaslMechanisms.NTLM, ntlmMechanismHandler );
+            mechanismHandlerMap.put( SupportedSaslMechanisms.GSS_SPNEGO, ntlmMechanismHandler
);
+
+            ldapServer.setSaslMechanismHandlers( mechanismHandlerMap );
+
+            return ldapServer;
+        }
+    }
+    
+
+    /**
+     * Tests to make sure a negated search for OU of "test1" returns
+     * those entries that do not have the OU attribute or do not have
+     * a "test1" value for OU if the attribute exists.
+     */
+    @Test
+    public void testSearchNotOUIndexed() throws Exception
+    {
+        Set<SearchResult> results = getResults( "(!(ou=test1))" );
+        assertFalse( contains( "uid=test1,ou=test,ou=system", results ) );
+        assertTrue( contains( "uid=test2,ou=test,ou=system", results ) );
+        assertTrue( contains( "uid=testNoOU,ou=test,ou=system", results ) );
+    }
+
+    
+    /**
+     * Tests to make sure a negated search for actors without ou
+     * with value 'drama' returns those that do not have the attribute
+     * and do not have a 'drama' value for ou if the attribute still
+     * exists.  This test DOES build an index on ou for the system
+     * partition and should have failed if the bug in DIRSERVER-951
+     * was present and reproducable.
+     */
+    @Test
+    public void testSearchNotDramaIndexed() throws Exception
+    {
+        // jack black has ou but not drama, and joe newbie has no ou what so ever
+        Set<SearchResult> results = getActorResults( "(!(ou=drama))" );
+        assertTrue( contains( "uid=jblack,ou=actors,ou=system", results ) );
+        assertTrue( contains( "uid=jnewbie,ou=actors,ou=system", results ) );
+        assertEquals( 2, results.size() );
+    }
+
+    
+    boolean contains( String dn, Set<SearchResult> results )
+    {
+        for ( SearchResult result : results )
+        {
+            if ( result.getNameInNamespace().equals( dn ) )
+            {
+                return true;
+            }
+        }
+        
+        return false;
+    }
+    
+    
+    /**
+     * Tests to make sure a negated search for actors without ou
+     * with value 'drama' returns those that do not have the attribute
+     * and do not have a 'drama' value for ou if the attribute still
+     * exists.  This test DOES build an index on ou for the system
+     * partition and should have failed if the bug in DIRSERVER-951
+     * was present and reproducable.
+     */
+    @Test
+    public void testSearchNotDramaNotNewbieIndexed() throws Exception
+    {
+        // jack black has ou but not drama, and joe newbie has no ou what so ever
+        Set<SearchResult> results = getActorResults( "(& (!(uid=jnewbie)) (!(ou=drama))
)" );
+        assertTrue( contains( "uid=jblack,ou=actors,ou=system", results ) );
+        assertFalse( contains( "uid=jnewbie,ou=actors,ou=system", results ) );
+        assertEquals( 1, results.size() );
+    }
+
+    
+    Set<SearchResult> getActorResults( String filter ) throws Exception
+    {
+        DirContext ctx = getWiredContext( ldapServer );
+        Set<SearchResult> results = new HashSet<SearchResult>();
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        NamingEnumeration<SearchResult> namingEnumeration = ctx.search( "ou=actors,ou=system",
filter, controls );
+        while( namingEnumeration.hasMore() )
+        {
+            results.add( namingEnumeration.next() );
+        }
+        
+        return results;
+    }
+
+    
+    Set<SearchResult> getResults( String filter ) throws Exception
+    {
+        DirContext ctx = getWiredContext( ldapServer );
+        Set<SearchResult> results = new HashSet<SearchResult>();
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        NamingEnumeration<SearchResult> namingEnumeration = ctx.search( "ou=system",
filter, controls );
+        while( namingEnumeration.hasMore() )
+        {
+            results.add( namingEnumeration.next() );
+        }
+        
+        return results;
+    }
+}

Added: directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/NegationSearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/NegationSearchIT.java?rev=683514&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/NegationSearchIT.java
(added)
+++ directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/NegationSearchIT.java
Wed Aug  6 22:44:09 2008
@@ -0,0 +1,178 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.operations.search;
+
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.server.core.integ.annotations.Factory;
+import org.apache.directory.server.integ.SiRunner;
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
+
+import org.apache.directory.server.newldap.LdapServer;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.directory.DirContext;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+
+/**
+ * A set of tests to make sure the negation operator is working 
+ * properly when included in search filters. Created in response
+ * to JIRA issue 
+ * <a href="https://issues.apache.org/jira/browse/DIRSERVER-951">DIRSERVER-951</a>.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 519077 $
+ */
+@RunWith ( SiRunner.class ) 
+@CleanupLevel ( Level.SUITE )
+@Factory ( IndexedNegationSearchIT.Factory.class )
+@ApplyLdifs( {
+    "dn: ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: organizationalUnit\n" +
+    "ou: actors\n\n" +
+
+    "dn: uid=jblack,ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: person\n" +
+    "objectClass: organizationalPerson\n" +
+    "objectClass: uidObject\n" +
+    "uid: jblack\n" +
+    "ou: comedy\n" +
+    "ou: adventure\n" +
+    "cn: Jack Black\n" +
+    "sn: Black\n\n" +
+
+    "dn: uid=bpitt,ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: person\n" +
+    "objectClass: organizationalPerson\n" +
+    "objectClass: uidObject\n" +
+    "uid: bpitt\n" +
+    "ou: drama\n" +
+    "ou: adventure\n" +
+    "cn: Brad Pitt\n" +
+    "sn: Pitt\n\n" +
+
+    "dn: uid=gcloony,ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: person\n" +
+    "objectClass: organizationalPerson\n" +
+    "objectClass: uidObject\n" +
+    "uid: gcloony\n" +
+    "ou: drama\n" +
+    "cn: Goerge Cloony\n" +
+    "sn: Cloony\n\n" +
+
+    "dn: uid=jnewbie,ou=actors,ou=system\n" +
+    "objectClass: top\n" +
+    "objectClass: person\n" +
+    "objectClass: organizationalPerson\n" +
+    "objectClass: uidObject\n" +
+    "uid: jnewbie\n" +
+    "cn: Joe Newbie\n" +
+    "sn: Newbie\n\n" 
+
+    }
+)
+public class NegationSearchIT 
+{
+    public static LdapServer ldapServer;
+
+    
+    /**
+     * Tests to make sure a negated search for actors without ou
+     * with value 'drama' returns those that do not have the attribute
+     * and do not have a 'drama' value for ou if the attribute still
+     * exists.  This test does not build an index on ou for the system
+     * partition.
+     */
+    @Test
+    public void testSearchNotDrama() throws Exception
+    {
+        // jack black has ou but not drama, and joe newbie has no ou what so ever
+        Set<SearchResult> results = getResults( "(!(ou=drama))" );
+        assertTrue( contains( "uid=jblack,ou=actors,ou=system", results ) );
+        assertTrue( contains( "uid=jnewbie,ou=actors,ou=system", results ) );
+        assertEquals( 2, results.size() );
+    }
+
+    
+    /**
+     * Tests to make sure a negated search for actors without ou
+     * with value 'drama' returns those that do not have the attribute
+     * and do not have a 'drama' value for ou if the attribute still
+     * exists.  This test does not build an index on ou for the system
+     * partition.
+     */
+    @Test
+    public void testSearchNotDramaNotNewbie() throws Exception
+    {
+        // jack black has ou but not drama, and joe newbie has no ou what so ever
+        Set<SearchResult> results = getResults( "(& (!(uid=jnewbie)) (!(ou=drama))
)" );
+        assertTrue( contains( "uid=jblack,ou=actors,ou=system", results ) );
+        assertFalse( contains( "uid=jnewbie,ou=actors,ou=system", results ) );
+        assertEquals( 1, results.size() );
+    }
+
+    
+    boolean contains( String dn, Set<SearchResult> results )
+    {
+        for ( SearchResult result : results )
+        {
+            if ( result.getNameInNamespace().equals( dn ) )
+            {
+                return true;
+            }
+        }
+        
+        return false;
+    }
+    
+    
+    Set<SearchResult> getResults( String filter ) throws Exception
+    {
+        DirContext ctx = getWiredContext( ldapServer );
+        Set<SearchResult> results = new HashSet<SearchResult>();
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        NamingEnumeration<SearchResult> namingEnumeration = ctx.search( "ou=actors,ou=system",
filter, controls );
+        while( namingEnumeration.hasMore() )
+        {
+            results.add( namingEnumeration.next() );
+        }
+        
+        return results;
+    }
+}

Copied: directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/PersistentSearchTest.java
(from r683480, directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/PersistentSearchTest.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/PersistentSearchTest.java?p2=directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/PersistentSearchTest.java&p1=directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/PersistentSearchTest.java&r1=683480&r2=683514&rev=683514&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/PersistentSearchTest.java
(original)
+++ directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/PersistentSearchTest.java
Wed Aug  6 22:44:09 2008
@@ -17,18 +17,16 @@
  *  under the License. 
  *  
  */
-package org.apache.directory.server;
+package org.apache.directory.server.operations.search;
 
 
 import java.util.ArrayList;
 import java.util.EventObject;
-import java.util.Hashtable;
 
 import javax.naming.NamingEnumeration;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
 import javax.naming.directory.SearchResult;
 import javax.naming.event.EventContext;
 import javax.naming.event.EventDirContext;
@@ -38,10 +36,14 @@
 import javax.naming.event.ObjectChangeListener;
 import javax.naming.ldap.Control;
 import javax.naming.ldap.HasControls;
-import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
 
-import org.apache.directory.server.unit.AbstractServerTest;
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.server.integ.SiRunner;
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
+import org.apache.directory.server.newldap.LdapServer;
 import org.apache.directory.shared.ldap.codec.search.controls.ChangeType;
 import org.apache.directory.shared.ldap.codec.search.controls.EntryChangeControlCodec;
 import org.apache.directory.shared.ldap.codec.search.controls.EntryChangeControlDecoder;
@@ -49,28 +51,41 @@
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.message.PersistentSearchControl;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 
 /**
- * Testcase which tests the correct operation of the persistent search control.
+ * TODO - enable me - not executed (not in suite yet)
+ * Test case which tests the correct operation of the persistent search control.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class PersistentSearchTest extends AbstractServerTest
+@RunWith ( SiRunner.class ) 
+@CleanupLevel ( Level.SUITE )
+@ApplyLdifs( {
+    // Entry # 2
+    "dn: cn=Tori Amos,ou=system\n" +
+    "objectClass: person\n" +
+    "objectClass: top\n" +
+    "cn: Tori Amos\n" +
+    "description: an American singer-songwriter\n" +
+    "sn: Amos\n\n"
+    }
+)
+public class PersistentSearchTest
 {
-    public static final Logger log = LoggerFactory.getLogger( PersistentSearchTest.class
);
-    public static final String PERSON_DESCRIPTION = "an American singer-songwriter";
-    public static final String RDN = "cn=Tori Amos";
-    private LdapContext ctx = null;
+    private static final String BASE = "ou=system";
+    private static final String PERSON_DESCRIPTION = "an American singer-songwriter";
+    private static final String RDN = "cn=Tori Amos";
 
+    public static LdapServer ldapServer;
+    
 
     /**
      * Creation of required attributes of a person entry.
@@ -88,57 +103,14 @@
         return attributes;
     }
 
-
-    /**
-     * Create context and a person entry.
-     */
-    @Before
-    public void setUp() throws Exception
-    {
-        super.setUp();
-
-        Hashtable<String, Object> env = new Hashtable<String, Object>();
-        env.put( "java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory" );
-        env.put( "java.naming.provider.url", "ldap://localhost:" + port + "/ou=system" );
-        env.put( "java.naming.security.principal", "uid=admin,ou=system" );
-        env.put( "java.naming.security.credentials", "secret" );
-        env.put( "java.naming.security.authentication", "simple" );
-
-        ctx = new InitialLdapContext( env, null );
-        assertNotNull( ctx );
-
-        // Create a person with description
-        Attributes attributes = this.getPersonAttributes( "Amos", "Tori Amos" );
-        attributes.put( "description", PERSON_DESCRIPTION );
-        ctx.createSubcontext( RDN, attributes );
-    }
-
-
-    /**
-     * Remove person entry and close context.
-     */
-    @After
-    public void tearDown() throws Exception
-    {
-        try
-        {
-            ctx.unbind( RDN );
-            ctx.close();
-            ctx = null;
-            super.tearDown();
-        }
-        catch ( Throwable t )
-        {
-        }
-    }
-
-
+    
     /**
      * Shows correct notifications for modify(4) changes.
      */
     @Test
     public void testPsearchModify() throws Exception
     {
+        EventDirContext ctx = ( EventDirContext ) getWiredContext( ldapServer).lookup( BASE
);
         PSearchListener listener = new PSearchListener();
         Thread t = new Thread( listener, "PSearchListener" );
         t.start();
@@ -174,6 +146,7 @@
     @Test
     public void testPsearchModifyDn() throws Exception
     {
+        DirContext ctx = ( DirContext ) getWiredContext( ldapServer).lookup( BASE );
         PSearchListener listener = new PSearchListener();
         Thread t = new Thread( listener );
         t.start();
@@ -207,6 +180,7 @@
     @Test
     public void testPsearchDelete() throws Exception
     {
+        DirContext ctx = ( DirContext ) getWiredContext( ldapServer).lookup( BASE );
         PSearchListener listener = new PSearchListener();
         Thread t = new Thread( listener );
         t.start();
@@ -240,6 +214,7 @@
     @Test
     public void testPsearchAdd() throws Exception
     {
+        DirContext ctx = ( DirContext ) getWiredContext( ldapServer).lookup( BASE );
         PSearchListener listener = new PSearchListener();
         Thread t = new Thread( listener );
         t.start();
@@ -274,6 +249,7 @@
     @Test
     public void testPsearchModifyWithEC() throws Exception
     {
+        DirContext ctx = ( DirContext ) getWiredContext( ldapServer).lookup( BASE );
         PersistentSearchControl control = new PersistentSearchControl();
         control.setReturnECs( true );
         PSearchListener listener = new PSearchListener( control );
@@ -311,6 +287,7 @@
     @Test
     public void testPsearchModifyDnWithEC() throws Exception
     {
+        DirContext ctx = ( DirContext ) getWiredContext( ldapServer).lookup( BASE );
         PersistentSearchControl control = new PersistentSearchControl();
         control.setReturnECs( true );
         PSearchListener listener = new PSearchListener( control );
@@ -349,6 +326,7 @@
     @Test
     public void testPsearchDeleteWithEC() throws Exception
     {
+        DirContext ctx = ( DirContext ) getWiredContext( ldapServer).lookup( BASE );
         PersistentSearchControl control = new PersistentSearchControl();
         control.setReturnECs( true );
         PSearchListener listener = new PSearchListener( control );
@@ -386,6 +364,7 @@
     @Test
     public void testPsearchAddWithEC() throws Exception
     {
+        DirContext ctx = ( DirContext ) getWiredContext( ldapServer).lookup( BASE );
         PersistentSearchControl control = new PersistentSearchControl();
         control.setReturnECs( true );
         PSearchListener listener = new PSearchListener( control );
@@ -423,6 +402,7 @@
     @Test
     public void testPsearchAddModifyEnabledWithEC() throws Exception
     {
+        DirContext ctx = ( DirContext ) getWiredContext( ldapServer).lookup( BASE );
         PersistentSearchControl control = new PersistentSearchControl();
         control.setReturnECs( true );
         control.setChangeTypes( ChangeType.ADD_VALUE );
@@ -536,16 +516,9 @@
     @Test
     public void testPsearchUsingJndiNotifications() throws Exception
     {
-        Hashtable<String, Object> env = new Hashtable<String, Object>();
-        env.put( "java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory" );
-        env.put( "java.naming.provider.url", "ldap://localhost:" + port + "/ou=system" );
-        env.put( "java.naming.security.principal", "uid=admin,ou=system" );
-        env.put( "java.naming.security.credentials", "secret" );
-        env.put( "java.naming.security.authentication", "simple" );
-
+        DirContext ctx = ( DirContext ) getWiredContext( ldapServer).lookup( BASE );
         JndiNotificationListener listener = new JndiNotificationListener();
-        InitialDirContext idc = new InitialDirContext( env );
-        EventDirContext edc = ( EventDirContext ) ( idc.lookup( "" ) );
+        EventDirContext edc = ( EventDirContext ) getWiredContext( ldapServer).lookup( BASE
);
         edc.addNamingListener( "", EventContext.ONELEVEL_SCOPE, listener );
 
         while ( listener.list.isEmpty() )
@@ -649,7 +622,7 @@
     class JndiNotificationListener implements NamespaceChangeListener, ObjectChangeListener
     {
         boolean hasError = false;
-        ArrayList<EventObject> list = new ArrayList();
+        ArrayList<EventObject> list = new ArrayList<EventObject>();
         NamingExceptionEvent exceptionEvent = null;
 
         public void objectAdded( NamingEvent evt )
@@ -706,13 +679,14 @@
 
         public void run()
         {
-            NamingEnumeration list = null;
+            NamingEnumeration<SearchResult> list = null;
             control.setCritical( true );
             Control[] ctxCtls = new Control[]
                 { control };
 
             try
             {
+                LdapContext ctx = ( LdapContext ) getWiredContext( ldapServer).lookup( BASE
);
                 ctx.setRequestControls( ctxCtls );
                 isReady = true;
                 list = ctx.search( "", "objectClass=*", null );
@@ -721,7 +695,7 @@
                 while ( list.hasMore() )
                 {
                     Control[] controls = null;
-                    SearchResult sresult = ( SearchResult ) list.next();
+                    SearchResult sresult = list.next();
                     count++;
                     if ( sresult instanceof HasControls )
                     {

Added: directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/SchemaSearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/SchemaSearchIT.java?rev=683514&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/SchemaSearchIT.java
(added)
+++ directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/search/SchemaSearchIT.java
Wed Aug  6 22:44:09 2008
@@ -0,0 +1,291 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.operations.search;
+
+
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.server.integ.SiRunner;
+import org.apache.directory.server.newldap.LdapServer;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
+
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+
+/**
+ * Test case with different search operations on the cn=schema entry. 
+ * Created to demonstrate DIRSERVER-1055
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 569048 $
+ */
+@RunWith ( SiRunner.class ) 
+@CleanupLevel ( Level.SUITE )
+@ApplyLdifs( {
+    
+    // Bogus AD schema (not real)
+    
+    "dn: cn=active-directory, ou=schema\n" +
+    "objectclass: metaSchema\n" +
+    "objectclass: top\n" +
+    "cn: active-directory\n" +
+    "m-dependencies: core\n\n" +
+    
+    "dn: ou=attributeTypes, cn=active-directory, ou=schema\n" +
+    "objectclass: organizationalUnit\n" +
+    "objectclass: top\n" +
+    "ou: attributeTypes\n\n" +
+    
+    "dn: m-oid=1.1, ou=attributeTypes, cn=active-directory, ou=schema\n" +
+    "objectclass: metaAttributeType\n" +
+    "objectclass: metaTop\n" +
+    "objectclass: top\n" +
+    "m-oid: 1.1\n" +
+    "m-name: sAMAccountName\n" +
+    "m-syntax: 1.3.6.1.4.1.1466.115.121.1.15\n\n" +
+    
+    "dn: m-oid=1.2, ou=attributeTypes, cn=active-directory, ou=schema\n" +
+    "objectclass: metaAttributeType\n" +
+    "objectclass: metaTop\n" +
+    "objectclass: top\n" +
+    "m-oid: 1.2\n" +
+    "m-name: pwdLastSet\n" +
+    "m-equality: integerMatch\n" +
+    "m-ordering: integerMatch\n" +
+    "m-syntax: 1.3.6.1.4.1.1466.115.121.1.27\n\n" +
+
+    "dn: m-oid=1.4, ou=attributeTypes, cn=active-directory, ou=schema\n" +
+    "objectclass: metaAttributeType\n" +
+    "objectclass: metaTop\n" +
+    "objectclass: top\n" +
+    "m-oid: 1.4\n" +
+    "m-name: useraccountcontrol\n" +
+    "m-syntax: 1.3.6.1.4.1.1466.115.121.1.27\n\n" +
+
+    "dn: m-oid=1.5, ou=attributeTypes, cn=active-directory, ou=schema\n" +
+    "objectclass: metaAttributeType\n" +
+    "objectclass: metaTop\n" +
+    "objectclass: top\n" +
+    "m-oid: 1.5\n" +
+    "m-name: SourceAD\n" +
+    "m-syntax: 1.3.6.1.4.1.1466.115.121.1.15\n" +
+    "m-length: 0\n\n" +
+
+    "dn: ou=comparators, cn=active-directory, ou=schema\n" +
+    "objectclass: organizationalUnit\n" +
+    "objectclass: top\n" +
+    "ou: comparators\n\n" +
+
+    "dn: ou=ditContentRules, cn=active-directory, ou=schema\n" +
+    "objectclass: organizationalUnit\n" +
+    "objectclass: top\n" +
+    "ou: ditContentRules\n\n" +
+
+    "dn: ou=ditStructureRules, cn=active-directory, ou=schema\n" +
+    "objectclass: organizationalUnit\n" +
+    "objectclass: top\n" +
+    "ou: ditStructureRules\n\n" +
+
+    "dn: ou=matchingRules, cn=active-directory, ou=schema\n" +
+    "objectclass: organizationalUnit\n" +
+    "objectclass: top\n" +
+    "ou: matchingRules\n\n" +
+    
+    "dn: ou=nameForms, cn=active-directory, ou=schema\n" +
+    "objectclass: organizationalUnit\n" +
+    "objectclass: top\n" +
+    "ou: nameForms\n\n" +
+
+    "dn: ou=normalizers, cn=active-directory, ou=schema\n" +
+    "objectclass: organizationalUnit\n" +
+    "objectclass: top\n" +
+    "ou: normalizers\n\n" +
+
+    "dn: ou=objectClasses, cn=active-directory, ou=schema\n" +
+    "objectclass: organizationalUnit\n" +
+    "objectclass: top\n" +
+    "ou: objectClasses\n\n" +
+
+    "dn: m-oid=1.3, ou=objectClasses, cn=active-directory, ou=schema\n" +
+    "objectclass: metaObjectClass\n" +
+    "objectclass: metaTop\n" +
+    "objectclass: top\n" +
+    "m-oid: 1.3\n" +
+    "m-name: personActiveDirectory\n" +
+    "m-supObjectClass: person\n" +
+    "m-must: pwdLastSet\n" +
+    "m-must: sAMAccountName\n" +
+    "m-must: useraccountcontrol\n" +
+    "m-must: SourceAD\n\n" +
+
+    "dn: ou=syntaxCheckers, cn=active-directory, ou=schema\n" +
+    "objectclass: organizationalUnit\n" +
+    "objectclass: top\n" +
+    "ou: syntaxCheckers\n\n" +
+
+    "dn: ou=syntaxes, cn=active-directory, ou=schema\n" +
+    "objectclass: organizationalUnit\n" +
+    "objectclass: top\n" +
+    "ou: syntaxes\n\n"
+    }
+)
+public class SchemaSearchIT 
+{
+    private static final String DN = "cn=schema";
+    private static final String FILTER = "(objectclass=subschema)";
+
+    
+    public static LdapServer ldapServer;
+    
+
+    protected void checkForAttributes( Attributes attrs, String[] attrNames )
+    {
+        for ( int i = 0; i < attrNames.length; i++ )
+        {
+            String attrName = attrNames[i];
+
+            assertNotNull( "Check if attr " + attrName + " is present", attrs.get( attrNames[i]
) );
+        }
+    }
+
+
+    /**
+     * Check if modifyTimestamp and createTimestamp are present in the search result,
+     * if they are requested.
+     */
+    @Test
+    public void testRequestOperationalAttributes() throws Exception
+    {
+        DirContext ctx = getWiredContext( ldapServer );
+        SearchControls ctls = new SearchControls();
+
+        String[] attrNames =
+            { "creatorsName", "createTimestamp", "modifiersName", "modifyTimestamp" };
+
+        ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
+        ctls.setReturningAttributes( attrNames );
+
+        NamingEnumeration<SearchResult> result = ctx.search( DN, FILTER, ctls );
+
+        if ( result.hasMore() )
+        {
+            SearchResult entry = result.next();
+            checkForAttributes( entry.getAttributes(), attrNames );
+        }
+        else
+        {
+            fail( "entry " + DN + " not found" );
+        }
+
+        result.close();
+    }
+
+
+    /**
+     * Check if modifyTimestamp and createTimestamp are present in the search result,
+     * if + is requested.
+     */
+    @Test
+    public void testRequestAllOperationalAttributes() throws Exception
+    {
+        DirContext ctx = getWiredContext( ldapServer );
+        SearchControls ctls = new SearchControls();
+
+        ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
+        ctls.setReturningAttributes( new String[]
+            { "+" } );
+
+        NamingEnumeration<SearchResult> result = ctx.search( DN, FILTER, ctls );
+
+        if ( result.hasMore() )
+        {
+            SearchResult entry = result.next();
+            String[] attrNames =
+                { "creatorsName", "createTimestamp", "modifiersName", "modifyTimestamp" };
+            checkForAttributes( entry.getAttributes(), attrNames );
+        }
+        else
+        {
+            fail( "entry " + DN + " not found" );
+        }
+
+        result.close();
+    }
+
+    
+    /**
+     * Test case for DIRSERVER-1083: Search on an custom attribute added to 
+     * the dynamic schema fails when no result is found. 
+     */
+    @Test
+    public void testSearchingNewSchemaElements() throws Exception
+    {
+        DirContext ctx = getWiredContext( ldapServer );
+        
+        // create an entry with the schema objectClass personActiveDirectory
+        AttributesImpl person = new AttributesImpl( "objectClass", "top", true );
+        person.get( "objectClass" ).add( "person" );
+        person.get( "objectClass" ).add( "personActiveDirectory" );
+        person.put( "cn", "foobar" );
+        person.put( "sn", "bar" );
+        person.put( "pwdLastSet", "3" );
+        person.put( "SourceAD", "blah" );
+        person.put( "useraccountcontrol", "7" );
+        person.put( "sAMAccountName", "foobar" );
+        ctx.createSubcontext( "cn=foobar,ou=system", person );
+        
+        // Confirm creation with a lookup
+        Attributes read = ctx.getAttributes( "cn=foobar,ou=system" );
+        assertNotNull( read );
+        assertEquals( "3", read.get( "pwdLastSet" ).get() );
+        
+        // Now search for foobar with pwdLastSet value of 3
+        SearchControls searchControls = new SearchControls();
+        searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        NamingEnumeration<SearchResult> results = ctx.search( "ou=system", "(pwdLastSet=3)",
searchControls );
+        assertTrue( results.hasMore() );
+        SearchResult result = results.next();
+        assertNotNull( result );
+        assertEquals( "cn=foobar", result.getName() );
+        Attributes attributes = result.getAttributes();
+        assertEquals( "3", attributes.get( "pwdLastSet" ).get() );
+        results.close();
+        
+        // Now search with bogus value for pwdLastSet
+        results = ctx.search( "ou=system", "(pwdLastSet=300)", searchControls );
+        assertFalse( results.hasMore() );
+        results.close();
+    }
+}



Mime
View raw message