org.apache.directory.server.core.unit
Class AbstractTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.directory.server.core.unit.AbstractTestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
AbstractAdminTestCase

public abstract class AbstractTestCase
extends junit.framework.TestCase

A simple testcase for testing JNDI provider functionality.

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

Field Summary
protected  boolean doDelete
          flag whether to delete database files for each test or not
static java.lang.String LDIF
           
static org.slf4j.Logger LOG
           
protected  java.lang.String password
           
protected  Registries registries
           
protected  javax.naming.ldap.LdapContext rootDSE
          the rootDSE context for the server
protected  javax.naming.ldap.LdapContext schemaRoot
          the context root for the schema partition
protected  DirectoryService service
           
protected  javax.naming.ldap.LdapContext sysRoot
          the context root for the system partition
protected  java.util.List<org.apache.directory.shared.ldap.ldif.LdifEntry> testEntries
          A testEntries of entries as Attributes to add to the DIT for testing
protected  java.lang.String username
           
 
Constructor Summary
protected AbstractTestCase(java.lang.String username, java.lang.String password)
           
 
Method Summary
protected  void doDelete(java.io.File wkdir)
          Deletes the working directory.
protected  java.util.Hashtable<java.lang.String,java.lang.Object> getOverriddenEnvironment()
           
protected  void injectEntries(java.lang.String ldif)
          Inject an ldif String into the server.
protected  void overrideEnvironment(java.lang.String key, java.lang.Object value)
          Overrides default JNDI environment properties.
protected  void restart()
          Restarts the server without loading data when it has been shutdown.
protected  void setContextRoots(java.util.Hashtable<java.lang.String,java.lang.Object> env)
          Sets the system root taking into account the extras and overrides properties.
protected  void setContextRoots(java.lang.String user, java.lang.String passwd)
          Sets and returns the system root.
protected  void setLdifPath(java.lang.String ldifPath)
          Sets the LDIF path to use.
protected  void setLdifPath(java.lang.String ldifPath, java.lang.Class<?> loadClass)
          Sets the LDIF path as a relative resource path to use with the loadClass parameter to load the resource.
protected  void setLoadClass(java.lang.Class<?> loadClass)
           
protected  void setUp()
          Get's the initial context factory for the provider's ou=system context root.
protected  void shutdown()
          Issues a shutdown request to the server.
protected  void sync()
          Issues a sync request to the server.
protected  void tearDown()
          Sets the system context root to null.
 
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

LOG

public static final org.slf4j.Logger LOG

LDIF

public static final java.lang.String LDIF
See Also:
Constant Field Values

username

protected final java.lang.String username

password

protected final java.lang.String password

sysRoot

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


schemaRoot

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


rootDSE

protected javax.naming.ldap.LdapContext rootDSE
the rootDSE context for the server


doDelete

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


testEntries

protected java.util.List<org.apache.directory.shared.ldap.ldif.LdifEntry> testEntries
A testEntries of entries as Attributes to add to the DIT for testing


registries

protected Registries registries

service

protected DirectoryService service
Constructor Detail

AbstractTestCase

protected AbstractTestCase(java.lang.String username,
                           java.lang.String password)
                    throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

setLdifPath

protected void setLdifPath(java.lang.String ldifPath,
                           java.lang.Class<?> loadClass)
Sets the LDIF path as a relative resource path to use with the loadClass parameter to load the resource.

Parameters:
ldifPath - the relative resource path to the LDIF file
loadClass - the class used to load the LDIF as a resource stream

setLdifPath

protected void setLdifPath(java.lang.String ldifPath)
Sets the LDIF path to use. If the path is relative to this class then it is first tested

Parameters:
ldifPath - the path to the LDIF file

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()

restart

protected void restart()
                throws java.lang.Exception
Restarts the server without loading data when it has been shutdown.

Throws:
NamingException - if the restart fails
java.lang.Exception

doDelete

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

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

setContextRoots

protected void setContextRoots(java.lang.String user,
                               java.lang.String passwd)
                        throws java.lang.Exception
Sets and returns the system root. 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:
NamingException - if there is a failure of any kind
java.lang.Exception

setContextRoots

protected void setContextRoots(java.util.Hashtable<java.lang.String,java.lang.Object> env)
                        throws java.lang.Exception
Sets the system root taking into account the extras and overrides properties. In between these it sets the properties for the working directory, the provider URL and the JNDI InitialContexFactory to use.

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

overrideEnvironment

protected void overrideEnvironment(java.lang.String key,
                                   java.lang.Object value)
Overrides default JNDI environment properties. Please call this method to override any JNDI environment properties this test case will set.

Parameters:
key - the key of the hashtable entry to add to the environment
value - the value of the hashtable entry to add to the environment

getOverriddenEnvironment

protected java.util.Hashtable<java.lang.String,java.lang.Object> getOverriddenEnvironment()

shutdown

protected void shutdown()
Issues a shutdown request to the server.


sync

protected void sync()
Issues a sync request to the server.


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()

setLoadClass

protected void setLoadClass(java.lang.Class<?> loadClass)

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 ldif containing entries to add to the server.
Throws:
NamingException - if there is a problem adding the entries from the LDIF
java.lang.Exception


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