CreateKdcServer methodKdcServerBuilder = methodDescription.getAnnotation( CreateKdcServer.class );
// Ok, ready to run the test
try
{
DirectoryService directoryService = null;
// Set the revision to 0, we will revert only if it's set to another value
long revision = 0L;
// Check if this method has a dedicated DSBuilder
DirectoryService methodDS = DSAnnotationProcessor.getDirectoryService( methodDescription );
// give #1 priority to method level DS if present
if ( methodDS != null )
{
// Apply all the LDIFs
DSAnnotationProcessor.applyLdifs( suiteDescription, methodDS );
DSAnnotationProcessor.applyLdifs( classDescription, methodDS );
DSAnnotationProcessor.applyLdifs( methodDescription, methodDS );
directoryService = methodDS;
}
else if ( classDS != null )
{
directoryService = classDS;
// apply the method LDIFs, and tag for reversion
revision = getCurrentRevision( directoryService );
DSAnnotationProcessor.applyLdifs( methodDescription, directoryService );
}
// we don't support method level LdapServer so
// we check for the presence of Class level LdapServer first
else if ( classLdapServer != null )
{
directoryService = classLdapServer.getDirectoryService();
revision = getCurrentRevision( directoryService );
DSAnnotationProcessor.applyLdifs( methodDescription, directoryService );
}
else if ( classKdcServer != null )
{
directoryService = classKdcServer.getDirectoryService();
revision = getCurrentRevision( directoryService );
DSAnnotationProcessor.applyLdifs( methodDescription, directoryService );
}
if ( methodLdapServerBuilder != null )
{
methodLdapServer = ServerAnnotationProcessor.createLdapServer( methodDescription, directoryService );
}
if ( methodKdcServerBuilder != null )
{
int minPort = getMinPort();
methodKdcServer = ServerAnnotationProcessor.getKdcServer( methodDescription, directoryService,
minPort + 1 );
}
// At this point, we know which service to use.
// Inject it into the class
Method setService = null;
try
{
setService = getTestClass().getJavaClass().getMethod( SET_SERVICE_METHOD_NAME,
DirectoryService.class );
setService.invoke( getTestClass().getJavaClass(), directoryService );
}
catch ( NoSuchMethodException nsme )
{
// Do nothing
}
// if we run this class in a suite, tell it to the test
Method setLdapServer = null;
try
{
setLdapServer = getTestClass().getJavaClass().getMethod( SET_LDAP_SERVER_METHOD_NAME,
LdapServer.class );
}
catch ( NoSuchMethodException nsme )
{
// Do nothing
}
Method setKdcServer = null;
try
{
setKdcServer = getTestClass().getJavaClass().getMethod( SET_KDC_SERVER_METHOD_NAME, KdcServer.class );
}
catch ( NoSuchMethodException nsme )
{
// Do nothing
}
DirectoryService oldLdapServerDirService = null;
DirectoryService oldKdcServerDirService = null;
if ( methodLdapServer != null )
{
// setting the directoryService is required to inject the correct level DS instance in the class or suite level LdapServer
methodLdapServer.setDirectoryService( directoryService );