Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 14415 invoked from network); 4 May 2009 22:51:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 May 2009 22:51:24 -0000 Received: (qmail 7663 invoked by uid 500); 4 May 2009 22:51:24 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 7607 invoked by uid 500); 4 May 2009 22:51:24 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 7598 invoked by uid 99); 4 May 2009 22:51:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 May 2009 22:51:24 +0000 X-ASF-Spam-Status: No, hits=-1998.8 required=10.0 tests=ALL_TRUSTED,FS_REPLICA X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 May 2009 22:51:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6D42B2388A33; Mon, 4 May 2009 22:51:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r771486 - /directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/BindRequestTest.java Date: Mon, 04 May 2009 22:51:01 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090504225101.6D42B2388A33@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Mon May 4 22:51:01 2009 New Revision: 771486 URL: http://svn.apache.org/viewvc?rev=771486&view=rev Log: o Created a dedicated class for the Bind operation. o Added an Anonymous bind test Added: directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/BindRequestTest.java Added: 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=771486&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/BindRequestTest.java (added) +++ directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/BindRequestTest.java Mon May 4 22:51:01 2009 @@ -0,0 +1,224 @@ +/* + * 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.listeners.BindListener; +import org.apache.directory.shared.ldap.client.api.messages.BindRequest; +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.message.ResultCodeEnum; +import org.apache.directory.shared.ldap.util.StringTools; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertTrue; +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 + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +@RunWith ( SiRunner.class ) +@CleanupLevel ( Level.CLASS ) +public class BindRequestTest +{ + /** The server instance */ + public static LdapService ldapService; + + private static boolean responseReceived = false; + + @Before + public void init() + { + responseReceived = false; + } + + //------------------------------------------------------------------------ + // Synchronous bind + //------------------------------------------------------------------------ + /** + * Test a successful bind request + * + * @throws IOException + */ + @Test + public void testBindRequest() + { + LdapConnection connection = new LdapConnection( "localhost", ldapService.getPort() ); + + try + { + BindResponse bindResponse = connection.bind( "uid=admin,ou=system", "secret" ); + + assertNotNull( bindResponse ); + + assertEquals( 0, bindResponse.getMessageId() ); + assertNotNull( bindResponse.getControls() ); + assertEquals( 0, bindResponse.getControls().values().size() ); + + // Check the result + assertNotNull( bindResponse.getLdapResult() ); + LdapResult ldapResult = bindResponse.getLdapResult(); + + assertEquals( ResultCodeEnum.SUCCESS, ldapResult.getResultCode() ); + + assertTrue( StringTools.isEmpty( ldapResult.getErrorMessage() ) ); + assertTrue( StringTools.isEmpty( ldapResult.getMatchedDn() ) ); + } + catch ( LdapException le ) + { + fail(); + } + finally + { + try + { + connection.unBind(); + connection.close(); + } + catch( Exception e ) + { + fail(); + } + } + } + + + /** + * Test a successful anonymous bind request + * + * @throws IOException + */ + @Test + public void testAnonymousBindRequest() + { + LdapConnection connection = new LdapConnection( "localhost", ldapService.getPort() ); + + try + { + BindResponse bindResponse = connection.bind(); + + + assertNotNull( bindResponse ); + + assertEquals( 0, bindResponse.getMessageId() ); + assertNotNull( bindResponse.getControls() ); + assertEquals( 0, bindResponse.getControls().values().size() ); + + // Check the result + assertNotNull( bindResponse.getLdapResult() ); + LdapResult ldapResult = bindResponse.getLdapResult(); + + assertEquals( ResultCodeEnum.SUCCESS, ldapResult.getResultCode() ); + + assertTrue( StringTools.isEmpty( ldapResult.getErrorMessage() ) ); + assertTrue( StringTools.isEmpty( ldapResult.getMatchedDn() ) ); + + connection.unBind(); + } + catch ( LdapException le ) + { + fail(); + } + finally + { + try + { + connection.close(); + } + catch( IOException ioe ) + { + fail(); + } + } + } + + + //------------------------------------------------------------------------ + // Asynchronous bind + //------------------------------------------------------------------------ + /** + * Test a successful asynchronous bind request + * + * @throws IOException + */ + @Test + public void testAsyncBindRequest() + { + LdapConnection connection = new LdapConnection( "localhost", ldapService.getPort() ); + + try + { + BindRequest bindRequest = new BindRequestImpl(); + bindRequest.setCredentials( "secret" ); + bindRequest.setName( "uid=admin,ou=system" ); + + connection.bind( bindRequest, new BindListener() + { + public void bindCompleted( LdapConnection connection, BindResponse bindResponse ) throws LdapException + { + assertNotNull( bindResponse ); + responseReceived = true; + } + } ); + + // Wait a bit + Thread.sleep( 1000 ); + + assertTrue( responseReceived ); + + connection.unBind(); + } + catch ( LdapException le ) + { + fail(); + } + catch ( InterruptedException ie ) + { + fail(); + } + finally + { + try + { + connection.close(); + } + catch( IOException ioe ) + { + fail(); + } + } + } +}