org.apache.directory.server.unit
Class AbstractServerTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.directory.server.unit.AbstractServerTest
All Implemented Interfaces:
junit.framework.Test

public abstract class AbstractServerTest
extends junit.framework.TestCase

A simple testcase for testing JNDI provider functionality.

Version:
$Rev: 692919 $
Author:
Apache Directory Project

Field Summary
protected  DirectoryService directoryService
           
protected  boolean doDelete
          flag whether to delete database files for each test or not
protected  LdapService ldapService
           
protected static int nbTests
           
protected  int port
           
protected  CoreSession rootDSE
          the context root for the rootDSE
protected  javax.naming.ldap.LdapContext schemaRoot
          the context root for the schema
protected  SocketAcceptor socketAcceptor
           
protected  javax.naming.ldap.LdapContext sysRoot
          the context root for the system partition
 
Constructor Summary
AbstractServerTest()
           
 
Method Summary
protected  void configureDirectoryService()
           
protected  void configureLdapServer()
           
protected  void doDelete(java.io.File wkdir)
          Deletes the Eve working directory.
protected  javax.naming.ldap.LdapContext getWiredContext()
          Common code to get an initial context via a simple bind to the server over the wire using the SUN JNDI LDAP provider.
protected  javax.naming.ldap.LdapContext getWiredContext(java.lang.String bindPrincipalDn, java.lang.String password)
          Common code to get an initial context via a simple bind to the server over the wire using the SUN JNDI LDAP provider.
protected  void importLdif(java.io.InputStream in)
          Imports the LDIF entries packaged with the Eve JNDI provider jar into the newly created system partition to prime it up for operation.
protected  void injectEntries(java.lang.String ldif)
          Inject an ldif String into the server.
protected  java.util.List<org.apache.directory.shared.ldap.ldif.LdifEntry> loadLdif(java.io.InputStream in, boolean verifyEntries)
          Loads an LDIF from an input stream and adds the entries it contains to the server.
protected  java.util.List<org.apache.directory.shared.ldap.ldif.LdifEntry> loadTestLdif(boolean verifyEntries)
          If there is an LDIF file with the same name as the test class but with the .ldif extension then it is read and the entries it contains are added to the server.
protected  void setContexts(java.util.Hashtable<java.lang.String,java.lang.Object> env)
          Sets the contexts of this class taking into account the extras and overrides properties.
protected  void setContexts(java.lang.String user, java.lang.String passwd)
          Sets the contexts for this base class.
protected  void setUp()
          Get's the initial context factory for the provider's ou=system context root.
protected  void tearDown()
          Sets the system context root to null.
protected  void verify(org.apache.directory.shared.ldap.ldif.LdifEntry entry)
          Verifies that an entry exists in the directory with the specified attributes.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sysRoot

protected javax.naming.ldap.LdapContext sysRoot
the context root for the system partition


rootDSE

protected CoreSession rootDSE
the context root for the rootDSE


schemaRoot

protected javax.naming.ldap.LdapContext schemaRoot
the context root for the schema


doDelete

protected boolean doDelete
flag whether to delete database files for each test or not


port

protected int port

nbTests

protected static int nbTests

directoryService

protected DirectoryService directoryService

socketAcceptor

protected SocketAcceptor socketAcceptor

ldapService

protected LdapService ldapService
Constructor Detail

AbstractServerTest

public AbstractServerTest()
Method Detail

loadTestLdif

protected java.util.List<org.apache.directory.shared.ldap.ldif.LdifEntry> loadTestLdif(boolean verifyEntries)
                                                                                throws java.lang.Exception
If there is an LDIF file with the same name as the test class but with the .ldif extension then it is read and the entries it contains are added to the server. It appears as though the administor adds these entries to the server.

Parameters:
verifyEntries - whether or not all entry additions are checked to see if they were in fact correctly added to the server
Returns:
a list of entries added to the server in the order they were added
Throws:
javax.naming.NamingException - of the load fails
java.lang.Exception

loadLdif

protected java.util.List<org.apache.directory.shared.ldap.ldif.LdifEntry> loadLdif(java.io.InputStream in,
                                                                                   boolean verifyEntries)
                                                                            throws java.lang.Exception
