You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/02/23 10:02:27 UTC

svn commit: r915249 - /directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientSearchRequestTest.java

Author: kayyagari
Date: Tue Feb 23 09:02:27 2010
New Revision: 915249

URL: http://svn.apache.org/viewvc?rev=915249&view=rev
Log:
test case for search operation

Added:
    directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientSearchRequestTest.java

Added: directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientSearchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientSearchRequestTest.java?rev=915249&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientSearchRequestTest.java (added)
+++ directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientSearchRequestTest.java Tue Feb 23 09:02:27 2010
@@ -0,0 +1,131 @@
+/*
+ *   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.shared.client.api.operations;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.future.SearchFuture;
+import org.apache.directory.ldap.client.api.message.SearchResponse;
+import org.apache.directory.ldap.client.api.message.SearchResultDone;
+import org.apache.directory.server.annotations.CreateLdapServer;
+import org.apache.directory.server.annotations.CreateTransport;
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TODO ClientSearchRequestTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@RunWith(FrameworkRunner.class)
+@CreateLdapServer(transports =
+    { @CreateTransport(protocol = "LDAP"), @CreateTransport(protocol = "LDAPS") })
+public class ClientSearchRequestTest extends AbstractLdapTestUnit
+{
+    private LdapConnection connection;
+    private CoreSession session;
+
+
+    @Before
+    public void setup() throws Exception
+    {
+        connection = new LdapConnection( "localhost", ldapServer.getPort() );
+        LdapDN bindDn = new LdapDN( "uid=admin,ou=system" );
+        connection.bind( bindDn.getName(), "secret" );
+
+        session = ldapServer.getDirectoryService().getSession();
+    }
+
+
+    /**
+     * Close the LdapConnection
+     */
+    @After
+    public void shutdown()
+    {
+        try
+        {
+            if ( connection != null )
+            {
+                connection.close();
+            }
+        }
+        catch ( Exception ioe )
+        {
+            fail();
+        }
+    }
+
+
+    @Test
+    public void testSearch() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "ou=system", "(objectclass=*)", SearchScope.SUBTREE, "*",
+            "+" );
+        int count = 0;
+        while ( cursor.next() )
+        {
+            assertNotNull( cursor.get() );
+            count++;
+        }
+
+        assertEquals( 10, count );
+    }
+    
+
+    @Test
+    public void testAsyncSearch() throws Exception
+    {
+        SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*)", SearchScope.SUBTREE, "*",
+            "+" );
+        int count = 0;
+        SearchResponse searchResponse = null;
+        do
+        {
+            searchResponse = ( SearchResponse ) searchFuture.get( 1000, TimeUnit.MILLISECONDS );
+            assertNotNull( searchResponse );
+            if( !( searchResponse instanceof SearchResultDone ) )
+            {
+                count++;
+            }
+        }
+        while ( !( searchResponse instanceof SearchResultDone ) );
+
+        assertEquals( 10, count );
+    }
+
+}