You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2009/05/05 23:52:42 UTC
svn commit: r771982 - in
/directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api:
BindRequestTest.java LdapConnectionTest.java SearchRequestTest.java
getRootDSETest.java
Author: elecharny
Date: Tue May 5 21:52:42 2009
New Revision: 771982
URL: http://svn.apache.org/viewvc?rev=771982&view=rev
Log:
o Split tests into many classes : one per operation
o Added some test class for getRootDSE()
o Improved the existing tests
Added:
directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/SearchRequestTest.java
directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/getRootDSETest.java
Modified:
directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/BindRequestTest.java
directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
Modified: directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/BindRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/BindRequestTest.java?rev=771982&r1=771981&r2=771982&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/BindRequestTest.java (original)
+++ directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/BindRequestTest.java Tue May 5 21:52:42 2009
@@ -20,6 +20,7 @@
package org.apache.directory.shared.client.api;
import java.io.IOException;
+import java.util.concurrent.ExecutionException;
import org.apache.directory.server.core.integ.Level;
import org.apache.directory.server.core.integ.annotations.CleanupLevel;
@@ -32,6 +33,7 @@
import org.apache.directory.shared.ldap.client.api.messages.BindRequestImpl;
import org.apache.directory.shared.ldap.client.api.messages.BindResponse;
import org.apache.directory.shared.ldap.client.api.messages.LdapResult;
+import org.apache.directory.shared.ldap.client.api.messages.future.BindFuture;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.util.StringTools;
import org.junit.Before;
@@ -42,7 +44,6 @@
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
/**
* Test the BindRequest client api
@@ -57,12 +58,12 @@
/** The server instance */
public static LdapService ldapService;
- private static boolean responseReceived = false;
+ private static BindResponse staticBindResponse = null;
@Before
public void init()
{
- responseReceived = false;
+ staticBindResponse = null;
}
//------------------------------------------------------------------------
@@ -84,7 +85,7 @@
assertNotNull( bindResponse );
- assertEquals( 0, bindResponse.getMessageId() );
+ assertEquals( 1, bindResponse.getMessageId() );
assertNotNull( bindResponse.getControls() );
assertEquals( 0, bindResponse.getControls().values().size() );
@@ -130,10 +131,9 @@
{
BindResponse bindResponse = connection.bind();
-
assertNotNull( bindResponse );
- assertEquals( 0, bindResponse.getMessageId() );
+ assertEquals( 1, bindResponse.getMessageId() );
assertNotNull( bindResponse.getControls() );
assertEquals( 0, bindResponse.getControls().values().size() );
@@ -185,19 +185,24 @@
bindRequest.setCredentials( "secret" );
bindRequest.setName( "uid=admin,ou=system" );
- connection.bind( bindRequest, new BindListener()
+ BindFuture bindFuture = connection.bind( bindRequest, new BindListener()
{
public void bindCompleted( LdapConnection connection, BindResponse bindResponse ) throws LdapException
{
assertNotNull( bindResponse );
- responseReceived = true;
+ staticBindResponse = bindResponse;
}
} );
- // Wait a bit
- Thread.sleep( 1000 );
+ // We should also receive the response from the future.
+ BindResponse bindResponse = bindFuture.get();
+
+ assertNotNull( bindResponse );
+
+ // Wait a bit so that the listener is called.
+ Thread.sleep( 200 );
- assertTrue( responseReceived );
+ assertEquals( bindResponse, staticBindResponse );
connection.unBind();
}
@@ -209,6 +214,10 @@
{
fail();
}
+ catch ( ExecutionException ee )
+ {
+ fail();
+ }
finally
{
try
Modified: directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java?rev=771982&r1=771981&r2=771982&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java (original)
+++ directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java Tue May 5 21:52:42 2009
@@ -41,6 +41,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
/**
* Test the LdapConnection class
@@ -167,9 +168,18 @@
Cursor<SearchResponse> cursor =
connection.search( "uid=admin,ou=system", "(objectClass=*)", SearchScope.SUBTREE, "*" );
- SearchResponse response = cursor.get();
+ assertNotNull( cursor );
+
+ SearchResponse response = null;
+ int count = 0;
+
+ while ( (response = cursor.get() ) != null )
+ {
+ assertNotNull( response );
+ count++;
+ }
- // TODO: check return.
+ assertEquals( 1, count );
connection.unBind();
}
Added: directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/SearchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/SearchRequestTest.java?rev=771982&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/SearchRequestTest.java (added)
+++ directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/SearchRequestTest.java Tue May 5 21:52:42 2009
@@ -0,0 +1,171 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.server.integ.SiRunner;
+import org.apache.directory.server.ldap.LdapService;
+import org.apache.directory.shared.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.client.api.exception.LdapException;
+import org.apache.directory.shared.ldap.client.api.messages.SearchResponse;
+import org.apache.directory.shared.ldap.client.api.messages.SearchResultEntry;
+import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Test the LdapConnection class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@RunWith ( SiRunner.class )
+@CleanupLevel ( Level.CLASS )
+public class SearchRequestTest
+{
+ /** The server instance */
+ public static LdapService ldapService;
+
+
+ //------------------------------------------------------------------------
+ // Synchronous Search
+ //------------------------------------------------------------------------
+ /**
+ * Test a search request on rootDSE
+ */
+ @Test
+ public void testSearchNoArgs()
+ {
+ LdapConnection connection = new LdapConnection( "localhost", ldapService.getPort() );
+
+ try
+ {
+ connection.bind( "uid=admin,ou=system", "secret" );
+
+ SearchResultEntry rootDSE = connection.search();
+
+ assertNotNull( rootDSE );
+
+ assertTrue( rootDSE instanceof SearchResultEntry );
+
+ assertEquals( 2, rootDSE.getMessageId() );
+ Entry entry = rootDSE.getEntry();
+
+ assertNotNull( entry );
+ assertEquals( "", entry.getDn().toString() );
+ assertTrue( entry.contains( "ObjectClass", "top", "extensibleObject" ) );
+ assertFalse( entry.contains( "vendorName", "Apache Software Foundation" ) );
+
+ connection.unBind();
+ }
+ catch ( LdapException le )
+ {
+ le.printStackTrace();
+ fail();
+ }
+ catch ( Exception e )
+ {
+ fail();
+ }
+ finally
+ {
+ try
+ {
+ connection.close();
+ }
+ catch( IOException ioe )
+ {
+ fail();
+ }
+ }
+ }
+
+
+ /**
+ * Test a simple search request
+ */
+ @Test
+ public void testSearchRequest()
+ {
+ LdapConnection connection = new LdapConnection( "localhost", ldapService.getPort() );
+
+ try
+ {
+ connection.bind( "uid=admin,ou=system", "secret" );
+
+ Cursor<SearchResponse> cursor =
+ connection.search( "uid=admin,ou=system", "(objectClass=*)", SearchScope.SUBTREE, "*" );
+
+ assertNotNull( cursor );
+
+ SearchResponse response = null;
+ int count = 0;
+
+ while ( cursor.next() )
+ {
+ response = cursor.get();
+ assertNotNull( response );
+ assertTrue( response instanceof SearchResultEntry );
+ SearchResultEntry searchResultEntry = (SearchResultEntry)response;
+
+ assertEquals( 2, searchResultEntry.getMessageId() );
+ Entry entry = searchResultEntry.getEntry();
+
+ assertNotNull( entry );
+ assertEquals( "uid=admin,ou=system", entry.getDn().toString() );
+ count++;
+ }
+
+ assertEquals( 1, count );
+
+ connection.unBind();
+ }
+ catch ( LdapException le )
+ {
+ fail();
+ }
+ catch ( Exception e )
+ {
+ fail();
+ }
+ finally
+ {
+ try
+ {
+ connection.close();
+ }
+ catch( IOException ioe )
+ {
+ fail();
+ }
+ }
+ }
+}
Added: directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/getRootDSETest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/getRootDSETest.java?rev=771982&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/getRootDSETest.java (added)
+++ directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/getRootDSETest.java Tue May 5 21:52:42 2009
@@ -0,0 +1,217 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.server.integ.SiRunner;
+import org.apache.directory.server.ldap.LdapService;
+import org.apache.directory.shared.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.client.api.exception.LdapException;
+import org.apache.directory.shared.ldap.client.api.messages.SearchResultEntry;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Test the getRootDSE methods.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@RunWith ( SiRunner.class )
+@CleanupLevel ( Level.CLASS )
+public class getRootDSETest
+{
+ /** The server instance */
+ public static LdapService ldapService;
+
+ //------------------------------------------------------------------------
+ // Synchronous getRootDSE()
+ //------------------------------------------------------------------------
+ /**
+ * Test a simple getRootDSE() call.
+ */
+ @Test
+ public void testGetRootDSE()
+ {
+ LdapConnection connection = new LdapConnection( "localhost", ldapService.getPort() );
+
+ try
+ {
+ connection.bind( "uid=admin,ou=system", "secret" );
+
+ SearchResultEntry rootDSE = connection.getRootDSE();
+
+ assertNotNull( rootDSE );
+
+ assertTrue( rootDSE instanceof SearchResultEntry );
+
+ assertEquals( 2, rootDSE.getMessageId() );
+ Entry entry = rootDSE.getEntry();
+
+ assertNotNull( entry );
+ assertEquals( "", entry.getDn().toString() );
+ assertTrue( entry.contains( "ObjectClass", "top", "extensibleObject" ) );
+ assertFalse( entry.contains( "vendorName", "Apache Software Foundation" ) );
+
+ connection.unBind();
+ }
+ catch ( LdapException le )
+ {
+ le.printStackTrace();
+ fail();
+ }
+ catch ( Exception e )
+ {
+ fail();
+ }
+ finally
+ {
+ try
+ {
+ connection.close();
+ }
+ catch( IOException ioe )
+ {
+ fail();
+ }
+ }
+ }
+
+
+ /**
+ * Test a getRootDSE() call where we want all the operational and users attributes .
+ */
+ @Test
+ public void testGetRootDSEAllAttrs()
+ {
+ LdapConnection connection = new LdapConnection( "localhost", ldapService.getPort() );
+
+ try
+ {
+ connection.bind( "uid=admin,ou=system", "secret" );
+
+ SearchResultEntry rootDSE = connection.getRootDSE( "*", "+" );
+
+ assertNotNull( rootDSE );
+
+ assertTrue( rootDSE instanceof SearchResultEntry );
+
+ assertEquals( 2, rootDSE.getMessageId() );
+ Entry entry = rootDSE.getEntry();
+
+ assertNotNull( entry );
+ assertEquals( "", entry.getDn().toString() );
+ assertTrue( entry.contains( "ObjectClass", "top", "extensibleObject" ) );
+ assertTrue( entry.contains( "subschemaSubentry", "cn=schema" ) );
+ assertTrue( entry.contains( "vendorName", "Apache Software Foundation" ) );
+ assertTrue( entry.contains( "supportedLDAPVersion", "3" ) );
+
+ connection.unBind();
+ }
+ catch ( LdapException le )
+ {
+ le.printStackTrace();
+ fail();
+ }
+ catch ( Exception e )
+ {
+ fail();
+ }
+ finally
+ {
+ try
+ {
+ connection.close();
+ }
+ catch( IOException ioe )
+ {
+ fail();
+ }
+ }
+ }
+
+
+ /**
+ * Test a getRootDSE() call where we want all the operational attributes .
+ */
+ @Test
+ public void testGetRootDSEOperAttrs()
+ {
+ LdapConnection connection = new LdapConnection( "localhost", ldapService.getPort() );
+
+ try
+ {
+ connection.bind( "uid=admin,ou=system", "secret" );
+
+ SearchResultEntry rootDSE = connection.getRootDSE( "+" );
+
+ assertNotNull( rootDSE );
+
+ assertTrue( rootDSE instanceof SearchResultEntry );
+
+ assertEquals( 2, rootDSE.getMessageId() );
+ Entry entry = rootDSE.getEntry();
+
+ assertNotNull( entry );
+ assertEquals( "", entry.getDn().toString() );
+ assertFalse( entry.contains( "ObjectClass", "top", "extensibleObject" ) );
+ assertTrue( entry.contains( "subschemaSubentry", "cn=schema" ) );
+ assertTrue( entry.contains( "vendorName", "Apache Software Foundation" ) );
+ assertTrue( entry.contains( "supportedLDAPVersion", "3" ) );
+
+ connection.unBind();
+ }
+ catch ( LdapException le )
+ {
+ le.printStackTrace();
+ fail();
+ }
+ catch ( Exception e )
+ {
+ fail();
+ }
+ finally
+ {
+ try
+ {
+ connection.close();
+ }
+ catch( IOException ioe )
+ {
+ fail();
+ }
+ }
+ }
+
+
+ //------------------------------------------------------------------------
+ // Asynchronous getRootDSE()
+ //------------------------------------------------------------------------
+}