Loads an LDIF from an input stream and adds the entries it contains to the server. It appears as though the administrator added these entries to the server.

Parameters:
in - the input stream containing the LDIF entries to load
verifyEntries - whether or not all entry additions are checked to see if they were in fact correctly added to the server
Returns:
a list of entries added to the server in the order they were added
Throws:
javax.naming.NamingException - of the load fails
java.lang.Exception

verify

protected void verify(org.apache.directory.shared.ldap.ldif.LdifEntry entry)
               throws java.lang.Exception
Verifies that an entry exists in the directory with the specified attributes.

Parameters:
entry - the entry to verify
Throws:
javax.naming.NamingException - if there are problems accessing the entry
java.lang.Exception

getWiredContext

protected javax.naming.ldap.LdapContext getWiredContext()
                                                 throws java.lang.Exception
Common code to get an initial context via a simple bind to the server over the wire using the SUN JNDI LDAP provider. Do not use this method until after the setUp() method is called to start the server otherwise it will fail.

Returns:
an LDAP context as the the administrator to the rootDSE
Throws:
javax.naming.NamingException - if the server cannot be contacted
java.lang.Exception

getWiredContext

protected javax.naming.ldap.LdapContext getWiredContext(java.lang.String bindPrincipalDn,
                                                        java.lang.String password)
                                                 throws java.lang.Exception
Common code to get an initial context via a simple bind to the server over the wire using the SUN JNDI LDAP provider. Do not use this method until after the setUp() method is called to start the server otherwise it will fail.

Parameters:
bindPrincipalDn - the DN of the principal to bind as
password - the password of the bind principal
Returns:
an LDAP context as the the administrator to the rootDSE
Throws:
javax.naming.NamingException - if the server cannot be contacted
java.lang.Exception

setUp

protected void setUp()
              throws java.lang.Exception
Get's the initial context factory for the provider's ou=system context root.

Overrides:
setUp in class junit.framework.TestCase
Throws:
java.lang.Exception
See Also:
TestCase.setUp()

configureDirectoryService

protected void configureDirectoryService()
                                  throws java.lang.Exception
Throws:
java.lang.Exception

configureLdapServer

protected void configureLdapServer()

doDelete

protected void doDelete(java.io.File wkdir)
                 throws java.io.IOException
Deletes the Eve working directory.

Parameters:
wkdir - the directory to delete
Throws:
java.io.IOException - if the directory cannot be deleted

setContexts

protected void setContexts(java.lang.String user,
                           java.lang.String passwd)
                    throws java.lang.Exception
Sets the contexts for this base class. Values of user and password used to set the respective JNDI properties. These values can be overriden by the overrides properties.

Parameters:
user - the username for authenticating as this user
passwd - the password of the user
Throws:
javax.naming.NamingException - if there is a failure of any kind
java.lang.Exception

setContexts

protected void setContexts(java.util.Hashtable<java.lang.String,java.lang.Object> env)
                    throws java.lang.Exception
Sets the contexts of this class taking into account the extras and overrides properties.

Parameters:
env - an environment to use while setting up the system root.
Throws:
javax.naming.NamingException - if there is a failure of any kind
java.lang.Exception

tearDown

protected void tearDown()
                 throws java.lang.Exception
Sets the system context root to null.

Overrides:
tearDown in class junit.framework.TestCase
Throws:
java.lang.Exception
See Also:
TestCase.tearDown()

importLdif

protected void importLdif(java.io.InputStream in)
                   throws javax.naming.NamingException
Imports the LDIF entries packaged with the Eve JNDI provider jar into the newly created system partition to prime it up for operation. Note that only ou=system entries will be added - entries for other partitions cannot be imported and will blow chunks.

Parameters:
in - the input stream with the ldif
Throws:
javax.naming.NamingException - if there are problems reading the ldif file and adding those entries to the system partition

injectEntries

protected void injectEntries(java.lang.String ldif)
                      throws java.lang.Exception
Inject an ldif String into the server. DN must be relative to the root.

Parameters:
ldif - the entries to inject
Throws:
javax.naming.NamingException - if the entries cannot be added
java.lang.Exception


Copyright © 2003-2009 Apache Software Foundation. All Rights Reserved.